From 0c1b481d8045fe04746e7d56df6fcf33bacc59bc Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 25 Feb 2002 12:05:41 +0000 Subject: [PATCH] Make it possible to grep through translator comments. --- doc/ChangeLog | 4 + doc/msggrep.texi | 7 +- src/ChangeLog | 11 +++ src/msggrep.c | 56 +++++++++-- tests/ChangeLog | 5 + tests/Makefile.am | 4 +- tests/msggrep-5 | 234 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 310 insertions(+), 11 deletions(-) create mode 100755 tests/msggrep-5 diff --git a/doc/ChangeLog b/doc/ChangeLog index c1478a965..e37e2a144 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2002-02-21 Bruno Haible + + * msggrep.texi: Document option -C. + 2002-02-14 Bruno Haible * gettext.texi (configure.in): Mention the alternative for automake diff --git a/doc/msggrep.texi b/doc/msggrep.texi index d7f2f8706..85a71d3cd 100644 --- a/doc/msggrep.texi +++ b/doc/msggrep.texi @@ -43,7 +43,8 @@ or if it is @samp{-}. @subsection Message selection @example - [-N @var{sourcefile}]... [-M @var{domainname}]... [-K @var{msgid-pattern}] [-T @var{msgstr-pattern}] + [-N @var{sourcefile}]... [-M @var{domainname}]... + [-K @var{msgid-pattern}] [-T @var{msgstr-pattern}] [-C @var{comment-pattern}] @end example A message is selected if @@ -53,7 +54,9 @@ A message is selected if @item or if @samp{-K} is given and its key (msgid or msgid_plural) matches @var{msgid-pattern}, @item or if @samp{-T} is given and its translation (msgstr) matches - @var{msgstr-pattern}. + @var{msgstr-pattern}, +@item or if @samp{-C} is given and the translator's comment matches + @var{comment-pattern}. @end itemize When more than one selection criterion is specified, the set of selected diff --git a/src/ChangeLog b/src/ChangeLog index 6cda5b4df..493fcf978 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2002-02-21 Bruno Haible + + * msggrep.c: Include liballoca.h. + (grep_args): Add a third one. + (grep_argv): Likewise. + (long_options): Add --comment option. + (main): Handle option --comment/-C. + (usage): Document option -C. + (is_message_selected): If option -C is given, concatenate the + translator comments and run a third grep pass on the result. + 2002-02-09 Bruno Haible * message.h (possible_format_p): Change return type to bool. diff --git a/src/msggrep.c b/src/msggrep.c index ad338b8ee..014f58388 100644 --- a/src/msggrep.c +++ b/src/msggrep.c @@ -20,6 +20,7 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include "liballoca.h" #include #include @@ -54,6 +55,7 @@ #define _(str) gettext (str) + /* Force output of PO file even if empty. */ static int force_po; @@ -64,18 +66,19 @@ static string_list_ty *location_files; static string_list_ty *domain_names; /* Arguments to be passed to the grep subprocesses. */ -static string_list_ty *grep_args[2]; +static string_list_ty *grep_args[3]; /* Pathname of the grep program. */ static const char *grep_path; /* Argument lists for the grep program. */ -static char **grep_argv[2]; +static char **grep_argv[3]; /* Long options. */ static const struct option long_options[] = { { "add-location", no_argument, &line_comment, 1 }, + { "comment", no_argument, NULL, 'C' }, { "directory", required_argument, NULL, 'D' }, { "domain", required_argument, NULL, 'M' }, { "escape", no_argument, NULL, CHAR_MAX + 1 }, @@ -158,8 +161,9 @@ main (argc, argv) domain_names = string_list_alloc (); grep_args[0] = string_list_alloc (); grep_args[1] = string_list_alloc (); + grep_args[2] = string_list_alloc (); - while ((opt = getopt_long (argc, argv, "D:e:Ef:FhiKM:N:o:TVw:", + while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiKM:N:o:TVw:", long_options, NULL)) != EOF) switch (opt) @@ -167,6 +171,10 @@ main (argc, argv) case '\0': /* Long option. */ break; + case 'C': + grep_pass = 2; + break; + case 'D': dir_list_append (optarg); break; @@ -311,7 +319,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ /* Read input file. */ result = read_po_file (input_file); - if (grep_args[0]->nitems > 0 || grep_args[1]->nitems > 0) + if (grep_args[0]->nitems > 0 + || grep_args[1]->nitems > 0 + || grep_args[2]->nitems > 0) { /* Warn if the current locale is not suitable for this PO file. */ compare_po_locale_charsets (result); @@ -323,7 +333,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ } /* Build argument lists for the 'grep' program. */ - for (grep_pass = 0; grep_pass < 2; grep_pass++) + for (grep_pass = 0; grep_pass < 3; grep_pass++) if (grep_args[grep_pass]->nitems > 0) { string_list_ty *args = grep_args[grep_pass]; @@ -423,11 +433,13 @@ or if it is -.\n\ /* xgettext: no-wrap */ printf (_("\ Message selection:\n\ - [-N SOURCEFILE]... [-M DOMAINNAME]... [-K MSGID-PATTERN] [-T MSGSTR-PATTERN]\n\ + [-N SOURCEFILE]... [-M DOMAINNAME]...\n\ + [-K MSGID-PATTERN] [-T MSGSTR-PATTERN] [-C COMMENT-PATTERN]\n\ A message is selected if it comes from one of the specified source files,\n\ or if it comes from one of the specified domains,\n\ or if -K is given and its key (msgid or msgid_plural) matches MSGID-PATTERN,\n\ -or if -T is given and its translation (msgstr) matches MSGSTR-PATTERN.\n\ +or if -T is given and its translation (msgstr) matches MSGSTR-PATTERN,\n\ +or if -C is given and the translator's comment matches COMMENT-PATTERN.\n\ \n\ When more than one selection criterion is specified, the set of selected\n\ messages is the union of the selected messages of each criterion.\n\ @@ -592,6 +604,36 @@ is_message_selected (mp) p += length + 1; } + /* Test translator comments using the --comment arguments. */ + if (grep_args[2]->nitems > 0 + && mp->comment != NULL && mp->comment->nitems > 0) + { + size_t length; + char *total_comment; + char *q; + size_t j; + + length = 0; + for (j = 0; j < mp->comment->nitems; j++) + length += strlen (mp->comment->item[j]) + 1; + total_comment = (char *) alloca (length); + + q = total_comment; + for (j = 0; j < mp->comment->nitems; j++) + { + size_t l = strlen (mp->comment->item[j]); + + memcpy (q, mp->comment->item[j], l); + q += l; + *q++ = '\n'; + } + if (q != total_comment + length) + abort (); + + if (is_string_selected (2, total_comment, length)) + return true; + } + return false; } diff --git a/tests/ChangeLog b/tests/ChangeLog index 90422d5a1..9299bff46 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2002-02-21 Bruno Haible + + * msggrep-5: New file. + * Makefile.am (TESTS): Add it. + 2002-01-28 Bruno Haible * xgettext-19: New file. diff --git a/tests/Makefile.am b/tests/Makefile.am index 64a40284d..a35b953e4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,7 +35,7 @@ TESTS = gettext-1 gettext-2 \ msgfilter-1 msgfilter-2 \ msgfmt-1 msgfmt-2 msgfmt-3 msgfmt-4 msgfmt-5 msgfmt-6 msgfmt-7 \ msgfmt-8 msgfmt-9 msgfmt-10 \ - msggrep-1 msggrep-2 msggrep-3 msggrep-4 \ + msggrep-1 msggrep-2 msggrep-3 msggrep-4 msggrep-5 \ msgmerge-1 msgmerge-2 msgmerge-3 msgmerge-4 msgmerge-5 msgmerge-6 \ msgmerge-7 msgmerge-8 msgmerge-9 msgmerge-10 msgmerge-11 msgmerge-12 \ msgmerge-13 msgmerge-14 msgmerge-15 msgmerge-16 msgmerge-17 \ @@ -45,7 +45,7 @@ TESTS = gettext-1 gettext-2 \ xgettext-1 xgettext-2 xgettext-3 xgettext-4 xgettext-5 xgettext-6 \ xgettext-7 xgettext-8 xgettext-9 xgettext-10 xgettext-11 xgettext-12 \ xgettext-13 xgettext-14 xgettext-15 xgettext-16 xgettext-17 \ - xgettext-18 \ + xgettext-18 xgettext-19 xgettext-20 \ format-awk-1 format-awk-2 \ format-c-1 format-c-2 \ format-elisp-1 format-elisp-2 \ diff --git a/tests/msggrep-5 b/tests/msggrep-5 new file mode 100755 index 000000000..c35aa5df0 --- /dev/null +++ b/tests/msggrep-5 @@ -0,0 +1,234 @@ +#! /bin/sh + +# Test --comment option. + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles mg-test5.po" +cat <<\EOF > mg-test5.po +# German translations for GNU gettext package. +# Copyright (C) 1995, 1996, 1997, 2001 Free Software Foundation, Inc. +msgid "" +msgstr "" +"Project-Id-Version: GNU gettext 0.11-pre1\n" +"POT-Creation-Date: 2001-12-08 20:33+0100\n" +"PO-Revision-Date: 2001-11-04 12:25+0100\n" +"Last-Translator: Karl Eichwalder \n" +"Language-Team: German \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ISO-8859-1\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: argmatch.c:141 +#, c-format +msgid "invalid argument `%s' for `%s'" +msgstr "ungültiges Argument »%s« für »%s«" + +#: argmatch.c:142 +#, c-format +msgid "ambiguous argument `%s' for `%s'" +msgstr "mehrdeutiges Argument »%s« für »%s«" + +#: argmatch.c:162 +msgid "Valid arguments are:" +msgstr "Gültige Argumente sind:" + +# @proofread +#: copy-file.c:60 +#, c-format +msgid "error while opening \"%s\" for reading" +msgstr "Öffnen der Datei »%s« zum Lesen fehlgeschlagen" + +# @proofread +#: copy-file.c:67 +#, c-format +msgid "cannot open backup file \"%s\" for writing" +msgstr "Öffnen der Sicherungsdatei »%s« zum Schreiben fehlgeschlagen" + +#: copy-file.c:80 +#, c-format +msgid "error reading \"%s\"" +msgstr "Fehler beim Lesen von »%s«" + +#: copy-file.c:86 copy-file.c:90 +#, c-format +msgid "error writing \"%s\"" +msgstr "Fehler beim Schreiben von »%s«" + +#: copy-file.c:92 +#, c-format +msgid "error after reading \"%s\"" +msgstr "Fehler nach dem Lesen von »%s«" + +#: error.c:115 +msgid "Unknown system error" +msgstr "Unbekannter Systemfehler" + +# @proofread +#: execute.c:170 execute.c:205 pipe-bidi.c:156 pipe-bidi.c:191 pipe-in.c:169 +#: pipe-in.c:205 pipe-out.c:169 pipe-out.c:205 wait-process.c:136 +#, c-format +msgid "%s subprocess failed" +msgstr "Subprozess %s fehlgeschlagen" + +#: getopt.c:691 +#, c-format +msgid "%s: option `%s' is ambiguous\n" +msgstr "%s: Option »%s« ist mehrdeutig\n" + +#: getopt.c:716 +#, c-format +msgid "%s: option `--%s' doesn't allow an argument\n" +msgstr "%s: Option »--%s« erwartet kein Argument\n" + +#: getopt.c:721 +#, c-format +msgid "%s: option `%c%s' doesn't allow an argument\n" +msgstr "%s: Option »%c%s« erwartet kein Argument\n" + +#: getopt.c:739 getopt.c:912 +#, c-format +msgid "%s: option `%s' requires an argument\n" +msgstr "%s: Option »%s« erwartet ein Argument\n" + +#: getopt.c:768 +#, c-format +msgid "%s: unrecognized option `--%s'\n" +msgstr "%s: unbekannte Option »--%s«\n" + +#: getopt.c:772 +#, c-format +msgid "%s: unrecognized option `%c%s'\n" +msgstr "%s: unbekannte Option »%c%s«\n" + +# Möchte mal gerne wissen, was der Unterschied zwischen +# "unzulässig" und "ungültig" ist. +# Übrigens ist im Englischen "illegal" falsch. +# @proofread +#: getopt.c:798 +#, c-format +msgid "%s: illegal option -- %c\n" +msgstr "%s: unzulässige Option -- %c\n" + +#: getopt.c:801 +#, c-format +msgid "%s: invalid option -- %c\n" +msgstr "%s: ungültige Option -- %c\n" + +#: getopt.c:831 getopt.c:961 +#, c-format +msgid "%s: option requires an argument -- %c\n" +msgstr "%s: Option erwartet ein Argument -- %c\n" + +#: getopt.c:878 +#, c-format +msgid "%s: option `-W %s' is ambiguous\n" +msgstr "%s: Option »-W %s« ist mehrdeutig\n" + +#: getopt.c:896 +#, c-format +msgid "%s: option `-W %s' doesn't allow an argument\n" +msgstr "%s: Option »-W %s« erwartet kein Argument\n" + +#: javacomp.c:465 +msgid "Java compiler not found, try installing gcj or set $JAVAC" +msgstr "" +"Java-Compiler nicht gefunden; bitte »gcj« installieren oder $JAVAC setzen" + +#: javaexec.c:404 +msgid "Java virtual machine not found, try installing gij or set $JAVA" +msgstr "" +"Virtuelle Java-Maschine nicht gefunden; bitte »gcj« installieren oder\n" +"$JAVA setzen" + +#: obstack.c:474 xerror.c:75 xmalloc.c:56 +msgid "memory exhausted" +msgstr "virtueller Speicher erschöpft" + +# Auch "Pipe" eindeutschen. @proofread +#: pipe-bidi.c:119 pipe-bidi.c:121 pipe-in.c:136 pipe-out.c:136 +msgid "cannot create pipe" +msgstr "Es ist nicht möglich, eine Pipe zu erzeugen" + +#: wait-process.c:117 +#, c-format +msgid "%s subprocess" +msgstr "Subprozess %s" + +#: wait-process.c:129 +#, c-format +msgid "%s subprocess got fatal signal" +msgstr "Subprozess %s hat ein fatales Signal erhalten" + +# A pattern specified for the msgid only must not be matched with the msgstr. +msgid "GSG-9" +msgstr "Antiterror-Einheit" +EOF + +tmpfiles="$tmpfiles mg-test5.out mg-test5.err" +: ${MSGGREP=msggrep} +LC_MESSAGES=C LC_ALL= \ +${MSGGREP} -C -e @proofread mg-test5.po -o mg-test5.out >mg-test5.err 2>&1 +result=$? +cat mg-test5.err | grep -v 'warning: Locale charset' | grep -v '^ ' +test $result = 0 || { rm -fr $tmpfiles; exit 1; } + +tmpfiles="$tmpfiles mg-test5.ok" +cat <<\EOF > mg-test5.ok +# German translations for GNU gettext package. +# Copyright (C) 1995, 1996, 1997, 2001 Free Software Foundation, Inc. +msgid "" +msgstr "" +"Project-Id-Version: GNU gettext 0.11-pre1\n" +"POT-Creation-Date: 2001-12-08 20:33+0100\n" +"PO-Revision-Date: 2001-11-04 12:25+0100\n" +"Last-Translator: Karl Eichwalder \n" +"Language-Team: German \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ISO-8859-1\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +# @proofread +#: copy-file.c:60 +#, c-format +msgid "error while opening \"%s\" for reading" +msgstr "Öffnen der Datei »%s« zum Lesen fehlgeschlagen" + +# @proofread +#: copy-file.c:67 +#, c-format +msgid "cannot open backup file \"%s\" for writing" +msgstr "Öffnen der Sicherungsdatei »%s« zum Schreiben fehlgeschlagen" + +# @proofread +#: execute.c:170 execute.c:205 pipe-bidi.c:156 pipe-bidi.c:191 pipe-in.c:169 +#: pipe-in.c:205 pipe-out.c:169 pipe-out.c:205 wait-process.c:136 +#, c-format +msgid "%s subprocess failed" +msgstr "Subprozess %s fehlgeschlagen" + +# Möchte mal gerne wissen, was der Unterschied zwischen +# "unzulässig" und "ungültig" ist. +# Übrigens ist im Englischen "illegal" falsch. +# @proofread +#: getopt.c:798 +#, c-format +msgid "%s: illegal option -- %c\n" +msgstr "%s: unzulässige Option -- %c\n" + +# Auch "Pipe" eindeutschen. @proofread +#: pipe-bidi.c:119 pipe-bidi.c:121 pipe-in.c:136 pipe-out.c:136 +msgid "cannot create pipe" +msgstr "Es ist nicht möglich, eine Pipe zu erzeugen" +EOF + +: ${DIFF=diff} +${DIFF} mg-test5.ok mg-test5.out +result=$? + +rm -fr $tmpfiles + +exit $result -- 2.47.2