summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2005-11-29 13:33:44 +0000
committerBruno Haible <bruno@clisp.org>2009-06-23 12:12:57 +0200
commit4ac7d5061ddc8e32969153cc8b3befb44b3105f4 (patch)
treea04349627d43b5c244ba16d4cba4f4d6cb84ddcf
parent38d7f4e293d5938f589dc80a3c7f028d1182c607 (diff)
downloadexternal_gettext-4ac7d5061ddc8e32969153cc8b3befb44b3105f4.zip
external_gettext-4ac7d5061ddc8e32969153cc8b3befb44b3105f4.tar.gz
external_gettext-4ac7d5061ddc8e32969153cc8b3befb44b3105f4.tar.bz2
New option --invert-match.
-rw-r--r--NEWS2
-rw-r--r--gettext-tools/doc/ChangeLog4
-rw-r--r--gettext-tools/doc/msggrep.texi7
-rw-r--r--gettext-tools/src/ChangeLog10
-rw-r--r--gettext-tools/src/msggrep.c40
5 files changed, 56 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index 844096d..aafd528 100644
--- 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:
diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog
index f45f76d..579a827 100644
--- a/gettext-tools/doc/ChangeLog
+++ b/gettext-tools/doc/ChangeLog
@@ -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
diff --git a/gettext-tools/doc/msggrep.texi b/gettext-tools/doc/msggrep.texi
index 2570a2d..8bbff16 100644
--- a/gettext-tools/doc/msggrep.texi
+++ b/gettext-tools/doc/msggrep.texi
@@ -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
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
index f928c36..a76d9a4 100644
--- a/gettext-tools/src/ChangeLog
+++ b/gettext-tools/src/ChangeLog
@@ -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.
diff --git a/gettext-tools/src/msggrep.c b/gettext-tools/src/msggrep.c
index 9f45bdc..cc9e867 100644
--- a/gettext-tools/src/msggrep.c
+++ b/gettext-tools/src/msggrep.c
@@ -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)
{