diff options
author | Ed Maste <emaste@FreeBSD.org> | 2017-05-05 17:35:05 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2017-05-05 17:35:05 +0000 |
commit | e2127de812b4143c20ac1968c55035e5a19f98f5 (patch) | |
tree | 9d7cc1de76c7b2128825db083b9a788ac9890f96 /usr.bin | |
parent | e6c0d5c360d927ce09fd4a8bc70a7fc884d02613 (diff) | |
download | src-e2127de812b4143c20ac1968c55035e5a19f98f5.tar.gz src-e2127de812b4143c20ac1968c55035e5a19f98f5.zip |
bsdgrep: don't ouptut matches with -c, -l, -L
Refactoring done in r317703 broke -c, -l, and -L flags implying
suppression of match printing. Fortunately this is just a matter of not
doing any printing of the resulting matches and context printing was not
broken in this refactoring.
Add some regression tests since this area may still see further
refactoring, include different context flags as well even though they
were not broken in this case.
PR: 219077
Submitted by: Kyle kevans91@ksu.edu
Reported by: markj
Reviewed by: cem, ngie
Differential Revision: https://reviews.freebsd.org/D10607
Notes
Notes:
svn path=/head/; revision=317842
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/grep/util.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index bd2f8acf83a7..cfcc72d8cbd6 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -201,7 +201,7 @@ procfile(const char *fn) struct str *ln; mode_t s; int c, last_outed, t, tail; - bool doctx, same_file; + bool doctx, printmatch, same_file; if (strcmp(fn, "-") == 0) { fn = label != NULL ? label : getstr(1); @@ -237,12 +237,14 @@ procfile(const char *fn) last_outed = 0; same_file = false; doctx = false; - if ((!pc.binary || binbehave != BINFILE_BIN) && !cflag && !qflag && - !lflag && !Lflag && (Aflag != 0 || Bflag != 0)) + printmatch = true; + if ((pc.binary && binbehave == BINFILE_BIN) || cflag || qflag || + lflag || Lflag) + printmatch = false; + if (printmatch && (Aflag != 0 || Bflag != 0)) doctx = true; mcount = mlimit; - for (c = 0; c == 0 || !(lflag || qflag); ) { /* Reset match count for every line processed */ pc.matchidx = 0; @@ -283,7 +285,7 @@ procfile(const char *fn) tail = Aflag; } /* Print the matching line, but only if not quiet/binary */ - if (t == 0 && !qflag && !pc.binary) { + if (t == 0 && printmatch) { printline(&pc, ':'); first_match = false; same_file = true; |