--- quake3/game/bg_lib.c Tue Feb 13 03:05:00 2001 +++ fi/game/bg_lib.c Sun Aug 26 02:53:51 2001 @@ -1022,16 +1022,24 @@ #define SHORTINT 0x00000040 /* short integer */ #define ZEROPAD 0x00000080 /* zero (as opposed to blank) pad */ #define FPT 0x00000100 /* floating point number */ +#define UNSIGNED 0x00000200 /* unsigned integer. */ #define to_digit(c) ((c) - '0') #define is_digit(c) ((unsigned)to_digit(c) <= 9) #define to_char(n) ((n) + '0') -void AddInt( char **buf_p, int val, int width, int flags ) { +void AddInt( char **buf_p, int val, int width, int flags, char *charset ) { char text[32]; int digits; int signedVal; char *buf; + int base; + + if (charset == NULL) + charset = "0123456789"; /* Decimal by default. */ + + for (base = 0; charset[base]; base++); /* Note NOP operation. */ + /* Offset of NULL is the number base. So "0123456789" -> base-10. */ digits = 0; signedVal = val; @@ -1039,11 +1047,11 @@ val = -val; } do { - text[digits++] = '0' + val % 10; - val /= 10; + text[digits++] = charset[val % base]; //'0' + val % 10; + val /= base; //10; } while ( val ); - if ( signedVal < 0 ) { + if (( signedVal < 0 ) && !(flags & UNSIGNED)) { text[digits++] = '-'; } @@ -1165,6 +1173,7 @@ *buf_p = buf; } + /* vsprintf @@ -1243,7 +1252,7 @@ break; case 'd': case 'i': - AddInt( &buf_p, *arg, width, flags ); + AddInt( &buf_p, *arg, width, flags, "0123456789" ); arg++; break; case 'f': @@ -1261,6 +1270,24 @@ case '%': *buf_p++ = ch; break; + + case 'u': /* Unsigned decimal. */ + AddInt (&buf_p, *arg, width, flags | UNSIGNED, "0123456789"); + arg++; + break; + case 'o': /* (Unsigned) Octal. */ + AddInt (&buf_p, *arg, width, flags | UNSIGNED, "01234567"); + arg++; + break; + case 'x': /* (unsigned) hexadecimal (lower-case letters). */ + AddInt (&buf_p, *arg, width, flags | UNSIGNED, "0123456789abcdef"); + arg++; + break; + case 'X': /* (unsigned) Hexadecimal (upper-case letters). */ + AddInt (&buf_p, *arg, width, flags | UNSIGNED, "0123456789ABCDEF"); + arg++; + break; + default: *buf_p++ = (char)*arg; arg++;