ntdll: Use proper flags instead of characters for printf flags.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-07-07 16:12:44 +02:00
parent 3a3c7cbd20
commit 1a43c5de71
1 changed files with 33 additions and 23 deletions

View File

@ -50,11 +50,10 @@ typedef struct pf_output_t
typedef struct pf_flags_t typedef struct pf_flags_t
{ {
char Sign, LeftAlign, Alternate, PadZero; enum { LEN_DEFAULT, LEN_SHORT, LEN_LONG } IntegerLength;
BOOLEAN IntegerDouble, IntegerNative, LeftAlign, Alternate, PadZero, WideString;
int FieldLength, Precision; int FieldLength, Precision;
char IntegerLength, IntegerDouble, IntegerNative; char Sign, Format;
char WideString;
char Format;
} pf_flags; } pf_flags;
/* /*
@ -268,9 +267,9 @@ static int pf_handle_string_format( pf_output *out, const void* str, int len,
return pf_output_format_A( out, "(null)", -1, flags); return pf_output_format_A( out, "(null)", -1, flags);
/* prefixes take priority over %c,%s vs. %C,%S, so we handle them first */ /* prefixes take priority over %c,%s vs. %C,%S, so we handle them first */
if(flags->WideString || flags->IntegerLength == 'l') if (flags->WideString || flags->IntegerLength == LEN_LONG)
return pf_output_format_W( out, str, len, flags); return pf_output_format_W( out, str, len, flags);
if(flags->IntegerLength == 'h') if (flags->IntegerLength == LEN_SHORT)
return pf_output_format_A( out, str, len, flags); return pf_output_format_A( out, str, len, flags);
/* %s,%c -> chars in ansi functions & wchars in unicode /* %s,%c -> chars in ansi functions & wchars in unicode
@ -310,7 +309,7 @@ static void pf_integer_conv( char *buf, pf_flags *flags, LONGLONG x )
i = 0; i = 0;
if( x == 0 ) if( x == 0 )
{ {
flags->Alternate = 0; flags->Alternate = FALSE;
if( flags->Precision ) if( flags->Precision )
buf[i++] = '0'; buf[i++] = '0';
} }
@ -410,11 +409,11 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
flags.Sign = *p; flags.Sign = *p;
} }
else if( *p == '-' ) else if( *p == '-' )
flags.LeftAlign = *p; flags.LeftAlign = TRUE;
else if( *p == '0' ) else if( *p == '0' )
flags.PadZero = *p; flags.PadZero = TRUE;
else if( *p == '#' ) else if( *p == '#' )
flags.Alternate = *p; flags.Alternate = TRUE;
else else
break; break;
p++; p++;
@ -427,7 +426,7 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
flags.FieldLength = va_arg( valist, int ); flags.FieldLength = va_arg( valist, int );
if (flags.FieldLength < 0) if (flags.FieldLength < 0)
{ {
flags.LeftAlign = '-'; flags.LeftAlign = TRUE;
flags.FieldLength = -flags.FieldLength; flags.FieldLength = -flags.FieldLength;
} }
p++; p++;
@ -461,19 +460,24 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
{ {
if (*p == 'l' && *(p+1) == 'l') if (*p == 'l' && *(p+1) == 'l')
{ {
flags.IntegerDouble++; flags.IntegerDouble = TRUE;
p += 2; p += 2;
} }
else if( *p == 'h' || *p == 'l' || *p == 'L' ) else if( *p == 'l' || *p == 'L' )
{ {
flags.IntegerLength = *p; flags.IntegerLength = LEN_LONG;
p++;
}
else if( *p == 'h')
{
flags.IntegerLength = LEN_SHORT;
p++; p++;
} }
else if( *p == 'I' ) else if( *p == 'I' )
{ {
if( *(p+1) == '6' && *(p+2) == '4' ) if( *(p+1) == '6' && *(p+2) == '4' )
{ {
flags.IntegerDouble++; flags.IntegerDouble = TRUE;
p += 3; p += 3;
} }
else if( *(p+1) == '3' && *(p+2) == '2' ) else if( *(p+1) == '3' && *(p+2) == '2' )
@ -481,7 +485,7 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
else if( p[1] && strchr( "diouxX", p[1] ) ) else if( p[1] && strchr( "diouxX", p[1] ) )
{ {
if( sizeof(void *) == 8 ) if( sizeof(void *) == 8 )
flags.IntegerDouble = *p; flags.IntegerDouble = TRUE;
p++; p++;
} }
else if( isDigit(*(p+1)) || *(p+1) == 0 ) else if( isDigit(*(p+1)) || *(p+1) == 0 )
@ -490,12 +494,18 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
p++; p++;
} }
else if( *p == 'w' ) else if( *p == 'w' )
flags.WideString = *p++; {
flags.WideString = TRUE;
p++;
}
else if ((*p == 'z' || *p == 't') && p[1] && strchr("diouxX", p[1])) else if ((*p == 'z' || *p == 't') && p[1] && strchr("diouxX", p[1]))
flags.IntegerNative = *p++; {
flags.IntegerNative = TRUE;
p++;
}
else if (*p == 'j') else if (*p == 'j')
{ {
flags.IntegerDouble++; flags.IntegerDouble = TRUE;
p++; p++;
} }
else if( *p == 'F' ) else if( *p == 'F' )
@ -532,10 +542,10 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
void *ptr = va_arg( valist, void * ); void *ptr = va_arg( valist, void * );
int prec = flags.Precision; int prec = flags.Precision;
flags.Format = 'X'; flags.Format = 'X';
flags.PadZero = '0'; flags.PadZero = TRUE;
flags.Precision = 2*sizeof(void*); flags.Precision = 2*sizeof(void*);
pf_integer_conv( pointer, &flags, (ULONG_PTR)ptr ); pf_integer_conv( pointer, &flags, (ULONG_PTR)ptr );
flags.PadZero = 0; flags.PadZero = FALSE;
flags.Precision = prec; flags.Precision = prec;
r = pf_output_format_A( out, pointer, -1, &flags ); r = pf_output_format_A( out, pointer, -1, &flags );
} }
@ -563,10 +573,10 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
if(flags.IntegerDouble || (flags.IntegerNative && sizeof(void*) == 8)) if(flags.IntegerDouble || (flags.IntegerNative && sizeof(void*) == 8))
pf_integer_conv( x, &flags, va_arg(valist, LONGLONG) ); pf_integer_conv( x, &flags, va_arg(valist, LONGLONG) );
else if(flags.Format=='d' || flags.Format=='i') else if(flags.Format=='d' || flags.Format=='i')
pf_integer_conv( x, &flags, flags.IntegerLength!='h' ? pf_integer_conv( x, &flags, flags.IntegerLength != LEN_SHORT ?
va_arg(valist, int) : (short)va_arg(valist, int) ); va_arg(valist, int) : (short)va_arg(valist, int) );
else else
pf_integer_conv( x, &flags, flags.IntegerLength!='h' ? pf_integer_conv( x, &flags, flags.IntegerLength != LEN_SHORT ?
(unsigned int)va_arg(valist, int) : (unsigned short)va_arg(valist, int) ); (unsigned int)va_arg(valist, int) : (unsigned short)va_arg(valist, int) );
r = pf_output_format_A( out, x, -1, &flags ); r = pf_output_format_A( out, x, -1, &flags );