freebsd-dev/contrib/netbsd-tests/usr.bin
Kyle Evans 3e2d96ac97 grep: fix -A handling in conjunction with -m match limitation
The basic issue here is that grep, when given -m 1, would stop all
line processing once it hit the match count and exit immediately.  The
problem with exiting immediately is that -A processing only happens when
subsequent lines are processed and do not match.

The fix here is relatively easy; when bsdgrep matches a line, it resets
the 'tail' of the matching context to the value supplied to -A and
dumps anything that's been queued up for -B. After the current line has
been printed and tail is reset, we check our mcount and do what's
needed. Therefore, at the time that we decide we're doing nothing, we
know that 'tail' of the context is correct and we can simply continue
on if there's still more to pick up.

With this change, we still bail out immediately if there's been no -A
flag. If -A was supplied, we signal that we should continue on. However,
subsequent lines will not even bothere to try and process the line.  We
have reached the match count, so even if the next line would match then
we must process it if it hadn't. Thus, the loop in procfile() can
short-circuit and just process the line as a non-match until
procmatches() indicates that it's safe to stop.

A test has been added to reflect both that we should be picking up the
next line and that the next line should be considered a non-match even
if it should have been.

PR:		253350
MFC-after:	3 days
2021-02-08 12:41:22 -06:00
..
awk
basename
bzip2
cc Checkpoint initial integration work 2016-08-12 08:50:05 +00:00
cmp
config Upgrade NetBSD tests to 01.11.2017_23.20 snapshot 2017-01-13 03:33:57 +00:00
cut
diff
dirname Remove expected failure for :basic (effectively reverting r305007, r305031) 2016-09-19 06:39:08 +00:00
find
gdb Checkpoint initial integration work 2016-08-12 08:50:05 +00:00
grep grep: fix -A handling in conjunction with -m match limitation 2021-02-08 12:41:22 -06:00
gzip
id
infocmp
jot
ld Checkpoint initial integration work 2016-08-12 08:50:05 +00:00
m4
make Checkpoint initial integration work 2016-08-12 08:50:05 +00:00
mixerctl Merge content currently under test from ^/vendor/NetBSD/tests/dist/@r312123 2017-01-14 06:49:17 +00:00
mkdep
nbperf
netpgpverify Upgrade NetBSD tests to 01.11.2017_23.20 snapshot 2017-01-13 03:33:57 +00:00
pr
rump_server
sdiff
sed Checkpoint initial integration work 2016-08-12 08:50:05 +00:00
shmif_dumpbus
sort Checkpoint initial integration work 2016-08-12 08:50:05 +00:00
tmux
tr
unifdef Re-apply fixed r354847 2019-11-20 19:43:34 +00:00
uniq Merge content currently under test from ^/vendor/NetBSD/tests/dist/@r312123 2017-01-14 06:49:17 +00:00
vmstat
xlint/lint1 Upgrade NetBSD tests to 01.11.2017_23.20 snapshot 2017-01-13 03:33:57 +00:00