]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
New option --invert-match.
authorBruno Haible <bruno@clisp.org>
Tue, 29 Nov 2005 13:33:44 +0000 (13:33 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:57 +0000 (12:12 +0200)
NEWS
gettext-tools/doc/ChangeLog
gettext-tools/doc/msggrep.texi
gettext-tools/src/ChangeLog
gettext-tools/src/msggrep.c

diff --git a/NEWS b/NEWS
index 844096da2ccab019c3c27382d7410953ecd4ad70..aafd5281e2055a99000254868d9c3a5d59e3d874 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,8 @@
   is used:
     "number of format specifications in 'msgid' and 'msgstr[1]' does not match"
 
+* msggrep has a new option -v/--invert-match that acts like grep's -v option.
+
 * Programming languages support:
 
   - Python:
index f45f76d0b0a9a1cae44ab2615654710f238e61fb..579a827d21cc5fa712a9c22c2195c858ba62b5bb 100644 (file)
@@ -1,3 +1,7 @@
+2005-11-29  Colin Watson  <cjwatson@ubuntu.com>
+
+       * msggrep.texi: Document --invert-match option.
+
 2005-10-18  Bruno Haible  <bruno@clisp.org>
 
        * xgettext.texi (--keyword): Document how to specify the total number
index 2570a2d1f4946d85a8c249d7d70ab42f3491fcc2..8bbff16a52265f2b4ff82806313688b243ec4227 100644 (file)
@@ -140,6 +140,13 @@ Obtain @var{pattern} from @var{file}.
 @opindex --ignore-case@r{, @code{msggrep} option}
 Ignore case distinctions.
 
+@item -v
+@itemx --invert-match
+@opindex -v@r{, @code{msggrep} option}
+@opindex --invert-match@r{, @code{msggrep} option}
+Output only the messages that do not match any selection criterion, instead
+of the messages that match a selection criterion.
+
 @end table
 
 @subsection Input file syntax
index f928c36688268910eca5f7cdff1747703f16638f..a76d9a48497549d6085d251d56b2f33838424681 100644 (file)
@@ -1,3 +1,13 @@
+2005-11-29  Colin Watson  <cjwatson@ubuntu.com>
+
+       * msggrep.c (invert_match): New variable.
+       (long_options): Add --invert-match option.
+       (main): Handle --invert-match option.
+       (usage): Document --invert-match option.
+       (is_message_selected_no_invert): New function, extracted from
+       is_message_selected.
+       (is_message_selected): Call it. Handle match inversion.
+
 2005-11-01  Bruno Haible  <bruno@clisp.org>
 
        * write-csharp.c (write_csharp_code): Add culture_name argument.
index 9f45bdc9b211fbecea73df1db0160f7733130c34..cc9e867cff2badf27a08589d01b3e4154cd2f8cb 100644 (file)
@@ -63,6 +63,9 @@
 /* Force output of PO file even if empty.  */
 static int force_po;
 
+/* Output only non-matching messages.  */
+static bool invert_match = false;
+
 /* Selected source files.  */
 static string_list_ty *location_files;
 
@@ -95,6 +98,7 @@ static const struct option long_options[] =
   { "help", no_argument, NULL, 'h' },
   { "ignore-case", no_argument, NULL, 'i' },
   { "indent", no_argument, NULL, CHAR_MAX + 2 },
+  { "invert-match", no_argument, NULL, 'v' },
   { "location", required_argument, NULL, 'N' },
   { "msgctxt", no_argument, NULL, 'J' },
   { "msgid", no_argument, NULL, 'K' },
@@ -182,7 +186,7 @@ main (int argc, char **argv)
       gt->case_insensitive = false;
     }
 
-  while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiJKM:N:o:pPTVw:",
+  while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiJKM:N:o:pPTvVw:",
                             long_options, NULL))
         != EOF)
     switch (opt)
@@ -320,6 +324,10 @@ error while reading \"%s\""), optarg);
        grep_pass = 2;
        break;
 
+      case 'v':
+       invert_match = true;
+       break;
+
       case 'V':
        do_version = true;
        break;
@@ -537,6 +545,8 @@ expressions if -E is given, or fixed strings if -F is given.\n\
   -e, --regexp=PATTERN        use PATTERN as a regular expression\n\
   -f, --file=FILE             obtain PATTERN from FILE\n\
   -i, --ignore-case           ignore case distinctions\n\
+  -v, --invert-match          output only the messages that do not match any\n\
+                              selection criterion\n\
 "));
       printf ("\n");
       printf (_("\
@@ -649,19 +659,16 @@ is_string_selected (int grep_pass, const char *str, size_t len)
 }
 
 
-/* Return true if a message matches.  */
+/* Return true if a message matches, considering only the positive selection
+   criteria and ignoring --invert-match.  */
 static bool
-is_message_selected (const message_ty *mp)
+is_message_selected_no_invert (const message_ty *mp)
 {
   size_t i;
   const char *msgstr;
   size_t msgstr_len;
   const char *p;
 
-  /* Always keep the header entry.  */
-  if (is_header (mp))
-    return true;
-
   /* Test whether one of mp->filepos[] is selected.  */
   for (i = 0; i < mp->filepos_count; i++)
     if (filename_list_match (location_files, mp->filepos[i].file_name))
@@ -732,6 +739,25 @@ is_message_selected (const message_ty *mp)
 }
 
 
+/* Return true if a message matches.  */
+static bool
+is_message_selected (const message_ty *mp)
+{
+  bool result;
+
+  /* Always keep the header entry.  */
+  if (is_header (mp))
+    return true;
+
+  result = is_message_selected_no_invert (mp);
+
+  if (invert_match)
+    return !result;
+  else
+    return result;
+}
+
+
 static void
 process_message_list (const char *domain, message_list_ty *mlp)
 {