summaryrefslogtreecommitdiff
path: root/usr.bin/grep
diff options
context:
space:
mode:
authorDave Voutila <dv@cvs.openbsd.org>2022-05-30 16:07:29 +0000
committerDave Voutila <dv@cvs.openbsd.org>2022-05-30 16:07:29 +0000
commitf2c103f311f2086993741895c4c5fb10b6dc0ac8 (patch)
treeab91a07727f6893c19d41c7649b7a0bc7ff282d6 /usr.bin/grep
parentcbc687c68f61c4827c6c35ddaa4975692b562403 (diff)
grep(1): print full context when using match count
When using the match count flag (-m), grep was not printing the context after the match if the -A or -C flags were provided. This changes the logic to continue printing lines after hitting the match count. ok op@, millert@
Diffstat (limited to 'usr.bin/grep')
-rw-r--r--usr.bin/grep/util.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index bcef0897881..33b10946590 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.64 2021/12/28 16:27:53 otto Exp $ */
+/* $OpenBSD: util.c,v 1.65 2022/05/30 16:07:28 dv Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -163,7 +163,7 @@ procfile(char *fn)
overflow = 1;
else
c += t;
- if (mflag && mcount <= 0)
+ if (mflag && mcount <= 0 && tail <= 0)
break;
}
if (Bflag > 0)
@@ -212,6 +212,8 @@ procline(str_t *l, int nottext)
c = 1;
goto print;
}
+ if (mflag && mcount <= 0)
+ goto print;
for (i = 0; i < patterns; i++) {
offset = 0;