From 401e060c052ea9a5940d5b9995178c7b04b5f85d Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 6 Oct 2005 20:30:52 +1000 Subject: [PATCH] Updates to string formating functions darcs-hash:20051006103052-ac50b-78e27365d2b2412ffced94825f37cbf6c0fa4d45.gz --- fish_tests.c | 1 - wutil.c | 130 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 90 insertions(+), 41 deletions(-) diff --git a/fish_tests.c b/fish_tests.c index 4a29ddefd..4b849d41a 100644 --- a/fish_tests.c +++ b/fish_tests.c @@ -69,7 +69,6 @@ static void ok() wprintf( L"OK\n" ); } - static int pq_compare( void *e1, void *e2 ) { return e1-e2; diff --git a/wutil.c b/wutil.c index 6a1a41220..cddae6af2 100644 --- a/wutil.c +++ b/wutil.c @@ -228,8 +228,8 @@ static int vgwprintf( void (*writer)(wchar_t), int width = 0; filter++; int loop=1; - int precision=INT_MAX; - + int precision=-1; + while( loop ) { switch(*filter) @@ -291,11 +291,26 @@ static int vgwprintf( void (*writer)(wchar_t), break; } case L's': - { - wchar_t *ss = is_long?va_arg(va, wchar_t*):str2wcs(va_arg(va, char*)); - + { + wchar_t *ss=0; + if( is_long ) + { + ss = va_arg(va, void *); + } + else + { + char *ns = va_arg(va, char*); + + if( ns ) + { + ss = str2wcs( ns ); + } + } + if( !ss ) + { return -1; + } if( width ) { @@ -306,13 +321,13 @@ static int vgwprintf( void (*writer)(wchar_t), count++; } } - + wchar_t *s=ss; int precount = count; while( *s ) { - if( (precision <= (count-precount) ) ) + if( (precision > 0) && (precision <= (count-precount) ) ) break; writer( *(s++) ); @@ -329,27 +344,38 @@ static int vgwprintf( void (*writer)(wchar_t), case L'i': { char str[32]; - + char *pos; + switch( is_long ) { case 0: { int d = va_arg( va, int ); - snprintf( str, 32, "%.*d", precision, d ); + if( precision > 0 ) + snprintf( str, 32, "%.*d", precision, d ); + else + snprintf( str, 32, "%d", d ); + break; } case 1: { long d = va_arg( va, long ); - snprintf( str, 32, "%.*ld", precision, d ); + if( precision > 0 ) + snprintf( str, 32, "%.*ld", precision, d ); + else + snprintf( str, 32, "%ld", d ); break; } case 2: { long long d = va_arg( va, long long ); - snprintf( str, 32, "%.*lld", precision, d ); + if( precision > 0 ) + snprintf( str, 32, "%.*lld", precision, d ); + else + snprintf( str, 32, "%lld", d ); break; } @@ -360,27 +386,29 @@ static int vgwprintf( void (*writer)(wchar_t), if( width ) { int i; + for( i=strlen(str); i