• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ skip_atoi函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中skip_atoi函数的典型用法代码示例。如果您正苦于以下问题:C++ skip_atoi函数的具体用法?C++ skip_atoi怎么用?C++ skip_atoi使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了skip_atoi函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: vtxprintf

int vtxprintf(void (*tx_byte)(unsigned char byte, void *data),
	       const char *fmt, va_list args, void *data)
{
	int len;
	unsigned long long num;
	int i, base;
	const char *s;

	int flags;		/* flags to number() */

	int field_width;	/* width of output field */
	int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
	int qualifier;		/* 'h', 'H', 'l', or 'L' for integer fields */

	int count;

	for (count = 0; *fmt ; ++fmt) {
		if (*fmt != '%') {
			call_tx(*fmt), count++;
			continue;
		}

		/* process flags */
		flags = 0;
repeat:
			++fmt;		/* this also skips first '%' */
			switch (*fmt) {
				case '-': flags |= LEFT; goto repeat;
				case '+': flags |= PLUS; goto repeat;
				case ' ': flags |= SPACE; goto repeat;
				case '#': flags |= SPECIAL; goto repeat;
				case '0': flags |= ZEROPAD; goto repeat;
				}

		/* get field width */
		field_width = -1;
		if (is_digit(*fmt)) {
			field_width = skip_atoi(&fmt);
		} else if (*fmt == '*') {
			++fmt;
			/* it's the next argument */
			field_width = va_arg(args, int);
			if (field_width < 0) {
				field_width = -field_width;
				flags |= LEFT;
			}
		}

		/* get the precision */
		precision = -1;
		if (*fmt == '.') {
			++fmt;
			if (is_digit(*fmt)) {
				precision = skip_atoi(&fmt);
			} else if (*fmt == '*') {
				++fmt;
				/* it's the next argument */
				precision = va_arg(args, int);
			}
开发者ID:canistation,项目名称:coreboot,代码行数:60,代码来源:vtxprintf.c


示例2: vsprintf

int vsprintf(char* buf, const char* fmt, va_list args)
{
	int len;
	long num;
	int i;
	int base;
	char* str;
	const char* s;

	int flags;		/* flags to number() */

	int field_width;	/* width of output field */
	int precision;		/* min. # of digits for integers; max
					   number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'q' for integer fields */

	for (str = buf; *fmt; ++fmt) {
		if (*fmt != '%') {
			*str++ = *fmt;
			continue;
		}

		/* process flags */
		flags = 0;
repeat:
		++fmt;		/* this also skips first '%' */
		switch (*fmt) {
			case '-': flags |= LEFT; goto repeat;
			case '+': flags |= PLUS; goto repeat;
			case ' ': flags |= SPACE; goto repeat;
			case '#': flags |= SPECIAL; goto repeat;
			case '0': flags |= ZEROPAD; goto repeat;
		}

		/* get field width */
		field_width = -1;
		if (is_digit(*fmt)) {
			field_width = skip_atoi(&fmt);
		} else if (*fmt == '*') {
			++fmt;
			/* it's the next argument */
			field_width = va_arg(args, int);
			if (field_width < 0) {
				field_width = -field_width;
				flags |= LEFT;
			}
		}

		/* get the precision */
		precision = -1;
		if (*fmt == '.') {
			++fmt;
			if (is_digit(*fmt)) {
				precision = skip_atoi(&fmt);
			} else if (*fmt == '*') {
				++fmt;
				/* it's the next argument */
				precision = va_arg(args, int);
			}
开发者ID:dholm,项目名称:kernel,代码行数:59,代码来源:vsprintf.c


示例3: vsprintf

static int vsprintf(char *buff, const char *format, va_list args)
{
	int len;
	int i;
	char *str;
	char *s;
	int *ip;

	int flags;		// flags to number()

	int field_width;	// width of output field
	int precision;		// min. # of digits for integers; max number of chars for from string

	for (str = buff ; *format ; ++format) {
		if (*format != '%') {
			*str++ = *format;
			continue;
		}

		flags = 0;
		repeat:
			++format;		// this also skips first '%'
			switch (*format) {
				case '-': flags |= LEFT;
					  goto repeat;
				case '+': flags |= PLUS;
					  goto repeat;
				case ' ': flags |= SPACE;
					  goto repeat;
				case '#': flags |= SPECIAL;
					  goto repeat;
				case '0': flags |= ZEROPAD;
					  goto repeat;
			}

		// get field width
		field_width = -1;
		if (is_digit(*format)) {
			field_width = skip_atoi(&format);
		} else if (*format == '*') {
			// it's the next argument
			field_width = va_arg(args, int);
			if (field_width < 0) {
				field_width = -field_width;
				flags |= LEFT;
			}
		}

		// get the precision
		precision = -1;
		if (*format == '.') {
			++format;
			if (is_digit(*format)) {
				precision = skip_atoi(&format);
			} else if (*format == '*') {
				// it's the next argument
				precision = va_arg(args, int);
			}
开发者ID:micnaelyuanfeng,项目名称:BitCoinOS,代码行数:58,代码来源:printk.c


示例4: vsnprintf

/*
** This vsnprintf() emulation does not implement the conversions:
**	%e, %E, %g, %G, %wc, %ws
** The %f implementation is limited.
*/
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
  int len;
  unsigned long num;
  int i, base;
  char *str;
  const char *s;

  int flags;
  int dotflag;

  int field_width;
  int precision;

  int qualifier;

  size--;
  for(str = buf; *fmt && size; ++fmt) {
    if(*fmt != '%') {
      *str++ = *fmt;
      size--;
      continue;
    }

    flags = 0;
    dotflag = 0;
    repeat:
      ++fmt;
      switch(*fmt) {
        case '-': flags |= LEFT; goto repeat;
        case '+': flags |= PLUS; goto repeat;
        case ' ': flags |= SPACE; goto repeat;
        case '#': flags |= SPECIAL; goto repeat;
        case '0': flags |= ZEROPAD; goto repeat;
      }

      field_width = -1;
      if(isdigit(*fmt))
        field_width = skip_atoi(&fmt);
      else if(*fmt == '*') {
        ++fmt;
        field_width = va_arg(args,int);
        if(field_width < 0) {
          field_width = - field_width;
          flags |= LEFT;
        }
      }

      precision = -1;
      if(*fmt == '.') {
	dotflag++;
        ++fmt;
        if(isdigit(*fmt))
          precision = skip_atoi(&fmt);
        else if(*fmt == '*') {
          ++fmt;
          precision = va_arg(args,int);
        }
开发者ID:Distrotech,项目名称:proftpd,代码行数:63,代码来源:vsnprintf.c


示例5: vsprintf

int vsprintf(char *buf, const char *fmt, va_list args) {
 int len;
 unsigned long num;
 int i, base;
 char *str;
 char *s;

 int flags;            // Flags to number()

 int field_width;      // Width of output field
 int precision;        // Min. # of digits for integers; max number of chars for from string
 int qualifier;        // 'l', or 'L' for integer fields

 for (str = buf; *fmt; fmt++) {
  if (*fmt != '%') {
   *str++ = *fmt;
   continue;
  }

  // Process flags
  flags = 0;
 repeat:
  fmt++; // This also skips first '%'
  switch (*fmt) {
  case '-': flags |= LEFT; goto repeat;
  case '+': flags |= PLUS; goto repeat;
  case ' ': flags |= SPACE; goto repeat;
  case '#': flags |= SPECIAL; goto repeat;
  case '0': flags |= ZEROPAD; goto repeat;
  }

  // Get field width
  field_width = -1;
  if (is_digit(*fmt)) {
   field_width = skip_atoi(&fmt);
  }
  else if (*fmt == '*') {
   fmt++;
   field_width = va_arg(args, int);
   if (field_width < 0) {
    field_width = -field_width;
    flags |= LEFT;
   }
  }

  // Get the precision
  precision = -1;
  if (*fmt == '.') {
   ++fmt;
   if (is_digit(*fmt)) {
    precision = skip_atoi(&fmt);
   }
   else if (*fmt == '*') {
    ++fmt;
    precision = va_arg(args, int);
   }
开发者ID:BeyondEngine,项目名称:BeyondEngine,代码行数:56,代码来源:Android_sprintf.c


示例6: vsprintf

static int vsprintf(char *buff, const char *format, va_list args)
{
    int len;
    int i;
    char *str;
    char *s;
    int *ip;
    int flags;
    int field_width;
    int precision;
    
    for (str = buff; *format; ++format) {
        if (*format != '%') {
            *str ++ = *format;
            continue;
        }
        flags = 0;
        repeat:
            ++format;
            switch (*format) {
                case '-':   flags |= LEFT;
                            goto repeat;
                case '+':   flags |= PLUS;
                            goto repeat;
                case ' ':   flags |= SPACE;
                            goto repeat;
                case '#':   flags |= SPECIAL;
                            goto repeat;
                case '0':   flags |= ZEROPAD;
                            goto repeat;
            }
            
        // get field width
        field_width = -1;
        if (is_digit(*format)) {
            field_width = skip_atoi(&format);
        } else if (*format == '*') {
            // it's the next arguments
            field_width = va_arg(args, int);
            if (field_width < 0) {
                field_width = -field_width;
                flags |= LEFT;
            }
        }
        
        // get the precision
        precision = -1;
        if (*format == '.') {
            ++ format;
            if (is_digit(*format)) {
                precision = skip_atoi(&format);
            } else if (*format == '*') {
                // it's the next arguments
                precision = va_arg(args, int);
            }
开发者ID:samuelts,项目名称:naiveos,代码行数:55,代码来源:printk.c


示例7: sprintf

int sprintf(char *buf, const char *fmt, va_list args)
{
	char *str;	// for keeping track of output location in buf
	int flags;	// for keeping track of formatting flags
	int field_width;// width of output field
	int precision;	// min number of digits for integers; for strings,
			// max number of chars
	int qualifier;	// 'h', 'l' or 'L' for integers
	char *s;	// if there's a string argument, this is it
	int len;	// this is its length
	int i;		// index variable
	int *ip;	// ptr for 'n' format

	for (str = buf; *fmt; ++fmt) { // loop til end of format string
		if (*fmt != '%') { // detect speshul placeholders
			*str++ = *fmt; // twas a regular char so stick it in
			continue;
		}

		flags = 0;
repeat: // an elegant use of goto if I've ever seen one
		++fmt;		// look at next char, or skip first '%'
		switch(*fmt) {	// look at it!
			case '-': flags |= LEFT; goto repeat;
			case '+': flags |= PLUS; goto repeat;
			case ' ': flags |= SPACE; goto repeat;
			case '#': flags |= SPECIAL; goto repeat;
			case '0': flags |= ZEROPAD; goto repeat;
		}

		// flags done, now field width
		field_width = -1;
		if (is_digit(*fmt)) {
			field_width = skip_atoi(&fmt);
		} else if (*fmt == '*') { // width in next arg
			field_width = va_arg(args, int);
			if (field_width < 0) {
				// negative width means left-align
				field_width = -field_width;
				flags |= LEFT;
			}
		}

		// width done, get precision
		precision = -1;
		if (*fmt == '.') { // precision coming up
			++fmt;
			if (is_digit(*fmt)) {
				precision = skip_atoi(&fmt);
			} else if (*fmt == '*') {
				// precision is next argument
				precision = va_arg(args, int);
			}
开发者ID:ilkka,项目名称:unix-from-scratch,代码行数:53,代码来源:printf.c


示例8: vsprintf

static int vsprintf(char *buf, const char *fmt, va_list args)
{

	int len;
	unsigned long num;
	int i, base;
	char * str;
	const char *s;

	int flags;		/* flags to number() */

	int field_width;	/* width of output field */
	int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'L' for integer fields */

    for (str = buf; *fmt; ++fmt) {
        if (*fmt != '%') {
            *str++ = *fmt;
            continue;
        }
        flags = 0;
repeat:
        ++fmt;
        switch (*fmt) {
        case '-': flags |= LEFT; goto repeat;
        case '+': flags |= PLUS; goto repeat;
        case ' ': flags |= SPACE;goto repeat;
        case '#': flags |= SPECIAL;goto repeat;
        case '0': flags |= ZEROPAD;goto repeat;
        }
        field_width = -1;
        if (is_digit(*fmt))
            field_width = skip_atoi(&fmt);
        else if (*fmt == '*') {
            ++ fmt;
            field_width = va_arg(args, int);
            if (field_width < 0) {
                field_width = -field_width;
                flags |= LEFT;
            }
        }

        precision = -1;
        if (*fmt == '.') {
            ++fmt;
            if (is_digit(*fmt))
                precision = skip_atoi(&fmt);
            else if (*fmt == '*') {
                ++fmt;
                precision = va_arg(args, int);
            }
开发者ID:Insswer,项目名称:ARM_KERNEL_SkyEYE,代码行数:52,代码来源:printf.c


示例9: parse_printf_fmt

/**
 * parse_printf_fmt() - Parse printf/printk conversion spec.
 * fmt points to the '%' in a printk conversion specification.  Advance
 * fmt past any flags, width and/or precision specifiers, and qualifiers
 * such as 'l' and 'L'.  Return a pointer to the conversion character.
 * Stores the qualifier character (or -1, if there is none) at *pqualifier.
 * *wp is set to flags indicating whether the width and/or precision are '*'.
 * For example, given
 *      %*.2lx
 * *pqualifier is set to 'l', *wp is set to 0x1, and a pointer to the 'x'
 * is returned.
 *
 * Note: This function is derived from vsnprintf() (see * lib/vsprintf.c),
 * and should be kept in sync with that function.
 *
 * @fmt - points to '%' in conversion spec
 * @pqualifier - *pqualifier is set to conversion spec's qualifier, or -1.
 * @wp - Bits in *wp are set if the width or/and precision are '*'.
 */
const char *
parse_printf_fmt(const char *fmt, int *pqualifier, int *wp)
{
	int qualifier = -1;
	*wp = 0;

	/* process flags */
	repeat:
		++fmt;          /* this also skips first '%' */
		switch (*fmt) {
			case '-':
			case '+':
			case ' ':
			case '#':
			case '0':
				goto repeat;
		}

	/* get field width */
	if (isdigit(*fmt))
		skip_atoi(&fmt);
	else if (*fmt == '*') {
		++fmt;
		/* it's the next argument */
		*wp |= 0x1;
	}

	/* get the precision */
	if (*fmt == '.') {
		++fmt;
		if (isdigit(*fmt))
			skip_atoi(&fmt);
		else if (*fmt == '*') {
			++fmt;
			/* it's the next argument */
			*wp |= 0x2;
		}
	}

	/* get the conversion qualifier */
	if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt =='Z') {
		qualifier = *fmt;
		++fmt;
		if (qualifier == 'l' && *fmt == 'l') {
			qualifier = 'L';
			++fmt;
		}
	}

	*pqualifier = qualifier;
	return fmt;
}
开发者ID:cmjonze,项目名称:evlog_cvs,代码行数:71,代码来源:evlog.c


示例10: do_gpio

static int  do_gpio(int argc, const char* argv[])
{
	char *tmp = argv[2];
	int gpio = skip_atoi(&tmp);
	
	if (strcmp(argv[1], "in") == 0) {
		GPIO_DIS_OUTPUT(gpio);
		console_printf("GP%d==%d\n", gpio, GPIO_INPUT_GET(gpio));
	} else 	if (strcmp(argv[1], "out") == 0) {
		if (argc < 4)
			return;
		tmp = argv[3];
		int v = skip_atoi(&tmp);
		GPIO_OUTPUT_SET(gpio, v);
	}
	
}
开发者ID:d946,项目名称:esp8266-frankenstein,代码行数:17,代码来源:cmd_gpio.c


示例11: do_listen

static int   do_listen(int argc, const char* argv[])
{
	int port = skip_atoi(&argv[1]);
	console_printf("Listening (TCP) on port %d\n", port);
	esp_conn.type = ESPCONN_TCP;
	esp_conn.state = ESPCONN_NONE;
	esp_conn.proto.tcp = &esptcp;
	esp_conn.proto.tcp->local_port = port;
	espconn_regist_connectcb(&esp_conn, webserver_listen);
	espconn_accept(&esp_conn);
	linebuffer = os_malloc(LINEBUFFER_SIZE);
	lineptr = 0;
	console_lock(1);
}
开发者ID:d946,项目名称:esp8266-frankenstein,代码行数:14,代码来源:cmd_listen.c


示例12: bvsnprintf

/**
 * bvsnprintf - BIRD's vsnprintf()
 * @buf: destination buffer
 * @size: size of the buffer
 * @fmt: format string
 * @args: a list of arguments to be formatted
 *
 * This functions acts like ordinary sprintf() except that it checks
 * available space to avoid buffer overflows and it allows some more
 * format specifiers: |%I| for formatting of IP addresses (any non-zero
 * width is automatically replaced by standard IP address width which
 * depends on whether we use IPv4 or IPv6; |%#I| gives hexadecimal format),
 * |%R| for Router / Network ID (u32 value printed as IPv4 address)
 * and |%m| resp. |%M| for error messages (uses strerror() to translate @errno code to
 * message text). On the other hand, it doesn't support floating
 * point numbers.
 *
 * Result: number of characters of the output string or -1 if
 * the buffer space was insufficient.
 */
int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
{
	int len;
	unsigned long num;
	int i, base;
	u32 x;
	char *str, *start;
	const char *s;
	char ipbuf[STD_ADDRESS_P_LENGTH+1];
	struct iface *iface;

	int flags;		/* flags to number() */

	int field_width;	/* width of output field */
	int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'L' for integer fields */

	for (start=str=buf ; *fmt ; ++fmt, size-=(str-start), start=str) {
		if (*fmt != '%') {
			if (!size)
				return -1;
			*str++ = *fmt;
			continue;
		}
			
		/* process flags */
		flags = 0;
		repeat:
			++fmt;		/* this also skips first '%' */
			switch (*fmt) {
				case '-': flags |= LEFT; goto repeat;
				case '+': flags |= PLUS; goto repeat;
				case ' ': flags |= SPACE; goto repeat;
				case '#': flags |= SPECIAL; goto repeat;
				case '0': flags |= ZEROPAD; goto repeat;
				}
		
		/* get field width */
		field_width = -1;
		if (is_digit(*fmt))
			field_width = skip_atoi(&fmt);
		else if (*fmt == '*') {
			++fmt;
			/* it's the next argument */
			field_width = va_arg(args, int);
			if (field_width < 0) {
				field_width = -field_width;
				flags |= LEFT;
			}
		}

		/* get the precision */
		precision = -1;
		if (*fmt == '.') {
			++fmt;	
			if (is_digit(*fmt))
				precision = skip_atoi(&fmt);
			else if (*fmt == '*') {
				++fmt;
				/* it's the next argument */
				precision = va_arg(args, int);
			}
开发者ID:ChristianTacke,项目名称:bird,代码行数:83,代码来源:printf.c


示例13: vsnprintf

int
vsnprintf(char *buffer, size_t bufferSize, const char *format, va_list args)
{
	uint64 num;
	int base;
	int flags;			/* flags to number() */
	int fieldWidth;	/* width of output field */
	int precision;
		/* min. # of digits for integers; max number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'L' for integer fields */

	Buffer outBuffer(buffer, bufferSize);

	for (; format[0]; format++) {
		if (format[0] != '%') {
			outBuffer.PutCharacter(format[0]);
			continue;
		}

		/* process flags */

		flags = 0;

	repeat:
		format++;
			/* this also skips first '%' */
		switch (format[0]) {
			case '-': flags |= LEFT; goto repeat;
			case '+': flags |= PLUS; goto repeat;
			case ' ': flags |= SPACE; goto repeat;
			case '#': flags |= SPECIAL; goto repeat;
			case '0': flags |= ZEROPAD; goto repeat;

			case '%':
				outBuffer.PutCharacter(format[0]);
				continue;
		}

		/* get field width */

		fieldWidth = -1;
		if (isdigit(*format))
			fieldWidth = skip_atoi(&format);
		else if (format[0] == '*') {
			format++;
			/* it's the next argument */
			fieldWidth = va_arg(args, int);
			if (fieldWidth < 0) {
				fieldWidth = -fieldWidth;
				flags |= LEFT;
			}
		}

		/* get the precision */

		precision = -1;
		if (format[0] == '.') {
			format++;
			if (isdigit(*format))
				precision = skip_atoi(&format);
			else if (format[0] == '*') {
				format++;
				/* it's the next argument */
				precision = va_arg(args, int);
			}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:65,代码来源:kernel_vsprintf.cpp


示例14: rt_vsnprintf

rt_int32_t rt_vsnprintf(char       *buf,
                        rt_size_t   size,
                        const char *fmt,
                        va_list     args)
{
#ifdef RT_PRINTF_LONGLONG
    unsigned long long num;
#else
    rt_uint32_t num;
#endif
    int i, len;
    char *str, *end, c;
    const char *s;

    rt_uint8_t base;            /* the base of number */
    rt_uint8_t flags;           /* flags to print number */
    rt_uint8_t qualifier;       /* 'h', 'l', or 'L' for integer fields */
    rt_int32_t field_width;     /* width of output field */

#ifdef RT_PRINTF_PRECISION
    int precision;      /* min. # of digits for integers and max for a string */
#endif

    str = buf;
    end = buf + size - 1;

    /* Make sure end is always >= buf */
    if (end < buf)
    {
        end  = ((char *)-1);
        size = end - buf;
    }

    for (; *fmt ; ++fmt)
    {
        if (*fmt != '%')
        {
            if (str <= end)
                *str = *fmt;
            ++ str;
            continue;
        }

        /* process flags */
        flags = 0;

        while (1)
        {
            /* skips the first '%' also */
            ++ fmt;
            if (*fmt == '-') flags |= LEFT;
            else if (*fmt == '+') flags |= PLUS;
            else if (*fmt == ' ') flags |= SPACE;
            else if (*fmt == '#') flags |= SPECIAL;
            else if (*fmt == '0') flags |= ZEROPAD;
            else break;
        }

        /* get field width */
        field_width = -1;
        if (isdigit(*fmt)) field_width = skip_atoi(&fmt);
        else if (*fmt == '*')
        {
            ++ fmt;
            /* it's the next argument */
            field_width = va_arg(args, int);
            if (field_width < 0)
            {
                field_width = -field_width;
                flags |= LEFT;
            }
        }

#ifdef RT_PRINTF_PRECISION
        /* get the precision */
        precision = -1;
        if (*fmt == '.')
        {
            ++ fmt;
            if (isdigit(*fmt)) precision = skip_atoi(&fmt);
            else if (*fmt == '*')
            {
                ++ fmt;
                /* it's the next argument */
                precision = va_arg(args, int);
            }
开发者ID:1847123212,项目名称:EasyFlash,代码行数:86,代码来源:kservice.c


示例15: vsprintf

// 下面函数是送格式化输出到字符串中。
// 为了能在内核中使用格式化的输出,Linus 在内核实现了该C 标准函数。
// 其中参数fmt 是格式字符串;args 是个数变化的值;buf 是输出字符串缓冲区。
// 请参见本代码列表后的有关格式转换字符的介绍。
int
vsprintf (char *buf, const char *fmt, va_list args)
{
  int len;
  int i;
  char *str;			// 用于存放转换过程中的字符串。
  char *s;
  int *ip;

  int flags;			/* flags to number() */
/* number()函数使用的标志 */
  int field_width;		/* width of output field */
/* 输出字段宽度*/
  int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
/* min. 整数数字个数;max. 字符串中字符个数 */
  int qualifier;		/* 'h', 'l', or 'L' for integer fields */
/* 'h', 'l',或'L'用于整数字段 */
// 首先将字符指针指向buf,然后扫描格式字符串,对各个格式转换指示进行相应的处理。
  for (str = buf; *fmt; ++fmt)
    {
// 格式转换指示字符串均以'%'开始,这里从fmt 格式字符串中扫描'%',寻找格式转换字符串的开始。
// 不是格式指示的一般字符均被依次存入str。
      if (*fmt != '%')
	{
	  *str++ = *fmt;
	  continue;
	}

// 下面取得格式指示字符串中的标志域,并将标志常量放入flags 变量中。
/* process flags */
      flags = 0;
    repeat:
      ++fmt;			/* this also skips first '%' */
      switch (*fmt)
	{
	case '-':
	  flags |= LEFT;
	  goto repeat;		// 左靠齐调整。
	case '+':
	  flags |= PLUS;
	  goto repeat;		// 放加号。
	case ' ':
	  flags |= SPACE;
	  goto repeat;		// 放空格。
	case '#':
	  flags |= SPECIAL;
	  goto repeat;		// 是特殊转换。
	case '0':
	  flags |= ZEROPAD;
	  goto repeat;		// 要填零(即'0')。
	}

// 取当前参数字段宽度域值,放入field_width 变量中。如果宽度域中是数值则直接取其为宽度值。
// 如果宽度域中是字符'*',表示下一个参数指定宽度。因此调用va_arg 取宽度值。若此时宽度值
// 小于0,则该负数表示其带有标志域'-'标志(左靠齐),因此还需在标志变量中添入该标志,并
// 将字段宽度值取为其绝对值。
/* get field width */
      field_width = -1;
      if (is_digit (*fmt))
	field_width = skip_atoi (&fmt);
      else if (*fmt == '*')
	{
/* it's the next argument */
	  field_width = va_arg (args, int);
	  if (field_width < 0)
	    {
	      field_width = -field_width;
	      flags |= LEFT;
	    }
	}

// 下面这段代码,取格式转换串的精度域,并放入precision 变量中。精度域开始的标志是'.'。
// 其处理过程与上面宽度域的类似。如果精度域中是数值则直接取其为精度值。如果精度域中是
// 字符'*',表示下一个参数指定精度。因此调用va_arg 取精度值。若此时宽度值小于0,则
// 将字段精度值取为其绝对值。
/* get the precision */
      precision = -1;
      if (*fmt == '.')
	{
	  ++fmt;
	  if (is_digit (*fmt))
	    precision = skip_atoi (&fmt);
	  else if (*fmt == '*')
	    {
/* it's the next argument */
	      precision = va_arg (args, int);
	    }
开发者ID:rivoreo,项目名称:Kestrel-Kernel,代码行数:92,代码来源:vsprintf.c


示例16: vcprintf

int
vcprintf(const char *fmt, va_list args)
{
    int len, DynamicColourFlag = 0, ColourCount;
    unsigned long num;
    int i, base;
    char *s;

    int flags;			/* flags to number() */
    int field_width;		/* width of output field */
    int precision;		/* min. # of digits for integers; max
				 * number of chars for from string 
				 */
    int qualifier;		/* 'h', 'l', or 'L' for integer fields */

    for (; *fmt; ++fmt) {
	ColourCount = 0;
	if (*fmt != '%') {
	    if (*fmt == 1) {
		if (*(fmt + 1) == '%') {
		    DynamicColourFlag = 1;	/*
						 * Tricky stuff... 
						 */
		} else {
		    DynamicColourFlag = 0;
		    ColourChar(*(++fmt));
		}
	    } else
		bing(*fmt);
	    continue;
	}
	/*
	 * process flags 
	 */
	flags = 0;
      repeat:
	++fmt;			/*
				 * this also skips first '%' 
				 */
	switch (*fmt) {
	    case '-':
		flags |= LEFT;
		goto repeat;
	    case '+':
		flags |= PLUS;
		goto repeat;
	    case ' ':
		flags |= SPACE;
		goto repeat;
	    case '#':
		flags |= SPECIAL;
		goto repeat;
	    case '0':
		flags |= ZEROPAD;
		goto repeat;
	}

	/*
	 * get field width 
	 */
	field_width = -1;
	if (is_digit(*fmt))
	    field_width = skip_atoi(&fmt);
	else if (*fmt == '*') {
	    ++fmt;
	    /*
	     * it's the next argument 
	     */
	    field_width = va_arg(args, int);
	    if (field_width < 0) {
		field_width = -field_width;
		flags |= LEFT;
	    }
	}
	/*
	 * get the precision 
	 */
	precision = -1;
	if (*fmt == '.') {
	    ++fmt;
	    if (is_digit(*fmt))
		precision = skip_atoi(&fmt);
	    else if (*fmt == '*') {
		++fmt;
		/*
		 * it's the next argument 
		 */
		precision = va_arg(args, int);
	    }
开发者ID:cafuego,项目名称:monolith,代码行数:89,代码来源:cprintf.c


示例17: vsnprintf

int vsnprintf(int size, char *buf, const char *fmt, va_list args)
{
	int len;
	int i;
	char *str;
	char *newstr;
	char *s;
	int *ip;

	int flags;		/* flags to number() */

	int field_width;	/* width of output field */
	int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'L' for integer fields */

	int used_size=1; /* for null character */
	
	if(size == 0)
		return 0;
	*buf = 0;
	if(size == 1)
		return 1;

	for (str=buf ; *fmt ; ++fmt) {
		if (*fmt != '%') {
			if(used_size >= size)
				break;
			*str++ = *fmt;
			used_size++;
			continue;
		}
			
		/* process flags */
		flags = 0;
		repeat:
			++fmt;		/* this also skips first '%' */
			switch (*fmt) {
				case '-': flags |= LEFT; goto repeat;
				case '+': flags |= PLUS; goto repeat;
				case ' ': flags |= SPACE; goto repeat;
				case '#': flags |= SPECIAL; goto repeat;
				case '0': flags |= ZEROPAD; goto repeat;
				}
		
		/* get field width */
		field_width = -1;
		if (is_digit(*fmt))
			field_width = skip_atoi(&fmt);
		else if (*fmt == '*') {
			/* it's the next argument */
			field_width = va_arg(args, int);
			if (field_width < 0) {
				field_width = -field_width;
				flags |= LEFT;
			}
		}

		/* get the precision */
		precision = -1;
		if (*fmt == '.') {
			++fmt;	
			if (is_digit(*fmt))
				precision = skip_atoi(&fmt);
			else if (*fmt == '*') {
				/* it's the next argument */
				precision = va_arg(args, int);
			}
开发者ID:Dennisbonke,项目名称:DB-OS,代码行数:68,代码来源:vsprintf.c


示例18: vsprintf

static u16 vsprintf(char *buf, const char *fmt, va_list args)
{
    char			tmp_buffer[12];
    s16				i;
    s16				len;
    s16				*ip;
    u16         	num;
    char			*s;
    char			*hexchars;
    char			*str;
    s16				left_align;
    s16				plus_sign;
    s16				zero_pad;
    s16				space_sign;
    s16				field_width;
    s16				precision;

    for (str=buf ; *fmt ; ++fmt)
    {
        if (*fmt != '%')
        {
            *str++ = *fmt;
            continue;
        }

        space_sign = zero_pad = plus_sign = left_align = 0;

        // Process the flags
repeat:
        ++fmt;		// this also skips first '%'

        switch (*fmt)
        {
        case '-':
            left_align = 1;
            goto repeat;

        case '+':
            plus_sign = 1;
            goto repeat;

        case ' ':
            if (!plus_sign)
                space_sign = 1;
            goto repeat;

        case '0':
            zero_pad = 1;
            goto repeat;
        }

        // Process field width and precision

        field_width = precision = -1;

        if (isdigit(*fmt))
            field_width = skip_atoi(&fmt);
        else if (*fmt == '*')
        {
            ++fmt;
            // it's the next argument
            field_width = va_arg(args, s16);
            if (field_width < 0)
            {
                field_width = -field_width;
                left_align = 1;
            }
        }

        if (*fmt == '.')
        {
            ++fmt;
            if (isdigit(*fmt))
                precision = skip_atoi(&fmt);
            else if (*fmt == '*')
            {
                ++fmt;
                // it's the next argument
                precision = va_arg(args, s16);
            }

            if (precision < 0)
                precision = 0;
        }

        if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L')
        {
            ++fmt;
        }

        if (left_align)
            zero_pad = 0;

        switch (*fmt)
        {
        case 'c':
            if (!left_align)
                while (--field_width > 0)
                    *str++ = ' ';

//.........这里部分代码省略.........
开发者ID:moon-watcher,项目名称:GrielsQuest,代码行数:101,代码来源:text.c


示例19: _stp_vsnprintf

static int _stp_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
	int len;
	uint64_t num;
	int i, base;
	char *str, *end, c;
	const char *s;
	enum print_flag flags;		/* flags to number() */
	int field_width;	/* width of output field */
	int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
	int qualifier;		/* 'h', 'l', or 'L' for integer fields */

	/* Reject out-of-range values early */
	if (unlikely((int) size < 0))
		return 0;

	/*
	 * buf will be NULL when this function is called from _stp_printf.
	 * This branch calculates the exact size print buffer required for 
	 * the string and allocates it with _stp_reserve_bytes. A change
	 * to this branch requires a corresponding change to the same 
	 * section of code below.
	 */
	if (buf == NULL) {
	  const char* fmt_copy = fmt;
	  int num_bytes = 0;
          va_list args_copy;

          va_copy(args_copy, args);

          for (; *fmt_copy ; ++fmt_copy) {
                    if (*fmt_copy != '%') {
                            num_bytes++;
                            continue;
                    }

                    /* process flags */
                    flags = 0;
            repeat_copy:
                    ++fmt_copy;          /* this also skips first '%' */
                    switch (*fmt_copy) {
                    case '-': flags |= STP_LEFT; goto repeat_copy;
                    case '+': flags |= STP_PLUS; goto repeat_copy;
                    case ' ': flags |= STP_SPACE; goto repeat_copy;
                    case '#': flags |= STP_SPECIAL; goto repeat_copy;
                    case '0': flags |= STP_ZEROPAD; goto repeat_copy;
                    }

                    /* get field width */
                    field_width = -1;
                    if (isdigit(*fmt_copy))
                            field_width = clamp(skip_atoi(&fmt_copy), 0, STP_BUFFER_SIZE);
                    else if (*fmt_copy == '*') {
                            ++fmt_copy;
                            /* it's the next argument */
                            field_width = va_arg(args_copy, int);
                            if (field_width < 0) {
                                    field_width = -field_width;
                                    flags |= STP_LEFT;
                            }
                            field_width = clamp(field_width, 0, STP_BUFFER_SIZE);
                    }

                    /* get the precision */
                    precision = -1;
                    if (*fmt_copy == '.') {
                            ++fmt_copy;
                            if (isdigit(*fmt_copy))
                                    precision = skip_atoi(&fmt_copy);
                            else if (*fmt_copy == '*') {
                                    ++fmt_copy;
                                    /* it's the next argument */
                                    precision = va_arg(args_copy, int);
                            }
                            precision = clamp(precision, 0, STP_BUFFER_SIZE);
                    }
开发者ID:AMCScarface,项目名称:misc,代码行数:77,代码来源:vsprintf.c


示例20: nprintf

void nprintf(unsigned char *buf, uint32_t size, const char *fmt, va_list args)
{
  int32_t num;
  //	int i, len;
  unsigned char *str, *end;//, c;
  //	const char *s;
  
  uint8_t base;			/* the base of number */
  uint8_t flags;			/* flags to print number */
  uint8_t qualifier;		/* 'h', 'l', or 'L' for integer fields */
  int32_t field_width;	/* width of output field */
  
  str = buf;
  end = buf + size - 1;
  /* Make sure end is always >= buf */
  if (end < buf)
  {
    end = ((unsigned char *)-1);
    size = end - buf;
  }
  
  for (; *fmt ; ++fmt)
  {
    if (*fmt != '%')
    {
      if (str <= end) *str = *fmt;
      ++str;
      continue;
    }
    /* process flags */
    flags = 0;
    while(1)
    {
      /* skips the first '%' also */
      ++fmt;
      if (*fmt == '-') flags |= LEFT;
      else if (*fmt == '+') flags |= PLUS;
      else if (*fmt == ' ') flags |= SPACE;
      else if (*fmt == '#') flags |= SPECIAL;
      else if (*fmt == '0') flags |= ZEROPAD;
      else break;
    }
    
    /* get field width */
    field_width = -1;
    if (isdigit(*fmt)) field_width = skip_atoi(&fmt);
    else if (*fmt == '*')
    {
      ++fmt;
      /* it's the next argument */
      field_width = va_arg(args, int);
      if (field_width < 0)
      {
        field_width = -field_width;
        flags |= LEFT;
      }
    }
    /* get the conversion qualifier */
    qualifier = 0;
    if (*fmt == 'h' || *fmt == 'l')
    {
      qualifier = *fmt;
      ++fmt;
    }
    /* the default base */
    base = 10;
    switch (*fmt)
    {      
    case '%':
      if (str <= end) *str = '%';
      ++str;
      continue;
      /* integer number formats - set up the flags and "break" */
    case 'o':
      base = 8;
      break;
      
    case 'X':
      flags |= LARGE;
    case 'x':
      base = 16;
      break;
      
    case 'd':
    case 'i':
      flags |= SIGN;
    case 'u':
      break;
      
    default:
      if (str <= end) *str = '%';
      ++str;
      if (*fmt)
      {
        if (str <= end) *str = *fmt;
        ++str;
      }
      else
      {
        --fmt;
//.........这里部分代码省略.........
开发者ID:ririyeye,项目名称:by9010gai,代码行数:101,代码来源:ssprintf.c



注:本文中的skip_atoi函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ skip_bits函数代码示例发布时间:2022-05-30
下一篇:
C++ skipWhitespace函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap