📄 frmwri.c
字号:
{
case 'l':
case 'L':
l_L_modifier++;
format++;
break;
case 'h':
h_modifier++;
format++;
break;
}
/*===================================================*/
/* At exit from the following switch, we will emit */
/* the characters starting at "buf_pointer" and */
/* ending at "ptr"-1 */
/*===================================================*/
switch (format_flag = *format++)
{
case 'n':
if (sizeof(short) == sizeof(long))
{
*VAPTR(int) = nr_of_chars;
}
else if (sizeof(short) != sizeof(int))
{
if (sizeof(int) != sizeof(long))
{
if (h_modifier)
*VAPTR(short) = nr_of_chars;
else if (l_L_modifier)
*VAPTR(long) = nr_of_chars;
else
*VAPTR(int) = nr_of_chars;
}
else
{
if (h_modifier)
*VAPTR(short) = nr_of_chars;
else
*VAPTR(int) = nr_of_chars;
}
}
else
{
if (l_L_modifier)
*VAPTR(long) = nr_of_chars;
else
*VAPTR(int) = nr_of_chars;
}
continue;
case 'c':
buf[0] = va_arg(ap, int);
ptr++;
break;
case 's':
if ( !(buf_pointer = VAPTR(char)) )
buf_pointer = "(null pointer)";
if (precision < 0)
precision = 10000;
for (n=0; *buf_pointer++ && n < precision; n++)
;
ptr = --buf_pointer;
buf_pointer -= n;
break;
case 'o':
if (alternate_flag && !precision)
precision++;
case 'x':
hex = "0123456789abcdef";
case 'u':
case 'p':
case 'X':
if (format_flag == 'p')
ulong = (long)VAPTR(char);
else if (sizeof(short) == sizeof(long))
ulong = va_arg(ap,unsigned int);
else if (sizeof(short) == sizeof(int))
ulong = l_L_modifier ?
va_arg(ap,long) : va_arg(ap,unsigned int);
else
ulong = h_modifier ?
(unsigned short) va_arg(ap, int) : va_arg(ap, int);
div_factor = (format_flag == 'o') ?
8 : (format_flag == 'u') ? 10 : 16;
plus_space_flag = 0;
goto INTEGRAL_CONVERSION;
case 'd':
case 'i':
if (sizeof(short) == sizeof(long))
{
if ( (long)(ulong = va_arg(ap,long)) < 0)
{
plus_space_flag = '-';
ulong = -ulong;
}
}
else if (sizeof(short) == sizeof(int))
{
if ( (long)(ulong = l_L_modifier ?
va_arg(ap,long) : (long) va_arg(ap,int)) < 0)
{
plus_space_flag = '-';
ulong = -ulong;
}
}
else
{
if ( (long)(ulong = (long) (h_modifier ?
(short) va_arg(ap, int) : va_arg(ap,int))) < 0)
{
plus_space_flag = '-';
ulong = -ulong;
}
}
div_factor = 10;
/*=======================*/
/* now convert to digits */
/*=======================*/
INTEGRAL_CONVERSION:
ptr = buf_pointer = &buf[FRMWRI_BUFSIZE - 1];
nonzero_value = (ulong != 0);
if (precision != 0 || nonzero_value)
/* No char if zero and zero precision */
do
*--buf_pointer = hex[ulong % div_factor];
while (ulong /= div_factor);
if (precision < 0) /* "precision" takes precedence */
if (zeropad)
precision = field_width - (plus_space_flag != 0);
while (precision > ptr - buf_pointer)
*--buf_pointer = '0';
if (alternate_flag && nonzero_value)
{
if (format_flag == 'x' || format_flag == 'X')
{
*--buf_pointer = format_flag;
*--buf_pointer = '0';
}
else if ((format_flag == 'o') && (*buf_pointer != '0'))
{
*--buf_pointer = '0';
}
}
break;
#ifdef FLOAT_SUPPORT
case 'g':
case 'G':
n = 1;
format_flag -= 2;
if (! precision)
{
precision = 1;
}
goto FLOATING_CONVERSION;
case 'f':
format_flag = 0;
case 'e':
case 'E':
n = 0;
FLOATING_CONVERSION:
if (precision < 0)
{
precision = 6;
}
if (sizeof(double) != sizeof(long double))
{
if ( (fvalue = l_L_modifier ?
va_arg(ap,long double) : va_arg(ap,double)) < 0)
{
plus_space_flag = '-';
fvalue = -fvalue;
}
}
else if ( (fvalue = va_arg(ap,long double)) < 0)
{
plus_space_flag = '-';
fvalue = -fvalue;
}
ptr = float_conversion(fvalue,
precision,
buf_pointer += field_width,
format_flag,
n,
alternate_flag);
if (zeropad)
{
precision = field_width - (plus_space_flag != 0);
while (precision > ptr - buf_pointer)
*--buf_pointer = '0';
}
#else
case 'g':
case 'G':
case 'f':
case 'e':
case 'E':
ptr = buf_pointer = "FLOATS? wrong formatter installed!";
while (*ptr)
ptr++;
#endif
break;
case '\0': /* Really bad place to find NUL in */
format--;
default:
/*=======================*/
/* Undefined conversion! */
/*=======================*/
ptr = buf_pointer = "???";
ptr += 3;
break;
}
/*===========================================================*/
/* This part emittes the formatted string to "put_one_char". */
/*===========================================================*/
/* If field_width == 0 then nothing should be written. */
precision = ptr - buf_pointer;
if (precision > field_width)
{
n = 0;
}
else
{
n = field_width - precision - (plus_space_flag != 0);
}
/*=================================*/
/* emit any leading pad characters */
/*=================================*/
if (!left_adjust)
while (--n >= 0)
{
put_one_char(' ', secret_pointer);
nr_of_chars++;
}
/*===============================*/
/* emit flag characters (if any) */
/*===============================*/
if (plus_space_flag)
{
put_one_char(plus_space_flag, secret_pointer);
nr_of_chars++;
}
/*========================*/
/* emit the string itself */
/*========================*/
while (--precision >= 0)
{
put_one_char(*buf_pointer++, secret_pointer);
nr_of_chars++;
}
/*================================*/
/* emit trailing space characters */
/*================================*/
if (left_adjust)
while (--n >= 0)
{
put_one_char(' ', secret_pointer);
nr_of_chars++;
}
}
}
#else /* REDUCED_SUPPORT STARTS HERE */
{
#ifdef MODIFIERS_IN_REDUCED
char l_modifier, h_modifier;
unsigned long u_val, div_val;
#else
unsigned int u_val, div_val;
#endif
char format_flag;
unsigned int nr_of_chars, base;
char outChar;
char *ptr;
nr_of_chars = 0;
for (;;) /* Until full format string read */
{
while ((format_flag = *format++) != '%') /* Until '%' or '\0' */
{
if (!format_flag)
return nr_of_chars;
put_one_char (format_flag, secret_pointer);
nr_of_chars++;
}
#ifdef MODIFIERS_IN_REDUCED
/*=================================*/
/* Optional 'l' or 'h' modifiers ? */
/*=================================*/
l_modifier = h_modifier = 0;
switch (*format)
{
case 'l':
l_modifier = 1;
format++;
break;
case 'h':
h_modifier = 1;
format++;
break;
}
#endif
switch (format_flag = *format++)
{
case 'c':
format_flag = va_arg(ap, int);
default:
put_one_char(format_flag, secret_pointer);
nr_of_chars++;
continue;
case 's':
ptr = VAPTR(char);
while (format_flag = *ptr++)
{
put_one_char(format_flag, secret_pointer);
nr_of_chars++;
}
continue;
case 'o':
base = 8;
if (IS_SHORT)
div_val = 0x8000;
else
div_val = 0x40000000;
goto CONVERSION_LOOP;
case 'd':
base = 10;
if (IS_SHORT)
div_val = 10000;
else
div_val = 1000000000;
goto CONVERSION_LOOP;
case 'X':
case 'x':
base = 16;
if (IS_SHORT)
div_val = 0x1000;
else
div_val = 0x10000000;
CONVERSION_LOOP:
#ifdef MODIFIERS_IN_REDUCED
if (h_modifier)
u_val = (format_flag == 'd') ?
(unsigned long) (short) va_arg(ap, int) :
(unsigned long) (unsigned short) va_arg(ap, int);
else if (l_modifier)
u_val = va_arg(ap, long);
else
u_val = (format_flag == 'd') ?
(unsigned long) va_arg(ap,int) :
(unsigned long) va_arg(ap,unsigned int);
if (format_flag == 'd')
{
if (((long)u_val) < 0)
#else
u_val = va_arg(ap,int);
if (format_flag == 'd')
{
if (((int)u_val) < 0)
#endif
{
u_val = - u_val;
put_one_char('-', secret_pointer);
nr_of_chars++;
}
}
while (div_val > 1 && div_val > u_val)
{
div_val /= base;
}
do
{
outChar = (u_val / div_val) + '0';
if (outChar > '9')
if (format_flag == 'x')
outChar += 'a'-'9'-1;
else
outChar += 'A'-'9'-1;
put_one_char(outChar, secret_pointer);
nr_of_chars++;
u_val %= div_val;
div_val /= base;
}
while (div_val);
}
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -