From: Bruno Haible Date: Fri, 15 Aug 2008 10:25:48 +0000 (+0000) Subject: Treat %.0s and %.0r as type-agnostic argument consumer. X-Git-Tag: v0.18~381 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f57a99eeea0a49b3949ce5124cf85df0a2395f31;p=thirdparty%2Fgettext.git Treat %.0s and %.0r as type-agnostic argument consumer. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 448033f36..346e2910d 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,12 @@ +2008-08-15 Bruno Haible + + * format-python.c (format_parse): For %.0s and %.0r, set the type to + FORMAT_ANY. + (format_check): When strict equality is not desired, compare FORMAT_ANY + as matching any type. + Reported by Alexander Dupuy in + . + 2008-08-14 Bruno Haible * format-python.c (format_parse): For '%', set the type to FAT_NONE. diff --git a/gettext-tools/src/format-python.c b/gettext-tools/src/format-python.c index 395b56263..889f73265 100644 --- a/gettext-tools/src/format-python.c +++ b/gettext-tools/src/format-python.c @@ -55,7 +55,8 @@ - is finished by a specifier - '%', that needs no argument, - 'c', that needs a character argument, - - 's', 'r', that need a string argument, + - 's', 'r', that need a string argument (or, when a precision of 0 is + given, an argument of any type), - 'i', 'd', 'u', 'o', 'x', 'X', that need an integer argument, - 'e', 'E', 'f', 'g', 'G', that need a floating-point argument. Use of '(ident)' and use of unnamed argument specifications are exclusive, @@ -133,6 +134,7 @@ format_parse (const char *format, bool translated, char *fdi, { /* A directive. */ char *name = NULL; + bool zero_precision = false; enum format_arg_type type; FDI_SET (format - 1, FMTDIR_START); @@ -228,7 +230,14 @@ format_parse (const char *format, bool translated, char *fdi, } else if (isdigit (*format)) { - do format++; while (isdigit (*format)); + zero_precision = true; + do + { + if (*format != '0') + zero_precision = false; + format++; + } + while (isdigit (*format)); } } @@ -244,7 +253,7 @@ format_parse (const char *format, bool translated, char *fdi, type = FAT_CHARACTER; break; case 's': case 'r': - type = FAT_STRING; + type = (zero_precision ? FAT_ANY : FAT_STRING); break; case 'i': case 'd': case 'u': case 'o': case 'x': case 'X': type = FAT_INTEGER; @@ -475,7 +484,10 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, { if (strcmp (spec1->named[i].name, spec2->named[j].name) == 0) { - if (spec1->named[i].type != spec2->named[j].type) + if (!(spec1->named[i].type == spec2->named[j].type + || (!equality + && (spec1->named[i].type == FAT_ANY + || spec2->named[j].type == FAT_ANY)))) { if (error_logger) error_logger (_("format specifications in 'msgid' and '%s' for argument '%s' are not the same"), @@ -504,7 +516,10 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality, } else for (i = 0; i < spec2->unnamed_arg_count; i++) - if (spec1->unnamed[i].type != spec2->unnamed[i].type) + if (!(spec1->unnamed[i].type == spec2->unnamed[i].type + || (!equality + && (spec1->unnamed[i].type == FAT_ANY + || spec2->unnamed[i].type == FAT_ANY)))) { if (error_logger) error_logger (_("format specifications in 'msgid' and '%s' for argument %u are not the same"),