From b90e670d6fcf6b8a6e3dfef3776194be00f09f14 Mon Sep 17 00:00:00 2001 From: axel Date: Wed, 12 Oct 2005 17:06:08 +1000 Subject: [PATCH] Various fixes for *wprintf replacements used in NetBSD darcs-hash:20051012070608-ac50b-ae810ec5f6a2010ee1e16bda63fdd3471c5ab1db.gz --- wutil.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/wutil.c b/wutil.c index cddae6af2..3d4ccc0f0 100644 --- a/wutil.c +++ b/wutil.c @@ -225,7 +225,7 @@ static int vgwprintf( void (*writer)(wchar_t), { int i; int is_long=0; - int width = 0; + int width = -1; filter++; int loop=1; int precision=-1; @@ -256,9 +256,10 @@ static int vgwprintf( void (*writer)(wchar_t), } else { + precision=0; while( (*filter >= L'0') && (*filter <= L'9')) { - precision=10*precision+(*filter - L'0'); + precision=10*precision+(*filter++ - L'0'); } } break; @@ -275,7 +276,7 @@ static int vgwprintf( void (*writer)(wchar_t), wchar_t c; c = is_long?va_arg(va, wchar_t):btowc(va_arg(va, int)); - if( width ) + if( width>= 0 ) { int i; for( i=1; i=0 ) { int i; for( i=wcslen(ss); i 0 ) + if( precision >= 0 ) snprintf( str, 32, "%.*d", precision, d ); else snprintf( str, 32, "%d", d ); @@ -362,7 +363,7 @@ static int vgwprintf( void (*writer)(wchar_t), case 1: { long d = va_arg( va, long ); - if( precision > 0 ) + if( precision >= 0 ) snprintf( str, 32, "%.*ld", precision, d ); else snprintf( str, 32, "%ld", d ); @@ -372,7 +373,7 @@ static int vgwprintf( void (*writer)(wchar_t), case 2: { long long d = va_arg( va, long long ); - if( precision > 0 ) + if( precision >= 0 ) snprintf( str, 32, "%.*lld", precision, d ); else snprintf( str, 32, "%lld", d ); @@ -383,7 +384,7 @@ static int vgwprintf( void (*writer)(wchar_t), return -1; } - if( width ) + if( width >= 0 ) { int i; @@ -408,6 +409,7 @@ static int vgwprintf( void (*writer)(wchar_t), case L'u': { char str[32]; + char *pos; switch( is_long ) { @@ -436,7 +438,7 @@ static int vgwprintf( void (*writer)(wchar_t), return -1; } - if( width ) + if( width>=0 ) { int i; for( i=strlen(str); i= 0 ) + { + if( width>= 0 ) + { + snprintf( str, 32, "%*.*f", width, precision, val ); + } + else + { + snprintf( str, 32, "%.*f", precision, val ); + } + } else - count += c; + { + if( width>= 0 ) + { + snprintf( str, 32, "%*f", width, val ); + } + else + { + snprintf( str, 32, "%f", val ); + } + } + + pos = str; + + while( *pos ) + { + writer( *(pos++) ); + count++; + } break; }