25 #include "pedigree/kernel/processor/types.h" 26 #include "pedigree/kernel/utilities/utility.h" 30 #pragma GCC diagnostic ignored "-Wgnu-statement-expression" 34 #define is_digit(c) ((c) >= '0' && (c) <= '9') 36 static int skip_atoi(
const char **s)
41 i = i * 10 + *((*s)++) -
'0';
54 #if defined(X86_COMMON) || defined(HOSTED_X86_COMMON) || defined(UTILITY_LINUX) 55 #define do_div(n, base) \ 58 __asm__("div %4" : "=a"(n), "=d"(__res) : "0"(n), "1"(0), "r"(base)); \ 62 #define do_div(n, base) ({ n / base; }) 66 number(
char *str, int64_t num,
int base,
int size,
int precision,
int type)
68 char c, sign, tmp[36];
69 const char *digits =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
73 digits =
"0123456789abcdefghijklmnopqrstuvwxyz";
76 if (base < 2 || base > 36)
78 c = (type & ZEROPAD) ?
'0' :
' ';
79 if (type & SIGN && num < 0)
85 sign = (type & PLUS) ?
'+' : ((type & SPACE) ?
' ' : 0);
101 int d = do_div(num, base);
102 tmp[i++] = digits[d];
107 if (!(type & (ZEROPAD + LEFT)))
125 while (i < precision--)
134 int VStringFormat(
char *buf,
const char *fmt, va_list args)
149 for (str = buf; *fmt; ++fmt)
183 field_width = skip_atoi(&fmt);
184 else if (*fmt ==
'*')
187 field_width = va_arg(args,
int);
190 field_width = -field_width;
201 precision = skip_atoi(&fmt);
202 else if (*fmt ==
'*')
205 precision = va_arg(args,
int);
213 if (*fmt ==
'h' || *fmt ==
'l' || *fmt ==
'L')
223 while (--field_width > 0)
225 *str++ = (
unsigned char) va_arg(args,
int);
226 while (--field_width > 0)
231 s = va_arg(args,
char *);
232 len = StringLength(s);
235 else if (len > precision)
239 while (len < field_width--)
241 for (i = 0; i < len; ++i)
243 while (len < field_width--)
249 str, va_arg(args,
unsigned long), 8, field_width, precision,
254 if (field_width == -1)
256 field_width =
sizeof(
void *) * 2;
260 str, (uintptr_t) va_arg(args,
void *), 16, field_width,
268 str, va_arg(args,
unsigned long), 16, field_width,
277 str, va_arg(args,
unsigned long), 10, field_width,
282 ip = va_arg(args,
int *);