bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] msggrep --invert-match


From: Colin Watson
Subject: [PATCH] msggrep --invert-match
Date: Tue, 29 Nov 2005 10:31:21 +0000
User-agent: Mutt/1.5.9i

Hi,

I spend a fair chunk of time "branding" the Debian installer's
translations for Ubuntu (a distribution derived from Debian), that is,
taking any strings that refer to Debian and making them refer to Ubuntu
instead. This is pretty tedious work and obviously I try to automate it
as much as I can.

One of the tasks I often have to do by hand at the moment is removing
strings that don't make any sense for Ubuntu, such as the Debian
installer's option to select whether you want to install stable,
testing, or unstable, which makes sense for Debian but for reasons I
won't go into here is not at all relevant to Ubuntu. In order to keep
down the size of our diff versus Debian (people often look through it to
see what we've done, so it's important for it to be as small as
possible), to reduce the probability and complexity of future merge
conflicts, and because I happen to know in this case that the strings
I'm removing are very unlikely to be useful to translators even if kept
around with an obsolete #~ marker, I prefer to remove the translations
of these strings entirely. The translations are still available in
Debian, so they aren't lost.

In order to do this, I looked for a msggrep option analogous to 'grep
-v', but couldn't find one. The following patch against current CVS adds
such an option. In this patch I've included a short -v option as well as
the long --invert-match, for least-surprise for people familiar with
grep, although since I know -v is synonymous with --verbose in other
msg* tools I would understand if you thought it were better to omit the
short option.

Index: gettext-tools/doc/msggrep.texi
===================================================================
RCS file: /cvsroot/gettext/gettext/gettext-tools/doc/msggrep.texi,v
retrieving revision 1.5
diff -p -u -r1.5 msggrep.texi
--- gettext-tools/doc/msggrep.texi      6 Oct 2005 11:20:08 -0000       1.5
+++ gettext-tools/doc/msggrep.texi      29 Nov 2005 10:18:50 -0000
@@ -140,6 +140,12 @@ Obtain @var{pattern} from @var{file}.
 @opindex address@hidden, @code{msggrep} option}
 Ignore case distinctions.
 
address@hidden -v
address@hidden --invert-match
address@hidden address@hidden, @code{msggrep} option}
address@hidden address@hidden, @code{msggrep} option}
+Only output messages that do not match any selection criteria.
+
 @end table
 
 @subsection Input file syntax
Index: gettext-tools/src/msggrep.c
===================================================================
RCS file: /cvsroot/gettext/gettext/gettext-tools/src/msggrep.c,v
retrieving revision 1.26
diff -p -u -r1.26 msggrep.c
--- gettext-tools/src/msggrep.c 6 Oct 2005 11:20:08 -0000       1.26
+++ gettext-tools/src/msggrep.c 29 Nov 2005 10:18:53 -0000
@@ -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 str
   -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          only output messages that do not match any\n\
+                              selection criteria\n\
 "));
       printf ("\n");
       printf (_("\
@@ -651,17 +661,13 @@ is_string_selected (int grep_pass, const
 
 /* Return true if a message matches.  */
 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))
@@ -729,6 +735,27 @@ is_message_selected (const message_ty *m
     }
 
   return false;
+}
+
+
+/* Return true if a message matches.  If --invert-match is given, then
+ * return false if a message matches instead, except for the header entry
+ * for which we always return true no matter what.  */
+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;
 }
 
 

Thanks,

-- 
Colin Watson                                       address@hidden

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]