diff options
author | Bruno Haible <bruno@clisp.org> | 2006-02-13 13:09:17 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:12:59 +0200 |
commit | 1d4646967449a79cb73b20607fd47015fd845a47 (patch) | |
tree | 41cf6320f61d301f395e906d6e7cf98921d2e9ee /gettext-tools/src | |
parent | 8fad43c97c71588fa4e6dc099deddf4252a207e2 (diff) | |
download | external_gettext-1d4646967449a79cb73b20607fd47015fd845a47.zip external_gettext-1d4646967449a79cb73b20607fd47015fd845a47.tar.gz external_gettext-1d4646967449a79cb73b20607fd47015fd845a47.tar.bz2 |
Improve the c-format guessing heuristic.
Diffstat (limited to 'gettext-tools/src')
-rw-r--r-- | gettext-tools/src/ChangeLog | 32 | ||||
-rw-r--r-- | gettext-tools/src/format-awk.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-c.c | 21 | ||||
-rw-r--r-- | gettext-tools/src/format-csharp.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-elisp.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-gcc-internal.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-java.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-librep.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-lisp.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-pascal.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-perl-brace.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-perl.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-php.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-python.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-qt.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-scheme.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-sh.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-tcl.c | 3 | ||||
-rw-r--r-- | gettext-tools/src/format-ycp.c | 4 | ||||
-rw-r--r-- | gettext-tools/src/format.h | 7 | ||||
-rw-r--r-- | gettext-tools/src/xgettext.c | 8 |
21 files changed, 99 insertions, 21 deletions
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 56de0e8..588f186 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,5 +1,37 @@ 2006-02-12 Bruno Haible <bruno@clisp.org> + Reduce the number of false positives produced by the c-format guessing + heuristics. + * format.h (struct formatstring_parser): Add 'is_unlikely_intentional' + field. + * format-awk.c (formatstring_awk): Update. + * format-c.c (struct spec): Add 'unlikely_unintentional' field. + (format_parse): Set unlikely_unintentional to true when encountering + a "%...%" directive other than "%%". + (format_is_unlikely_intentional): New function. + (formatstring_c, formatstring_objc): Use it. + * format-csharp.c (formatstring_csharp): Update. + * format-elisp.c (formatstring_elisp): Update. + * format-gcc-internal.c (formatstring_gcc_internal): Update. + * format-java.c (formatstring_java): Update. + * format-librep.c (formatstring_librep): Update. + * format-lisp.c (formatstring_lisp): Update. + * format-pascal.c (formatstring_pascal): Update. + * format-perl.c (formatstring_perl): Update. + * format-perl-brace.c (formatstring_perl_brace): Update. + * format-php.c (format_php): Update. + * format-python.c (formatstring_python): Update. + * format-qt.c (formatstring_qt): Update. + * format-scheme.c (formatstring_scheme): Update + * format-sh.c (formatstring_sh): Update. + * format-tcl.c (formatstring_tcl): Update. + * format-ycp.c (formatstring_ycp, formatstring_smalltalk): Update. + * xgettext.c (remember_a_message, remember_a_message_plural): Don't + mark the message as c-format if the validity as c-format looks + unintentional. + +2006-02-12 Bruno Haible <bruno@clisp.org> + * msgattrib.c (main): Update year in --version output. * msgcat.c (main): Likewise. * msgcmp.c (main): Likewise. diff --git a/gettext-tools/src/format-awk.c b/gettext-tools/src/format-awk.c index b290f40..d540da6 100644 --- a/gettext-tools/src/format-awk.c +++ b/gettext-tools/src/format-awk.c @@ -1,5 +1,5 @@ /* awk format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2002. This program is free software; you can redistribute it and/or modify @@ -537,6 +537,7 @@ struct formatstring_parser formatstring_awk = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-c.c b/gettext-tools/src/format-c.c index be12d24..e31bebf 100644 --- a/gettext-tools/src/format-c.c +++ b/gettext-tools/src/format-c.c @@ -1,5 +1,5 @@ /* C format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -152,6 +152,7 @@ struct spec unsigned int unnumbered_arg_count; unsigned int allocated; struct unnumbered_arg *unnumbered; + bool unlikely_intentional; unsigned int sysdep_directives_count; const char **sysdep_directives; }; @@ -190,6 +191,7 @@ format_parse (const char *format, bool translated, bool objc_extensions, spec.allocated = 0; numbered = NULL; spec.unnumbered = NULL; + spec.unlikely_intentional = false; spec.sysdep_directives_count = 0; spec.sysdep_directives = NULL; @@ -608,6 +610,13 @@ format_parse (const char *format, bool translated, bool objc_extensions, switch (*format) { case '%': + /* Programmers writing _("%2%") most often will not want to + use this string as a c-format string, but rather as a + literal or as a different kind of format string. */ + if (format[-1] != '%') + spec.unlikely_intentional = true; + type = FAT_NONE; + break; case 'm': /* glibc extension */ type = FAT_NONE; break; @@ -820,6 +829,14 @@ format_free (void *descr) free (spec); } +static bool +format_is_unlikely_intentional (void *descr) +{ + struct spec *spec = (struct spec *) descr; + + return spec->unlikely_intentional; +} + static int format_get_number_of_directives (void *descr) { @@ -867,6 +884,7 @@ struct formatstring_parser formatstring_c = format_c_parse, format_free, format_get_number_of_directives, + format_is_unlikely_intentional, format_check }; @@ -876,6 +894,7 @@ struct formatstring_parser formatstring_objc = format_objc_parse, format_free, format_get_number_of_directives, + format_is_unlikely_intentional, format_check }; diff --git a/gettext-tools/src/format-csharp.c b/gettext-tools/src/format-csharp.c index 8e71fb1..966ede2 100644 --- a/gettext-tools/src/format-csharp.c +++ b/gettext-tools/src/format-csharp.c @@ -1,5 +1,5 @@ /* C# format strings. - Copyright (C) 2003-2004 Free Software Foundation, Inc. + Copyright (C) 2003-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software; you can redistribute it and/or modify @@ -206,6 +206,7 @@ struct formatstring_parser formatstring_csharp = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-elisp.c b/gettext-tools/src/format-elisp.c index 4f5005c..17c2e62 100644 --- a/gettext-tools/src/format-elisp.c +++ b/gettext-tools/src/format-elisp.c @@ -1,5 +1,5 @@ /* Emacs Lisp format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2002. This program is free software; you can redistribute it and/or modify @@ -385,6 +385,7 @@ struct formatstring_parser formatstring_elisp = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-gcc-internal.c b/gettext-tools/src/format-gcc-internal.c index 7d3be08..43713ae 100644 --- a/gettext-tools/src/format-gcc-internal.c +++ b/gettext-tools/src/format-gcc-internal.c @@ -1,5 +1,5 @@ /* GCC internal format strings. - Copyright (C) 2003-2005 Free Software Foundation, Inc. + Copyright (C) 2003-2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software; you can redistribute it and/or modify @@ -357,6 +357,7 @@ struct formatstring_parser formatstring_gcc_internal = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-java.c b/gettext-tools/src/format-java.c index 4574574..b7f6de1 100644 --- a/gettext-tools/src/format-java.c +++ b/gettext-tools/src/format-java.c @@ -1,5 +1,5 @@ /* Java format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -777,6 +777,7 @@ struct formatstring_parser formatstring_java = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-librep.c b/gettext-tools/src/format-librep.c index bc51379..e64b92c 100644 --- a/gettext-tools/src/format-librep.c +++ b/gettext-tools/src/format-librep.c @@ -1,5 +1,5 @@ /* librep format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -349,6 +349,7 @@ struct formatstring_parser formatstring_librep = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-lisp.c b/gettext-tools/src/format-lisp.c index 25c39c8..4b746b2 100644 --- a/gettext-tools/src/format-lisp.c +++ b/gettext-tools/src/format-lisp.c @@ -1,5 +1,5 @@ /* Lisp format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -3370,6 +3370,7 @@ struct formatstring_parser formatstring_lisp = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-pascal.c b/gettext-tools/src/format-pascal.c index cb4b88f..c863e30 100644 --- a/gettext-tools/src/format-pascal.c +++ b/gettext-tools/src/format-pascal.c @@ -1,5 +1,5 @@ /* Object Pascal format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -438,6 +438,7 @@ struct formatstring_parser formatstring_pascal = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-perl-brace.c b/gettext-tools/src/format-perl-brace.c index 9743754..1d3877b 100644 --- a/gettext-tools/src/format-perl-brace.c +++ b/gettext-tools/src/format-perl-brace.c @@ -1,5 +1,5 @@ /* Perl brace format strings. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software; you can redistribute it and/or modify @@ -213,6 +213,7 @@ struct formatstring_parser formatstring_perl_brace = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-perl.c b/gettext-tools/src/format-perl.c index b1d15d3..20d6632 100644 --- a/gettext-tools/src/format-perl.c +++ b/gettext-tools/src/format-perl.c @@ -1,5 +1,5 @@ /* Perl format strings. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software; you can redistribute it and/or modify @@ -615,6 +615,7 @@ struct formatstring_parser formatstring_perl = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-php.c b/gettext-tools/src/format-php.c index c32f3f5..434808e 100644 --- a/gettext-tools/src/format-php.c +++ b/gettext-tools/src/format-php.c @@ -1,5 +1,5 @@ /* PHP format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2002. This program is free software; you can redistribute it and/or modify @@ -385,6 +385,7 @@ struct formatstring_parser formatstring_php = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-python.c b/gettext-tools/src/format-python.c index 610cbf0..b86de59 100644 --- a/gettext-tools/src/format-python.c +++ b/gettext-tools/src/format-python.c @@ -1,5 +1,5 @@ /* Python format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -507,6 +507,7 @@ struct formatstring_parser formatstring_python = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-qt.c b/gettext-tools/src/format-qt.c index 7f395be..f4da230 100644 --- a/gettext-tools/src/format-qt.c +++ b/gettext-tools/src/format-qt.c @@ -1,5 +1,5 @@ /* Qt format strings. - Copyright (C) 2003-2004 Free Software Foundation, Inc. + Copyright (C) 2003-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software; you can redistribute it and/or modify @@ -145,6 +145,7 @@ struct formatstring_parser formatstring_qt = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-scheme.c b/gettext-tools/src/format-scheme.c index b71d65b..7497a92 100644 --- a/gettext-tools/src/format-scheme.c +++ b/gettext-tools/src/format-scheme.c @@ -1,5 +1,5 @@ /* Scheme format strings. - Copyright (C) 2001-2005 Free Software Foundation, Inc. + Copyright (C) 2001-2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -3308,6 +3308,7 @@ struct formatstring_parser formatstring_scheme = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-sh.c b/gettext-tools/src/format-sh.c index d09f0be..176177f 100644 --- a/gettext-tools/src/format-sh.c +++ b/gettext-tools/src/format-sh.c @@ -1,5 +1,5 @@ /* Shell format strings. - Copyright (C) 2003-2004 Free Software Foundation, Inc. + Copyright (C) 2003-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software; you can redistribute it and/or modify @@ -314,6 +314,7 @@ struct formatstring_parser formatstring_sh = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-tcl.c b/gettext-tools/src/format-tcl.c index 14e234c..8002832 100644 --- a/gettext-tools/src/format-tcl.c +++ b/gettext-tools/src/format-tcl.c @@ -1,5 +1,5 @@ /* Tcl format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2002. This program is free software; you can redistribute it and/or modify @@ -424,6 +424,7 @@ struct formatstring_parser formatstring_tcl = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format-ycp.c b/gettext-tools/src/format-ycp.c index 62f4fab..cf9797d 100644 --- a/gettext-tools/src/format-ycp.c +++ b/gettext-tools/src/format-ycp.c @@ -1,5 +1,5 @@ /* YCP and Smalltalk format strings. - Copyright (C) 2001-2004 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -146,6 +146,7 @@ struct formatstring_parser formatstring_ycp = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; @@ -155,6 +156,7 @@ struct formatstring_parser formatstring_smalltalk = format_parse, format_free, format_get_number_of_directives, + NULL, format_check }; diff --git a/gettext-tools/src/format.h b/gettext-tools/src/format.h index a62a5e0..27bb4af 100644 --- a/gettext-tools/src/format.h +++ b/gettext-tools/src/format.h @@ -1,5 +1,5 @@ /* Format strings. - Copyright (C) 2001-2005 Free Software Foundation, Inc. + Copyright (C) 2001-2006 Free Software Foundation, Inc. Written by Bruno Haible <haible@clisp.cons.org>, 2001. This program is free software; you can redistribute it and/or modify @@ -58,6 +58,11 @@ struct formatstring_parser A string that can be output literally has 0 format directives. */ int (*get_number_of_directives) (void *descr); + /* Return true if the format string, although valid, contains directives that + make it appear unlikely that the string was meant as a format string. + A NULL function is equivalent to a function that always returns false. */ + bool (*is_unlikely_intentional) (void *descr); + /* Verify that the argument types/names in msgid_descr and those in msgstr_descr are the same (if equality=true), or (if equality=false) that those of msgid_descr extend those of msgstr_descr (i.e. diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index c0fa97c..9da8476 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -2079,7 +2079,9 @@ meta information, not the empty string.\n"))); "xgettext: no-c-format" anywhere where a translator wishes to use a percent sign. So, the msgfmt checking will not be perfect. Oh well. */ - if (parser->get_number_of_directives (descr) > 0) + if (parser->get_number_of_directives (descr) > 0 + && !(parser->is_unlikely_intentional != NULL + && parser->is_unlikely_intentional (descr))) is_format[i] = possible; parser->free (descr); @@ -2181,7 +2183,9 @@ remember_a_message_plural (message_ty *mp, char *string, if (descr != NULL) { /* Same heuristic as in remember_a_message. */ - if (parser->get_number_of_directives (descr) > 0) + if (parser->get_number_of_directives (descr) > 0 + && !(parser->is_unlikely_intentional != NULL + && parser->is_unlikely_intentional (descr))) mp->is_format[i] = possible; parser->free (descr); |