// SPDX-License-Identifier: GPL-2.0-only /* -*- linux-c -*- ------------------------------------------------------- * * * Copyright (C) 1991, 1992 Linus Torvalds * Copyright 2007 rPath, Inc. - All Rights Reserved *
* ----------------------------------------------------------------------- */
/* * Oh, it's a waste of space, but oh-so-yummy for debugging. This * version of printf() does not include 64-bit support. "Live with * it." *
*/
#include"boot.h"
staticint skip_atoi(constchar **s)
{ int i = 0;
while (isdigit(**s))
i = i * 10 + *((*s)++) - '0'; return i;
}
#define ZEROPAD 1 /* pad with zero */ #define SIGN 2 /* unsigned/signed long */ #define PLUS 4 /* show plus */ #define SPACE 8 /* space if plus */ #define LEFT 16 /* left justified */ #define SMALL 32 /* Must be 32 == 0x20 */ #define SPECIAL 64 /* 0x */
staticchar *number(char *str, long num, int base, int size, int precision, int type)
{ /* we are called with base 8, 10 or 16, only, thus don't need "G..." */ staticconstchar digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
char tmp[66]; char c, sign, locase; int i;
/* locase = 0 or 0x20. ORing digits or letters with 'locase'
* produces same digits or (maybe lowercased) letters */
locase = (type & SMALL); if (type & LEFT)
type &= ~ZEROPAD; if (base < 2 || base > 16) return NULL;
c = (type & ZEROPAD) ? '0' : ' ';
sign = 0; if (type & SIGN) { if (num < 0) {
sign = '-';
num = -num;
size--;
} elseif (type & PLUS) {
sign = '+';
size--;
} elseif (type & SPACE) {
sign = ' ';
size--;
}
} if (type & SPECIAL) { if (base == 16)
size -= 2; elseif (base == 8)
size--;
}
i = 0; if (num == 0)
tmp[i++] = '0'; else while (num != 0)
tmp[i++] = (digits[__do_div(num, base)] | locase); if (i > precision)
precision = i;
size -= precision; if (!(type & (ZEROPAD + LEFT))) while (size-- > 0)
*str++ = ' '; if (sign)
*str++ = sign; if (type & SPECIAL) { if (base == 8)
*str++ = '0'; elseif (base == 16) {
*str++ = '0';
*str++ = ('X' | locase);
}
} if (!(type & LEFT)) while (size-- > 0)
*str++ = c; while (i < precision--)
*str++ = '0'; while (i-- > 0)
*str++ = tmp[i]; while (size-- > 0)
*str++ = ' '; return str;
}
int vsprintf(char *buf, constchar *fmt, va_list args)
{ int len; unsignedlong num; int i, base; char *str; constchar *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;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.