]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
New msggrep option --extracted-comment.
authorBruno Haible <bruno@clisp.org>
Fri, 17 Mar 2006 13:08:07 +0000 (13:08 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:03 +0000 (12:13 +0200)
NEWS
gettext-tools/doc/ChangeLog
gettext-tools/doc/gettext.texi
gettext-tools/doc/msggrep.texi
gettext-tools/src/ChangeLog
gettext-tools/src/msggrep.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am

diff --git a/NEWS b/NEWS
index e49edc4f86232bf6c35eeb42af9696178f09317c..ae78a405e962e4c06a75bcaa2653811305e5977e 100644 (file)
--- 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:
index 16df02db44b070c685f151e35a656176bb5c82b7..1473385d95431c76b0922a097009b0261a131290 100644 (file)
@@ -1,3 +1,9 @@
+2006-03-16  Bruno Haible  <bruno@clisp.org>
+
+       * 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  <bruno@clisp.org>
 
        * xgettext.texi (--keyword): Document suffix 'g'.
index c21d07f7c37063e61049cf9b0251f2b7fe1c5d5e..1190727364e7d288cd2dd5b0f4bc5da7da4e80de 100644 (file)
@@ -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}
index 8bbff16a52265f2b4ff82806313688b243ec4227..8c21a492cc6fd119babc670f233929006f762c02 100644 (file)
@@ -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}
index 493cfb12b365ee0f1aa1e2083854b6b4f26fd690..8cc75a1b52fca566815275217143b09a94a640d3 100644 (file)
@@ -1,3 +1,13 @@
+2006-03-16  Bruno Haible  <bruno@clisp.org>
+
+       * 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 <behdad@cs.toronto.edu>.
+
 2006-03-16  Bruno Haible  <bruno@clisp.org>
 
        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 <danilo@gnome.org>.
 
 2006-03-16  Bruno Haible  <bruno@clisp.org>
 
@@ -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 <clytie@riverland.net.au>.
 
 2006-03-09  Bruno Haible  <bruno@clisp.org>
 
index 2740129316b0723887ae15e79dbf0f536e5cc939..2ae25c983d837b1e6e2197c56cc743fa7c44ebe2 100644 (file)
@@ -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;
 }
 
index c26eb42b037ed35beb3722c69775800f2c8f805e..f794f27bb1a2d14b9fc9e01317633f29190b12cf 100644 (file)
@@ -1,3 +1,8 @@
+2006-03-16  Bruno Haible  <bruno@clisp.org>
+
+       * msggrep-8: New file.
+       * Makefile.am (TESTS): Add it.
+
 2006-03-16  Bruno Haible  <bruno@clisp.org>
 
        * xgettext-c-15: New file.
index 1757fef99dca85a7cb785376eae785f8063cf134..9a48e17b79363f55e8749449a6b46c226658e978 100644 (file)
@@ -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 \