📄 stdiop.c
字号:
else
state = 8;
break;
/*-----------------------------------------------------------------*/
/* State 7 fetches an int from list of args to be the precision. */
/*-----------------------------------------------------------------*/
case 7:
precision = va_arg(list_of_args, int);
/*---------------------------------------------------------------*/
/* If precision is negative, set it to 0. */
/*---------------------------------------------------------------*/
if (precision < 0)
precision = 0;
state = 8;
break;
/*-----------------------------------------------------------------*/
/* State 8 checks for 'l', 'L', 'h'. */
/*-----------------------------------------------------------------*/
case 8:
++format;
if (c == 'l')
special_value = l_VALUE;
else if (c == 'L')
special_value = L_VALUE;
else if (c == 'h')
special_value = h_VALUE;
else
--format;
state = 9;
break;
/*-----------------------------------------------------------------*/
/* State 9 checks for conversion specifiers ('x', 'd', etc). */
/*-----------------------------------------------------------------*/
case 9:
++format;
if (c == 'c')
state = 10;
else if (c == 'i' || c == 'd')
state = 11;
else if (c == 'n')
state = 12;
else if (c == 'o')
state = 13;
else if (c == 'p')
state = 14;
else if (c == 'x' || c == 'X')
{
/*-------------------------------------------------------------*/
/* Sets x to distinguish later between 'x' and 'X'. */
/*-------------------------------------------------------------*/
x = (c == 'x') ? 1 : 0;
state = 15;
}
else if (c == 's')
state = 16;
else if (c == 'u')
state = 17;
else
{
/*-------------------------------------------------------------*/
/* Go back to initial state. */
/*-------------------------------------------------------------*/
state = 0;
--format;
}
break;
/*-----------------------------------------------------------------*/
/* State 10 handles the 'c' specifier. */
/*-----------------------------------------------------------------*/
case 10:
buf[BUF_BYTES - 1] = (char)va_arg(list_of_args, int);
/*---------------------------------------------------------------*/
/* Send buf to be printed. */
/*---------------------------------------------------------------*/
bytes = print_buf(stream, buf, BUF_BYTES, BUF_BYTES - 1, flags,
S_SPEC, width, precision);
if (bytes == -1)
return -1;
count += bytes;
state = 0;
break;
/*-----------------------------------------------------------------*/
/* State 11 handles the 'i' and 'd' specifiers */
/*-----------------------------------------------------------------*/
case 11:
/*---------------------------------------------------------------*/
/* Based on the special value get the correct argument */
/*---------------------------------------------------------------*/
if (special_value == h_VALUE)
val = (i16)va_arg(list_of_args, int);
else if (special_value == l_VALUE)
val = va_arg(list_of_args, long);
else
val = va_arg(list_of_args, int);
/*---------------------------------------------------------------*/
/* If val is negative, put '-' in front and make it positive. */
/*---------------------------------------------------------------*/
if (val < 0)
{
sign = 1;
val = -val;
}
else
sign = 0;
start = trnsfrm_val(buf, (ui32)val, 10, 0, precision);
if (sign)
{
if (start > 0) --start;
buf[start] = '-';
}
/*---------------------------------------------------------------*/
/* Send buf to be printed. */
/*---------------------------------------------------------------*/
bytes = print_buf(stream, buf, BUF_BYTES, start, flags, DI_SPEC,
width, precision);
if (bytes == -1)
return -1;
count += bytes;
/*---------------------------------------------------------------*/
/* Go back to initial state. */
/*---------------------------------------------------------------*/
state = 0;
break;
/*-----------------------------------------------------------------*/
/* State 12 handles the 'n' specifier. */
/*-----------------------------------------------------------------*/
case 12:
/*---------------------------------------------------------------*/
/* Based on special_value get correct ptr, and store count. */
/*---------------------------------------------------------------*/
if (special_value == h_VALUE)
*va_arg(list_of_args, i16 *) = (i16)count;
else if (special_value == l_VALUE)
*va_arg(list_of_args, i32 *) = count;
else
*va_arg(list_of_args, int *) = count;
/*---------------------------------------------------------------*/
/* Go back to initial state. */
/*---------------------------------------------------------------*/
state = 0;
break;
/*-----------------------------------------------------------------*/
/* State 13 handles the 'o' specifier. */
/*-----------------------------------------------------------------*/
case 13:
/*---------------------------------------------------------------*/
/* Based on special_value get the correct argument. */
/*---------------------------------------------------------------*/
if (special_value == h_VALUE)
unsigned_val = (ui16)va_arg(list_of_args, int);
else if (special_value == l_VALUE)
unsigned_val = (ui32)va_arg(list_of_args, long);
else
unsigned_val = (uint)va_arg(list_of_args, int);
start = trnsfrm_val(buf, unsigned_val, 8, 0, precision);
/*---------------------------------------------------------------*/
/* If '#' flag is set, add a '0' in front of the number. */
/*---------------------------------------------------------------*/
if (flags & NUM_FLAG)
{
if (start > 0) --start;
buf[start] = '0';
}
/*---------------------------------------------------------------*/
/* Send buf to be printed. */
/*---------------------------------------------------------------*/
bytes = print_buf(stream, buf, BUF_BYTES, start, flags, UO_SPEC,
width, precision);
if (bytes == -1)
return -1;
count += bytes;
/*---------------------------------------------------------------*/
/* Go back to initial state. */
/*---------------------------------------------------------------*/
state = 0;
break;
/*-----------------------------------------------------------------*/
/* State 14 handles the 'p' specifier. */
/*-----------------------------------------------------------------*/
case 14:
p = (int)va_arg(list_of_args, void *);
start = trnsfrm_val(buf, (ui32)p, 16, 0, precision);
/*---------------------------------------------------------------*/
/* Send buf to be printed. */
/*---------------------------------------------------------------*/
bytes = print_buf(stream, buf, BUF_BYTES, start, 0, P_SPEC, width,
precision);
if (bytes == -1)
return -1;
count += bytes;
/*---------------------------------------------------------------*/
/* Go back to initial state. */
/*---------------------------------------------------------------*/
state = 0;
break;
/*-----------------------------------------------------------------*/
/* State 15 handles the 'x' and 'X' specifiers. */
/*-----------------------------------------------------------------*/
case 15:
/*---------------------------------------------------------------*/
/* Based on special_value get the correct argument. */
/*---------------------------------------------------------------*/
if (special_value == h_VALUE)
unsigned_val = (ui16)va_arg(list_of_args, int);
else if (special_value == l_VALUE)
unsigned_val = (ui32)va_arg(list_of_args, long);
else
unsigned_val = (uint)va_arg(list_of_args, int);
start = trnsfrm_val(buf, unsigned_val, 16, x, precision);
/*---------------------------------------------------------------*/
/* If '#' flag is set, add '0x' or '0X' on front of the number. */
/*---------------------------------------------------------------*/
if (flags & NUM_FLAG)
{
if (start > 0) --start;
if (start > 0) --start;
buf[start + 1] = (char)(x ? 'x' : 'X');
buf[start] = '0';
}
/*---------------------------------------------------------------*/
/* Send buf to be printed. */
/*---------------------------------------------------------------*/
bytes = print_buf(stream, buf, BUF_BYTES, start, flags, X_SPEC,
width, precision);
if (bytes == -1)
return -1;
count += bytes;
/*---------------------------------------------------------------*/
/* Go back to initial state. */
/*---------------------------------------------------------------*/
state = 0;
break;
/*-----------------------------------------------------------------*/
/* State 16 handles the 's' specifier. */
/*-----------------------------------------------------------------*/
case 16:
/*---------------------------------------------------------------*/
/* Get the string and figure out how many chars to output. */
/*---------------------------------------------------------------*/
str = va_arg(list_of_args, i8 *);
length = (int)strlen(str);
if (precision && precision < length)
length = precision;
/*---------------------------------------------------------------*/
/* Clear out the PLUS_, SPACE_, or ZERO_ FLAGS if present. */
/*---------------------------------------------------------------*/
flags &= ~(PLUS_FLAG | SPACE_FLAG | ZERO_FLAG);
/*---------------------------------------------------------------*/
/* Send buf to be printed. */
/*---------------------------------------------------------------*/
bytes = print_buf(stream, str, length, 0, flags, S_SPEC, width, 0);
if (bytes == -1)
return -1;
count += bytes;
/*---------------------------------------------------------------*/
/* Go back to initial state. */
/*---------------------------------------------------------------*/
state = 0;
break;
/*-----------------------------------------------------------------*/
/* State 17 handles the 'u' specifier. */
/*-----------------------------------------------------------------*/
case 17:
/*---------------------------------------------------------------*/
/* Based on special_value get the correct argument. */
/*---------------------------------------------------------------*/
if (special_value == h_VALUE)
unsigned_val = (ui16)va_arg(list_of_args, int);
else if (special_value == l_VALUE)
unsigned_val = (ui32)va_arg(list_of_args, long);
else
unsigned_val = (uint)va_arg(list_of_args, int);
start = trnsfrm_val(buf, unsigned_val, 10, 0, precision);
/*---------------------------------------------------------------*/
/* Send buf to be printed. */
/*---------------------------------------------------------------*/
bytes = print_buf(stream, buf, BUF_BYTES, start, flags, UO_SPEC,
width, precision);
if (bytes == -1)
return -1;
count += bytes;
/*---------------------------------------------------------------*/
/* Go back to initial state. */
/*---------------------------------------------------------------*/
state = 0;
break;
default:
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -