From: Bruno Haible Date: Fri, 17 Mar 2006 13:08:07 +0000 (+0000) Subject: New msggrep option --extracted-comment. X-Git-Tag: v0.15~283 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2fc16240dc0c53147273b164fa6f7d68118cf081;p=thirdparty%2Fgettext.git New msggrep option --extracted-comment. --- diff --git a/NEWS b/NEWS index e49edc4f8..ae78a405e 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,9 @@ * msggrep has a new option -v/--invert-match that acts like grep's -v option. +* msggrep has a new option -X/--extracted-comment that allows to search for a + pattern in the extracted comments. + * msgmerge is much faster now, when using a large compendium. * Programming languages support: diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 16df02db4..1473385d9 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,9 @@ +2006-03-16 Bruno Haible + + * gettext.texi (PO Files): Clarify the terms "automatic comments" and + "extracted comments". + * msggrep.texi: Document the -X/--extracted-comment option. + 2006-03-16 Bruno Haible * xgettext.texi (--keyword): Document suffix 'g'. diff --git a/gettext-tools/doc/gettext.texi b/gettext-tools/doc/gettext.texi index c21d07f7c..119072736 100644 --- a/gettext-tools/doc/gettext.texi +++ b/gettext-tools/doc/gettext.texi @@ -1103,7 +1103,7 @@ structure: @example @var{white-space} # @var{translator-comments} -#. @var{automatic-comments} +#. @var{extracted-comments} #: @var{reference}@dots{} #, @var{flag}@dots{} msgid @var{untranslated-string} @@ -1122,14 +1122,24 @@ msgid "Unknown system error" msgstr "Error desconegut del sistema" @end example +@cindex comments, translator +@cindex comments, automatic +@cindex comments, extracted Entries begin with some optional white space. Usually, when generated through GNU @code{gettext} tools, there is exactly one blank line between entries. Then comments follow, on lines all starting with the character @code{#}. There are two kinds of comments: those which have -some white space immediately following the @code{#}, which comments are -created and maintained exclusively by the translator, and those which -have some non-white character just after the @code{#}, which comments -are created and maintained automatically by GNU @code{gettext} tools. +some white space immediately following the @code{#} - the @var{translator +comments} -, which comments are created and maintained exclusively by the +translator, and those which have some non-white character just after the +@code{#} - the @var{automatic comments} -, which comments are created and +maintained automatically by GNU @code{gettext} tools. Comment lines +starting with @code{#.} contain comments given by the programmer, directed +at the translator; these comments are called @var{extracted comments} +because the @code{xgettext} program extracts them from the program's +source code. Comment lines starting with @code{#:} contain references to +the program's source code. Comment lines starting with @code{#,} contain +flags; more about these below. All comments, of either kind, are optional. @kwindex msgid @@ -1318,7 +1328,7 @@ this: @example @var{white-space} # @var{translator-comments} -#. @var{automatic-comments} +#. @var{extracted-comments} #: @var{reference}@dots{} #, @var{flag}@dots{} msgctxt @var{context} @@ -1340,7 +1350,7 @@ plural forms. @example @var{white-space} # @var{translator-comments} -#. @var{automatic-comments} +#. @var{extracted-comments} #: @var{reference}@dots{} #, @var{flag}@dots{} msgid @var{untranslated-string-singular} diff --git a/gettext-tools/doc/msggrep.texi b/gettext-tools/doc/msggrep.texi index 8bbff16a5..8c21a492c 100644 --- a/gettext-tools/doc/msggrep.texi +++ b/gettext-tools/doc/msggrep.texi @@ -110,6 +110,12 @@ Start of patterns for the msgstr. @opindex --comment@r{, @code{msggrep} option} Start of patterns for the translator's comment. +@item -X +@itemx --extracted-comment +@opindex -X@r{, @code{msggrep} option} +@opindex --extracted-comment@r{, @code{msggrep} option} +Start of patterns for the extracted comments. + @item -E @itemx --extended-regexp @opindex -E@r{, @code{msggrep} option} diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 493cfb12b..8cc75a1b5 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,13 @@ +2006-03-16 Bruno Haible + + * msggrep.c (grep_task): Increment size. + (long_options): Add --extracted-comment option. + (main): Handle --extracted-comment option. + (no_pass, usage): Update. + (is_message_selected_no_invert): Implement matching on extracted + comments. + Suggested by Behdad Esfahbod . + 2006-03-16 Bruno Haible Handle GNOME glib context syntax. @@ -12,6 +22,7 @@ (arglist_parser_done): When suffix 'g' was specified, split off the context from the msgid and/or msgid_plural. * x-perl.c (extract_variable): Update. + Suggested by Danilo Å egan . 2006-03-16 Bruno Haible @@ -67,6 +78,7 @@ (msgl-fsearch.obj): New rule. * Makefile.vms (msgmerge_OBJECTS): Add msgl-fsearch.obj. (msgl-fsearch.obj): New rule. + Reported by Clytie Siddall . 2006-03-09 Bruno Haible diff --git a/gettext-tools/src/msggrep.c b/gettext-tools/src/msggrep.c index 274012931..2ae25c983 100644 --- a/gettext-tools/src/msggrep.c +++ b/gettext-tools/src/msggrep.c @@ -81,7 +81,7 @@ struct grep_task { bool case_insensitive; void *compiled_patterns; }; -static struct grep_task grep_task[4]; +static struct grep_task grep_task[5]; /* Long options. */ static const struct option long_options[] = @@ -92,6 +92,7 @@ static const struct option long_options[] = { "domain", required_argument, NULL, 'M' }, { "escape", no_argument, NULL, CHAR_MAX + 1 }, { "extended-regexp", no_argument, NULL, 'E' }, + { "extracted-comment", no_argument, NULL, 'X' }, { "file", required_argument, NULL, 'f' }, { "fixed-strings", no_argument, NULL, 'F' }, { "force-po", no_argument, &force_po, 1 }, @@ -175,7 +176,7 @@ main (int argc, char **argv) location_files = string_list_alloc (); domain_names = string_list_alloc (); - for (i = 0; i < 4; i++) + for (i = 0; i < 5; i++) { struct grep_task *gt = &grep_task[i]; @@ -186,7 +187,7 @@ main (int argc, char **argv) gt->case_insensitive = false; } - while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiJKM:N:o:pPTvVw:", + while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiJKM:N:o:pPTvVw:X", long_options, NULL)) != EOF) switch (opt) @@ -342,6 +343,10 @@ error while reading \"%s\""), optarg); } break; + case 'X': + grep_pass = 4; + break; + case CHAR_MAX + 1: message_print_style_escape (true); break; @@ -418,7 +423,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ "--sort-output", "--sort-by-file"); /* Compile the patterns. */ - for (grep_pass = 0; grep_pass < 4; grep_pass++) + for (grep_pass = 0; grep_pass < 5; grep_pass++) { struct grep_task *gt = &grep_task[grep_pass]; @@ -442,7 +447,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ if (grep_task[0].pattern_count > 0 || grep_task[1].pattern_count > 0 || grep_task[2].pattern_count > 0 - || grep_task[3].pattern_count > 0) + || grep_task[3].pattern_count > 0 + || grep_task[4].pattern_count > 0) { /* Warn if the current locale is not suitable for this PO file. */ compare_po_locale_charsets (result); @@ -468,7 +474,7 @@ static void no_pass (int opt) { error (EXIT_SUCCESS, 0, - _("option '%c' cannot be used before 'J' or 'K' or 'T' or 'C' has been specified"), + _("option '%c' cannot be used before 'J' or 'K' or 'T' or 'C' or 'X' has been specified"), opt); usage (EXIT_FAILURE); } @@ -518,18 +524,20 @@ or if it is -.\n")); Message selection:\n\ [-N SOURCEFILE]... [-M DOMAINNAME]...\n\ [-J MSGCTXT-PATTERN] [-K MSGID-PATTERN] [-T MSGSTR-PATTERN]\n\ - [-C COMMENT-PATTERN]\n\ + [-C COMMENT-PATTERN] [-X EXTRACTED-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 -J is given and its context (msgctxt) matches MSGCTXT-PATTERN,\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 -C is given and the translator's comment matches COMMENT-PATTERN.\n\ +or if -C is given and the translator's comment matches COMMENT-PATTERN,\n\ +or if -X is given and the extracted comment matches EXTRACTED-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\ \n\ -MSGCTXT-PATTERN or MSGID-PATTERN or MSGSTR-PATTERN or COMMENT-PATTERN syntax:\n\ +MSGCTXT-PATTERN or MSGID-PATTERN or MSGSTR-PATTERN or COMMENT-PATTERN or\n\ +EXTRACTED-COMMENT-PATTERN syntax:\n\ [-E | -F] [-e PATTERN | -f FILE]...\n\ PATTERNs are basic regular expressions by default, or extended regular\n\ expressions if -E is given, or fixed strings if -F is given.\n\ @@ -540,6 +548,7 @@ expressions if -E is given, or fixed strings if -F is given.\n\ -K, --msgid start of patterns for the msgid\n\ -T, --msgstr start of patterns for the msgstr\n\ -C, --comment start of patterns for the translator's comment\n\ + -X, --extracted-comment start of patterns for the extracted comment\n\ -E, --extended-regexp PATTERN is an extended regular expression\n\ -F, --fixed-strings PATTERN is a set of newline-separated strings\n\ -e, --regexp=PATTERN use PATTERN as a regular expression\n\ @@ -735,6 +744,41 @@ is_message_selected_no_invert (const message_ty *mp) return true; } + /* Test extracted comments using the --extracted-comment arguments. */ + if (grep_task[4].pattern_count > 0 + && mp->comment_dot != NULL && mp->comment_dot->nitems > 0) + { + size_t length; + char *total_comment; + char *q; + size_t j; + bool selected; + + length = 0; + for (j = 0; j < mp->comment_dot->nitems; j++) + length += strlen (mp->comment_dot->item[j]) + 1; + total_comment = (char *) xallocsa (length); + + q = total_comment; + for (j = 0; j < mp->comment_dot->nitems; j++) + { + size_t l = strlen (mp->comment_dot->item[j]); + + memcpy (q, mp->comment_dot->item[j], l); + q += l; + *q++ = '\n'; + } + if (q != total_comment + length) + abort (); + + selected = is_string_selected (4, total_comment, length); + + freesa (total_comment); + + if (selected) + return true; + } + return false; } diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index c26eb42b0..f794f27bb 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,8 @@ +2006-03-16 Bruno Haible + + * msggrep-8: New file. + * Makefile.am (TESTS): Add it. + 2006-03-16 Bruno Haible * xgettext-c-15: New file. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 1757fef99..9a48e17b7 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -44,6 +44,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \ msgfmt-properties-1 \ msgfmt-qt-1 \ msggrep-1 msggrep-2 msggrep-3 msggrep-4 msggrep-5 msggrep-6 msggrep-7 \ + msggrep-8 \ msginit-1 msginit-2 \ msgmerge-1 msgmerge-2 msgmerge-3 msgmerge-4 msgmerge-5 msgmerge-6 \ msgmerge-7 msgmerge-8 msgmerge-9 msgmerge-10 msgmerge-11 msgmerge-12 \