From: John Hodge Date: Tue, 1 Mar 2011 06:40:01 +0000 (+0800) Subject: Fixed vsnprintf X-Git-Tag: rel0.10~178 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=22621d0f86a4b3ca5038e470f105d941fbbd7c62;p=tpg%2Facess2.git Fixed vsnprintf - '-' is padding, not '+' - Added precision --- diff --git a/Kernel/lib.c b/Kernel/lib.c index 3e57d00d..5f277b8b 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -199,7 +199,7 @@ void itoa(char *buf, Uint64 num, int base, int minLength, char pad) int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) { char c, pad = ' '; - int minSize = 0, len; + int minSize = 0, precision = -1, len; char tmpBuf[34]; // For Integers const char *p = NULL; int isLongLong = 0; @@ -231,7 +231,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) } // - Padding Side Flag - if(c == '+') { + if(c == '-') { bPadLeft = 1; c = *__format++; } @@ -262,6 +262,27 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) else minSize = 1; + // - Precision + precision = -1; + if( c == '.' ) { + c = *__format++; + + if(c == '*') { // Dynamic length + precision = va_arg(args, unsigned int); + c = *__format++; + } + else if('1' <= c && c <= '9') + { + precision = 0; + while('0' <= c && c <= '9') + { + precision *= 10; + precision += c - '0'; + c = *__format++; + } + } + } + // - Default, Long or LongLong? isLongLong = 0; if(c == 'l') // Long is actually the default on x86 @@ -323,12 +344,12 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) // String - Null Terminated Array case 's': p = va_arg(args, char*); // Get Argument - if( !CheckString(p) ) continue; // Avoid #PFs + if( !CheckString(p) ) p = "(inval)"; // Avoid #PFs printString: if(!p) p = "(null)"; len = strlen(p); if( !bPadLeft ) while(len++ < minSize) PUTCH(pad); - while(*p) PUTCH(*p++); + while(*p && precision--) PUTCH(*p++); if( bPadLeft ) while(len++ < minSize) PUTCH(pad); break; diff --git a/Kernel/logging.c b/Kernel/logging.c index 8132e5c0..c00746ae 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -113,7 +113,7 @@ void Log_AddEvent(const char *Ident, int Level, const char *Format, va_list Args char newData[ LOG_HDR_LEN + len + 2 + 1 ]; char _ident[9]; strncpy(_ident, Ident, 9); - sprintf( newData, "%014lli%s [%+8s] ", + sprintf( newData, "%014lli%s [%-8s] ", ent->Time, csaLevelCodes[Level], Ident); strcpy( newData + LOG_HDR_LEN, ent->Data ); strcpy( newData + LOG_HDR_LEN + len, "\r\n" ); @@ -153,7 +153,7 @@ void Log_AddEvent(const char *Ident, int Level, const char *Format, va_list Args void Log_Int_PrintMessage(tLogEntry *Entry) { SHORTLOCK( &glLogOutput ); - LogF("%s%014lli%s [%+8s] %s", + LogF("%s%014lli%s [%-8s] %s", csaLevelColours[Entry->Level], Entry->Time, csaLevelCodes[Entry->Level],