From eda4449ce2761b552d8243c995b52c39c0dfa08d Mon Sep 17 00:00:00 2001 From: dv Date: Mon, 30 May 2022 16:07:28 +0000 Subject: [PATCH] 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@ --- usr.bin/grep/util.c | 6 ++++-- 1 file 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; -- 2.20.1