2004-09-17 Theodore A. Roth
* libc/stdio/vfprintf.c: Evil hack to try to make '%llu' work. This doesn't seem to work. :-( Index: libc/stdio/vfprintf.c =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/libc/stdio/vfprintf.c,v retrieving revision 1.9 diff -u -p -p -r1.9 vfprintf.c --- libc/stdio/vfprintf.c 21 Jul 2004 22:11:59 -0000 1.9 +++ libc/stdio/vfprintf.c 17 Sep 2004 21:04:50 -0000 @@ -68,21 +68,22 @@ #define FLHASPERCENT 0x01 /* first % found */ #define FLNEGATIVE 0x02 /* arg is negative int */ #define FLLONG 0x04 /* arg is long int */ +#define FLLONGLONG 0x08 /* arg is long long int */ #endif #if PRINTF_LEVEL >= PRINTF_STD -#define FLPREC 0x08 /* .prec given */ -#define FLSIGNPLUS 0x10 /* always print '+' sign */ -#define FLSIGN 0x20 /* always print sign */ -#define FLALT 0x40 /* # alternate specification given */ -#define FLLPAD 0x80 /* left-align result */ -#define FLZFILL 0x100 /* zero-fill up to width */ +#define FLPREC 0x10 /* .prec given */ +#define FLSIGNPLUS 0x20 /* always print '+' sign */ +#define FLSIGN 0x40 /* always print sign */ +#define FLALT 0x80 /* # alternate specification given */ +#define FLLPAD 0x100 /* left-align result */ +#define FLZFILL 0x200 /* zero-fill up to width */ #endif #if PRINTF_LEVEL >= PRINTF_FLT -#define FLFLOAT 0x200 /* floating-point conversion */ -#define FLFCVT 0x400 /* do style `f' if set, style `e' if clear */ -#define FLGCVT 0x800 /* %g format, decide about %e or %f */ +#define FLFLOAT 0x400 /* floating-point conversion */ +#define FLFCVT 0x800 /* do style `f' if set, style `e' if clear */ +#define FLGCVT 0x1000 /* %g format, decide about %e or %f */ /* With 4-byte floats, we can get up to 39 digits. */ #define FLTBUFLEN 40 @@ -91,7 +92,8 @@ static int8_t flcvt(char *buf, double ar #endif /* PRINTF_LEVEL >= PRINTF_FLT */ /* Integer conversion buffer length. */ -#define BUFLEN 12 +//#define BUFLEN 12 +#define BUFLEN 50 int vfprintf(FILE *stream, const char *fmt, va_list ap) { @@ -100,7 +102,9 @@ vfprintf(FILE *stream, const char *fmt, uint8_t u8; int8_t i8; long l; + long long ll; unsigned long ul; + unsigned long long ull; char *pc; #if PRINTF_LEVEL >= PRINTF_FLT double d; @@ -317,7 +321,10 @@ vfprintf(FILE *stream, const char *fmt, #endif /* PRINTF_LEVEL > PRINTF_MIN */ break; case 'l': - flags |= FLLONG; + if (flags & FLLONG) + flags |= FLLONGLONG; + else + flags |= FLLONG; break; #if PRINTF_LEVEL < PRINTF_FLT case 'e': @@ -351,13 +358,24 @@ vfprintf(FILE *stream, const char *fmt, goto nextitem; case 'd': case 'i': - a.l = flags & FLLONG ? - va_arg(ap, long): - va_arg(ap, int); - if (a.l < 0) { - flags |= FLNEGATIVE; - a.l = -a.l; - } + if (flags & FLLONGLONG) + { + a.ll = va_arg(ap, long long); + if (a.ll < 0) { + flags |= FLNEGATIVE; + a.ll = -a.ll; + } + } + else + { + a.l = flags & FLLONG ? + va_arg(ap, long): + va_arg(ap, int); + if (a.l < 0) { + flags |= FLNEGATIVE; + a.l = -a.l; + } + } #if PRINTF_LEVEL > PRINTF_MIN flags &= ~FLALT; #endif @@ -377,22 +395,43 @@ vfprintf(FILE *stream, const char *fmt, /* FALLTHROUGH */ case 'u': getulong: - a.ul = flags & FLLONG? - va_arg(ap, unsigned long): - va_arg(ap, unsigned int); + if (flags & FLLONGLONG) + { + a.ull = va_arg(ap, unsigned long long); + } + else + { + a.ul = flags & FLLONG? + va_arg(ap, unsigned long): + va_arg(ap, unsigned int); + } #if PRINTF_LEVEL > PRINTF_MIN - flags &= ~(FLSIGNPLUS | FLSIGN); + flags &= ~(FLSIGNPLUS | FLSIGN); #endif processnum: pb = b; - do { - *pb = a.ul % base; - *pb = *pb > 9? - *pb + c - 'X' + 'A' - 10: - *pb + '0'; - *pb++; - a.ul /= base; - } while (a.ul); + if (flags & FLLONGLONG) + { + do { + *pb = a.ull % base; + *pb = *pb > 9? + *pb + c - 'X' + 'A' - 10: + *pb + '0'; + *pb++; + a.ull /= base; + } while (a.ull); + } + else + { + do { + *pb = a.ul % base; + *pb = *pb > 9? + *pb + c - 'X' + 'A' - 10: + *pb + '0'; + *pb++; + a.ul /= base; + } while (a.ul); + } #if PRINTF_LEVEL > PRINTF_MIN /* length of converted string */ a.i8 = pb - b;