📄 pollio.c
字号:
} while (val >>= 4);
while (t_count < f_flags->precision)
{
*(pt--) = '0';
t_count++;
}
/*---------------------------------------------------------------------*/
/* Next check to see if the 0 flag was used in the format and if the */
/* current count is less than the specified field width. If TRUE then */
/* fill in the leading zeros. Temporarily leave room in the field for */
/* an optional plus or minus sign. */
/*---------------------------------------------------------------------*/
pt++;
if (f_flags->zero)
{
s_length = strlen(pt);
if (f_flags->alter)
while (f_flags->width > s_length+2)
{
*(--pt) = '0';
s_length += 1;
}
else
while (f_flags->width > s_length)
{
*(--pt) = '0';
s_length += 1;
}
}
/*---------------------------------------------------------------------*/
/* If the "alternate form" flag is set, add 0x or 0X to the front of */
/* the string. */
/*---------------------------------------------------------------------*/
if (f_flags->alter)
{
if (f_flags->type == 'x')
*(--pt) = 'x';
else
*(--pt) = 'X';
*(--pt) = '0';
}
f_flags->precision = DEFAULT;
strout(f_flags, pt, strlen(pt));
}
/***********************************************************************/
/* strout: Output a formatted string, adding fill characters and */
/* field justification. */
/* */
/* INPUTS: f_flags = ptr to format data structure */
/* str = ptr to string */
/* len = length of string */
/* */
/***********************************************************************/
static void strout(FORMAT *f_flags, UCHAR *str, long len)
{
long size;
ULONG i, count = 0;
UCHAR pad = ' ';
/*---------------------------------------------------------------------*/
/* Check for a NULL string. */
/*---------------------------------------------------------------------*/
if (len == 0)
str = (UCHAR *)"(null)";
/*---------------------------------------------------------------------*/
/* Calculate the field width. */
/*---------------------------------------------------------------------*/
f_flags->count += len;
size = (f_flags->width < len ) ? len : f_flags->width;
/*---------------------------------------------------------------------*/
/* If the right justified field is set, fill the leading characters */
/* with blanks. */
/*---------------------------------------------------------------------*/
if (f_flags->right)
{
for (i = size - len; i > 0; i--)
{
putb(pad);
count++;
}
size = len;
}
/*---------------------------------------------------------------------*/
/* Output the string. */
/*---------------------------------------------------------------------*/
while (*str != '\0' && len > 0)
{
putb(*str++);
len--;
size--;
}
/*---------------------------------------------------------------------*/
/* If left justified, it may be necessary to pad end of the string. */
/*---------------------------------------------------------------------*/
for (i = size - len; i > 0; i--)
{
putb(pad);
count++;
}
f_flags->count += count;
}
/***********************************************************************/
/* Print: Format output and send it to the console */
/* */
/* INPUTS: format = ptr to format string */
/* additional inputs as specified by *format. */
/* */
/* RETURNS: # of characters output */
/* NOTE: Format strings are explained in the header at the */
/* top of this module. */
/* */
/***********************************************************************/
ULONG Print(char *format, ...)
{
ULONG ip_addr, ch;
FORMAT f_flags;
BUFFER buf;
va_list arg_pt;
/*
* 泅犁 Serial Port啊 窍唱捞骨肺 Racing Condition 惑炔捞 积扁骨肺
* 捞巴阑 规瘤窍扁困秦辑 碍力肺 Timer Interrrupt甫 Disable 矫挪促.
* OS Performance甫 惑寸洒 历窍矫虐绰 夸牢捞 惯积.
* Enable_Intr(nINT_TIMER0)
* Disable_Intr(nINT_TIMER0)
*/
buf.ptr = buf.buff;
buf.end = &buf.buff[BUFFSIZE-1];
va_start(arg_pt, format);
f_flags.count = 0;
if (format == NULL)
format = (char *)"(null)";
/*---------------------------------------------------------------------*/
/* Process characters in 'format ' string until null terminator is */
/* reached. If the character is not a '%' then simply print it. */
/* Otherwise it will require further processing. */
/*---------------------------------------------------------------------*/
while (*format != '\0')
{
if (*format != '%')
{
putb(*format++);
f_flags.count++;
}
else
{
/*-------------------------------------------------------------*/
/* Set up the fields in the format structure. */
/*-------------------------------------------------------------*/
format++;
format = percent(format, &f_flags, &arg_pt);
/*-------------------------------------------------------------*/
/* Continue to process based on the format type: */
/* d,i - signed decimal */
/* x,X - unsigned hexadecimal */
/* c - print least significant character of int */
/* s - argument taken to be (char *) pointer to string */
/* % - A % is printed. No argument is converted. */
/* I - IP address (dd.dd.dd.dd) */
/*-------------------------------------------------------------*/
switch (f_flags.type)
{
case 'd':
case 'i':
decout(&f_flags, &arg_pt);
break;
case 'x':
case 'X':
hexout(&f_flags, &arg_pt);
break;
case 'c':
charout(&f_flags, &arg_pt);
break;
case 's':
stringout(&f_flags, &arg_pt);
break;
case '%':
putb('%');
f_flags.count++;
break;
case 'I':
ip_addr = va_arg((arg_pt), long);
Print("%d.%d.%d.%d", (ip_addr >> 24) & 0xFF,
(ip_addr >> 16) & 0xFF,
(ip_addr >> 8) & 0xFF,
ip_addr & 0xFF);
break;
default:
ch = ch;
break;
}
}
}
return f_flags.count;
}
/***********************************************************************/
/* percent: Interpret a conversion specification */
/* */
/* INPUTS: format = ptr to current position in format string */
/* arg_pt = ptr to next argument */
/* */
/* RETURNS: Ptr to next char in format string past this specifier. */
/* OUTPUTS: *f_flags = filled in with format specification */
/* */
/***********************************************************************/
static char *percent(char *format, FORMAT *f_flags, va_list *arg_pt)
{
UCHAR p_flag = FALSE;
/*---------------------------------------------------------------------*/
/* Initialize the f_flag structure with the default values. */
/*---------------------------------------------------------------------*/
f_flags->width = DEFAULT;
f_flags->precision = DEFAULT_P;
f_flags->right = LTRUE;
f_flags->plus = FALSE;
f_flags->alter = FALSE;
f_flags->zero = FALSE;
f_flags->space = FALSE;
f_flags->type = '\0';
f_flags->mod = '\0';
/*---------------------------------------------------------------------*/
/* Process the flags that may exists between the '%' and the start of */
/* the width specification. The following flags may exist: */
/* */
/* '-' to set left justified */
/* '+' result will always have sign (+ or -) */
/* space for leading space */
/* '#' for alternate form */
/* '0' use leading zeros instead of spaces. */
/* */
/* The sequence of these flags is important. */
/*---------------------------------------------------------------------*/
if (*format == '-')
{
f_flags->right = FALSE;
format++;
}
if (*format == '+')
{
f_flags->plus = LTRUE;
format++;
}
if (*format == ' ')
{
if (f_flags->plus == FALSE)
f_flags->space = LTRUE;
format++;
}
if (*format == '#')
{
f_flags->alter = LTRUE;
format++;
}
if (*format == '0')
{
if (f_flags->right)
f_flags->zero = LTRUE;
format++;
}
/*---------------------------------------------------------------------*/
/* Process the width specification of the format. The width can be */
/* specified by the next value in the arg_pt list. If the next */
/* character is '*' then get the width from arg_pt with a call to the */
/* va_arg() macro. */
/* */
/* The width can also be specified as a value in the format. In this */
/* case the width is specified by a decimal number. */
/*---------------------------------------------------------------------*/
if (*format == '*')
{
f_flags->width = va_arg((*arg_pt), int);
if (f_flags->width < 0)
{
f_flags->right = FALSE;
f_flags->width = -f_flags->width;
}
format++;
}
else
{
if (isdigit(*format))
for (f_flags->width = 0; isdigit(*format); )
f_flags->width = f_flags->width * 10 + *format++ - '0';
}
/*---------------------------------------------------------------------*/
/* Process the precision field. The same options that are allowed for */
/* the width field are permitted here. */
/*---------------------------------------------------------------------*/
if (*format == '.')
{
p_flag = LTRUE;
format++;
if (*format == '*')
{
f_flags->precision = va_arg((*arg_pt), int);
format++;
}
else
{
f_flags->precision = 0;
while (isdigit (*format))
f_flags->precision = f_flags->precision * 10 + *format++ - '0';
}
}
/*---------------------------------------------------------------------*/
/* Check for process modifier characters. {h, l, L} */
/*---------------------------------------------------------------------*/
if ((*format == 'h') || (*format == 'l') || (*format == 'L'))
f_flags->mod = *format++;
/*---------------------------------------------------------------------*/
/* Based on the type of conversion it may be necessary to readjust the */
/* precision flag to a default value of 0. */
/*---------------------------------------------------------------------*/
if ((p_flag == FALSE) && (*format != 'c') && (*format != '%'))
f_flags->precision = 0;
/*---------------------------------------------------------------------*/
/* The final step is to read in the conversion type. */
/*---------------------------------------------------------------------*/
f_flags->type = *format++;
return format;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -