[Dctrl-tools-devel] [dctrl-tools] 01/02: grep-dctrl: Implement -l and -L as in grep.

Antti-Juhani Kaijanaho ajk at moszumanska.debian.org
Tue Nov 26 10:24:59 UTC 2013


This is an automated email from the git hooks/post-receive script.

ajk pushed a commit to branch master
in repository dctrl-tools.

commit 8083c32bc3823131d99bdd7e5c2cd31234138da3
Author: Antti-Juhani Kaijanaho <antti-juhani at kaijanaho.fi>
Date:   Tue Nov 26 12:24:41 2013 +0200

    grep-dctrl: Implement -l and -L as in grep.
    
    Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani at kaijanaho.fi>
---
 debian/changelog        |  5 ++--
 grep-dctrl/grep-dctrl.c | 71 +++++++++++++++++++++++++++++++++++++++++--------
 man/grep-dctrl.1.cp     | 18 ++++++++++---
 tests/0023.out          |  1 +
 tests/0023.sh           |  8 ++++++
 tests/0024.out          |  1 +
 tests/0024.sh           |  8 ++++++
 7 files changed, 95 insertions(+), 17 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 6e16f91..df3cb02 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,9 @@
 dctrl-tools (2.24) UNRELEASED; urgency=low
 
-  * 
+  * grep-dctrl: Implement -l and -L as in grep.
+    (This changes the meaning of -l, but I doubt any scripts have relied on it.)
 
- -- Antti-Juhani Kaijanaho <ajk at debian.org>  Tue, 07 May 2013 23:22:19 +0300
+ -- Antti-Juhani Kaijanaho <ajk at debian.org>  Tue, 26 Nov 2013 12:10:51 +0200
 
 dctrl-tools (2.23) unstable; urgency=low
 
diff --git a/grep-dctrl/grep-dctrl.c b/grep-dctrl/grep-dctrl.c
index 7ff6e44..166a1b3 100644
--- a/grep-dctrl/grep-dctrl.c
+++ b/grep-dctrl/grep-dctrl.c
@@ -1,6 +1,6 @@
 /*  dctrl-tools - Debian control file inspection tools
     Copyright © 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-                2010, 2011, 2012
+                2010, 2011, 2012, 2013
                 Antti-Juhani Kaijanaho
 
     This program is free software; you can redistribute it and/or modify
@@ -63,17 +63,20 @@ enum {
         OPT_IGN_ERRS,
         OPT_ENSURE,
         OPT_COMPAT,
-        OPT_PATTERN
+        OPT_PATTERN,
+        OPT_ERRORLEVEL,
 };
 
 static struct argp_option options[] = {
-	{ "errorlevel",	    'l', N_("LEVEL"),	    0, N_("Set log level to LEVEL."), 0 },
+	{ "errorlevel",	    OPT_ERRORLEVEL, N_("LEVEL"), 0, N_("Set log level to LEVEL."), 0 },
 	{ "field",	    'F', N_("FIELD,FIELD,..."), 0, N_("Restrict pattern matching to the FIELDs given."), 0 },
 	{ 0,		    'P', 0,		    0, N_("This is a shorthand for -FPackage."), 0 },
 	{ 0,		    'S', 0,		    0, N_("This is a shorthand for -FSource:Package."), 0 },
 	{ "show-field",	    's', N_("FIELD,FIELD,..."), 0, N_("Show only the body of these fields from the matching paragraphs."), 0 },
 	{ 0,		    'd', 0,		    0, N_("Show only the first line of the \"Description\" field from the matching paragraphs."), 0 },
 	{ "no-field-names", 'n', 0,		    0, N_("Suppress field names when showing specified fields."), 0 },
+        { "files-with-matches", 'l', 0,             0, N_("Show only the names of the files that contain matching paragraphs."), 0 },
+        { "files-without-matches", 'L', 0,          0, N_("Show only the names of the files that do not contain matching paragraphs."), 0 },
 	{ "eregex",	    'e', 0,		    0, N_("Regard the pattern as an extended POSIX regular expression."), 0 },
 	{ "regex",	    'r', 0,		    0, N_("Regard the pattern as a standard POSIX regular expression."), 0 },
 	{ "ignore-case",    'i', 0,		    0, N_("Ignore case when looking for a match."), 0 },
@@ -157,6 +160,8 @@ struct arguments {
 	bool invert_match;
         /* Show fields that are NOT listed? */
         bool invert_show;
+        /* Show only file name? */
+        bool only_file_name;
 	/* First unused position in toks.  */
 	size_t toks_np;
         /* Token read position. */
@@ -208,6 +213,13 @@ static error_t parse_opt (int key, char * arg, struct argp_state * state)
                 args->ensure_dctrl = false;
                 break;
 	case 'v':
+                if (args->only_file_name) {
+                        message(L_FATAL, 0,
+                                args->invert_match
+                                ? _("-v is incompatible with -L")
+                                : _("-v is incompatible with -l"));
+                        fail();
+                }
 		args->invert_match = true;
 		break;
 	case 'c':
@@ -221,6 +233,31 @@ static error_t parse_opt (int key, char * arg, struct argp_state * state)
 		debug_message("parse_opt: n", 0);
 		args->show_field_name = false;
 		break;
+	case 'l':
+                if (args->only_file_name) {
+                        message(L_FATAL, 0,
+                                _("only one -l or -L is allowed"));
+                        fail();
+                }
+                if (args->invert_match) {
+                        message(L_FATAL, 0, _("-l is incompatible with -v"));
+                        fail();
+                }
+		args->only_file_name = true;
+		break;
+	case 'L':
+                if (args->only_file_name) {
+                        message(L_FATAL, 0,
+                                _("only one -l or -L is allowed"));
+                        fail();
+                }
+                if (args->invert_match) {
+                        message(L_FATAL, 0, _("-L is incompatible with -v"));
+                        fail();
+                }
+		args->only_file_name = true;
+                args->invert_match = true;
+		break;
 	case 'd':
 		args->short_descr = true;
 		break;
@@ -258,7 +295,7 @@ static error_t parse_opt (int key, char * arg, struct argp_state * state)
 		free(carg);
 	}
 		break;
-	case 'l': {
+	case OPT_ERRORLEVEL: {
 		int ll = str2loglevel(arg);
 		if (ll < 0)
 		{
@@ -922,13 +959,24 @@ int main (int argc, char * argv[])
 		para_init(&pp, &para);
 		while (1) {
 			para_parse_next(&para);
-			if (para_eof(&pp)) break;
-			if ((args.invert_match 
-			     || !does_para_satisfy(args.p, &para))
-			    && (!args.invert_match 
-				|| does_para_satisfy(args.p, &para))) {
-				continue;
-			}
+			if (para_eof(&pp)) {
+                                if (args.only_file_name && args.invert_match) {
+                                        printf("%s\n", fname.s);
+                                        found = true;
+                                }
+                                break;
+                        }
+                        bool sat = does_para_satisfy(args.p, &para);
+                        if (args.only_file_name) {
+                                if (!sat) continue;
+                                if (!args.invert_match) {
+                                        printf("%s\n", fname.s);
+                                        found = true;
+                                }
+                                break;
+                        }
+                        if (sat == args.invert_match) continue;
+
 			if (args.quiet) {
 				exit(0);
 			}
@@ -937,6 +985,7 @@ int main (int argc, char * argv[])
 				++count;
 				continue;
 			}
+
                         print_para(&args, &para);
                 }
 		fsaf_close(fp);
diff --git a/man/grep-dctrl.1.cp b/man/grep-dctrl.1.cp
index 4729376..004390d 100644
--- a/man/grep-dctrl.1.cp
+++ b/man/grep-dctrl.1.cp
@@ -1,6 +1,6 @@
-.TH GREP-DCTRL 1 2012-04-22 "Debian Project" "Debian user's manual"
+.TH GREP-DCTRL 1 2013-11-26 "Debian Project" "Debian user's manual"
 \" Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2011,
-\"               2012
+\"               2012, 2013
 \"               Antti-Juhani Kaijanaho <ajk at debian.org>
 \"      This program is free software; you can redistribute it and/or modify
 \"      it under the terms of the GNU General Public License as published by
@@ -252,6 +252,16 @@ escaped for most shells.  Filter modifiers can be given before the
 opening parentheses; they will be treated as if they had been repeated
 for each simple filter inside the parentheses.
 .SS Output format modifiers
+.IP "\fB\-l\fR, \fB\-\-files\-with\-matches"
+Output only the file names, each on its own line, of those files that contain
+at least one matching paragraph.  This is incompatible with the
+.BR \-v " and " \-L
+options, and all other output format modifiers will be ignored.
+.IP "\fB\-L\fR, \fB\-\-files\-without\-matches"
+Output only the file names, each on its own line, of those files that do not
+contain any matching paragraphs.  This is incompatible with the
+.BR \-v " and " \-l
+options, and all other output format modifiers will be ignored.
 .IP "\fB\-s \fIfield\fR,\fIfield\fR, ... | \fB\-\-show\-field=\fIfield\fR,\fIfield\fR, ..."
 Show only the body of these
 .IR field s
@@ -338,7 +348,7 @@ is ignored in its entirety, and the next paragraph is assumed to start
 after the first newline since the location of the error.
 .IP "\fB\-\-debug\-optparse"
 Show how the current command line has been parsed. 
-.IP "\fB\-l \fIlevel\fR, \fB\-\-errorlevel=\fIlevel"
+.IP "\fB\-\-errorlevel=\fIlevel"
 Set log level to
 .IR level .
 .I level
@@ -572,7 +582,7 @@ There were more opening than closing parentheses in the given
 filter.
 .IP "\fBno such log level"
 The argument to
-.B \-l
+.B \-\-errorlevel
 was invalid.
 .IP "\fBtoo many file names"
 The number of file names specified in the command line exceeded a
diff --git a/tests/0023.out b/tests/0023.out
new file mode 100644
index 0000000..e1003ed
--- /dev/null
+++ b/tests/0023.out
@@ -0,0 +1 @@
+0014.in
diff --git a/tests/0023.sh b/tests/0023.sh
new file mode 100644
index 0000000..e5768c4
--- /dev/null
+++ b/tests/0023.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+set -e
+
+LC_ALL=C
+export LC_ALL
+
+$GREP_DCTRL -FPackage aaab -l 0014.in 0015.in
diff --git a/tests/0024.out b/tests/0024.out
new file mode 100644
index 0000000..3ed0b46
--- /dev/null
+++ b/tests/0024.out
@@ -0,0 +1 @@
+0015.in
diff --git a/tests/0024.sh b/tests/0024.sh
new file mode 100644
index 0000000..fa49f06
--- /dev/null
+++ b/tests/0024.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+set -e
+
+LC_ALL=C
+export LC_ALL
+
+$GREP_DCTRL -FPackage aaab -L 0014.in 0015.in

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/dctrl-tools.git



More information about the Dctrl-tools-devel mailing list