+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.
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
unsigned int unnumbered_arg_count;
unsigned int allocated;
struct unnumbered_arg *unnumbered;
+ bool unlikely_intentional;
unsigned int sysdep_directives_count;
const char **sysdep_directives;
};
spec.allocated = 0;
numbered = NULL;
spec.unnumbered = NULL;
+ spec.unlikely_intentional = false;
spec.sysdep_directives_count = 0;
spec.sysdep_directives = NULL;
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;
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)
{
format_c_parse,
format_free,
format_get_number_of_directives,
+ format_is_unlikely_intentional,
format_check
};
format_objc_parse,
format_free,
format_get_number_of_directives,
+ format_is_unlikely_intentional,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
format_parse,
format_free,
format_get_number_of_directives,
+ NULL,
format_check
};
/* 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
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.
"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);
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);
+2006-02-12 Bruno Haible <bruno@clisp.org>
+
+ * xgettext-c-12: New file.
+ * Makefile.am (TESTS): Add it.
+
2005-11-21 Bruno Haible <bruno@clisp.org>
* format-c-3: Put all non-option arguments after all option arguments,
## Makefile for the gettext-tools/tests subdirectory of GNU gettext
-## Copyright (C) 1995-1997, 2001-2005 Free Software Foundation, Inc.
+## Copyright (C) 1995-1997, 2001-2006 Free Software Foundation, Inc.
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
xgettext-awk-1 \
xgettext-c-1 xgettext-c-2 xgettext-c-3 xgettext-c-4 xgettext-c-5 \
xgettext-c-6 xgettext-c-7 xgettext-c-8 xgettext-c-9 xgettext-c-10 \
- xgettext-c-11 \
+ xgettext-c-11 xgettext-c-12 \
xgettext-csharp-1 xgettext-csharp-2 xgettext-csharp-3 \
xgettext-csharp-4 xgettext-csharp-5 \
xgettext-elisp-1 \