printf_x.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* Adapted from LinuxBIOS */
/*
*
*
* Copyright (C) 1991, 1992 Linus Torvalds
*
*/
/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
/*
* Wirzenius wrote this portably, Torvalds fucked it up :-)
*/
#include "etherboot.h"
#include <stdarg.h>
#include <lib.h>
/* haha, don't need ctype.c */
#define isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
static inline unsigned char __toupper(unsigned char c)
{
if (islower(c))
c -= 'a'-'A';
return c;
}
{
if (!base) {
base = 10;
if (*cp == '0') {
base = 8;
cp++;
cp++;
base = 16;
}
}
}
cp++;
}
if (endp)
return result;
}
{
if(*cp=='-')
}
{
unsigned long long result;
if (!endp) {
return 0;
}
case 'K':
result <<= 10;
++*endp;
break;
case 'M':
result <<= 20;
++*endp;
break;
case 'G':
result <<= 30;
++*endp;
break;
}
return result;
}
#if 0
// it can be used to substitute the vsprintf.c in etherboot. And it has better
// support in numeric output suppot
//When you want to debug filo, you need to enable it and disable vsprintf.c
// to get output from filo
// BY LYH
static int skip_atoi(const char **s)
{
int i=0;
while (is_digit(**s))
i = i*10 + *((*s)++) - '0';
return i;
}
int __res; \
n = ((unsigned long) n) / (unsigned) base; \
__res; })
,int type)
{
const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
int i;
int count = 0;
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return 0;
sign = 0;
if (num < 0) {
sign = '-';
size--;
sign = '+';
size--;
sign = ' ';
size--;
}
}
if (base == 16)
size -= 2;
else if (base == 8)
size--;
}
i = 0;
if (num == 0)
tmp[i++]='0';
else while (num != 0)
if (i > precision)
precision = i;
while(size-->0)
if (sign)
if (base==8)
else if (base==16) {
}
}
while (size-- > 0)
while (i < precision--)
while (i-- > 0)
while (size-- > 0)
return count;
}
{
int len;
unsigned long num;
int i, base;
const char *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 */
int count;
if (*fmt != '%') {
continue;
}
/* process flags */
flags = 0;
++fmt; /* this also skips first '%' */
switch (*fmt) {
}
/* get field width */
field_width = -1;
else if (*fmt == '*') {
++fmt;
/* it's the next argument */
if (field_width < 0) {
}
}
/* get the precision */
precision = -1;
if (*fmt == '.') {
++fmt;
else if (*fmt == '*') {
++fmt;
/* it's the next argument */
}
if (precision < 0)
precision = 0;
}
/* get the conversion qualifier */
qualifier = -1;
++fmt;
}
/* default base */
base = 10;
switch (*fmt) {
case 'c':
while (--field_width > 0)
while (--field_width > 0)
continue;
case 's':
if (!s)
s = "<NULL>";
while (len < field_width--)
for (i = 0; i < len; ++i)
while (len < field_width--)
continue;
case 'p':
if (field_width == -1) {
field_width = 2*sizeof(void *);
}
continue;
case 'n':
if (qualifier == 'l') {
} else {
}
continue;
case '%':
continue;
/* integer number formats - set up the flags and "break" */
case 'o':
base = 8;
break;
case 'X':
case 'x':
base = 16;
break;
case 'd':
case 'i':
case 'u':
break;
default:
if (*fmt)
else
--fmt;
continue;
}
if (qualifier == 'L')
else if (qualifier == 'l')
else if (qualifier == 'h') {
else
}
return count;
}
/* FIXME this global makes vsprintf non-reentrant
*/
static char *str_buf;
static int str_tx_byte(int byte)
{
str_buf++;
return byte;
}
{
int i;
/* and was just zeroing out the pointer instead */
*str_buf = '\0';
return i;
}
{
int i;
return i;
}
{
int i;
return i;
}
#endif