freebsd-src/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
..
addr2line
alias
apply
ar
asa
at
atm
awk
backlight Clean up backlight.8 2020-10-27 09:41:01 +00:00
banner
basename
bc
biff
bluetooth
bmake Merge bmake-20210110 2021-01-13 22:21:37 -08:00
brandelf
bsdcat bsdcat,cpio,tar: derive version string from archive.h 2020-12-29 14:21:50 -08:00
bsdiff bsdiff: fix off-by-one error 2020-11-16 18:41:49 +00:00
bzip2
bzip2recover
c89
c99
caesar
calendar Complete Steps 5 and 9 from the Committer's guide 2021-01-22 11:54:05 +00:00
cap_mkdb
chat Fix a few mandoc issues 2020-10-09 14:03:45 +00:00
chkey
chpass Partially revert r367756 (chpass(1) synopsis changes) 2020-11-17 16:54:12 +00:00
cksum
clang Add WITH_LLVM_CXXFILT option to install llvm-cxxfilt as c++filt 2020-11-03 19:57:28 +00:00
cmp cmp: fix -s (silent) when used with skip offsets 2021-01-10 19:02:56 -05:00
col col(1): Add EXAMPLES section 2020-10-21 16:30:34 +00:00
colrm
column
comm
compile_et
compress compress(1): Add EXAMPLES section 2020-10-20 13:05:25 +00:00
cpio bsdcat,cpio,tar: derive version string from archive.h 2020-12-29 14:21:50 -08:00
cpuset cpuset(1): Fix a typo 2020-10-10 13:01:04 +00:00
csplit
ctags
ctlstat
cut
cxxfilt
dc
diff diff: Use unprivileged_user with report_identical test 2021-02-03 17:18:59 +01:00
diff3
dirname
dpv Fix a few mandoc issues 2020-10-09 19:12:44 +00:00
drill Rename NO_WERROR -> MK_WERROR=no 2021-01-07 09:31:03 +00:00
dtc
du du_test: Skip three tests if sparse files are not supported 2021-02-03 17:06:07 +00:00
ee
elfctl elfctl: Fix type errors. 2021-01-23 17:24:32 +02:00
elfdump
enigma
env Document in the synopsis that -0 cannot be used with the utility argument 2020-11-11 14:53:03 +00:00
etdump
expand
factor
false
fetch fetch(1): Fix style 2020-10-30 09:48:41 +00:00
file
file2c
find
finger
fmt fmt(1): Add EXAMPLES section 2020-10-29 18:37:20 +00:00
fold fold(1): Add EXAMPLES section 2020-10-29 18:39:04 +00:00
fortune fortune(6): Add EXIT STATUS and HISTORY sections 2021-01-03 23:51:39 +01:00
from
fstat fstat(1): Add EXAMPLES section 2020-11-19 19:05:16 +00:00
fsync
ftp
gcore
gencat
getaddrinfo
getconf
getent getent(1): Add EXAMPLES section 2020-10-24 16:40:34 +00:00
getopt
gh-bc Make generated C files depend on this Makefile 2020-11-27 09:00:21 +00:00
gprof gprof: Retire a.out support 2020-12-26 11:47:47 -05:00
grdc
grep grep: fix -A handling in conjunction with -m match limitation 2021-02-08 12:41:22 -06:00
gzip fts_read: Handle error from a NULL return better. 2020-12-08 23:38:26 +00:00
head
hesinfo
hexdump
host
iconv iconv(1): Add EXAMPLE 2020-11-29 18:22:14 +00:00
id id(1): Add EXAMPLES section 2020-12-10 18:34:15 +00:00
ident ident(1): Normalizing date format 2020-12-19 12:54:00 +00:00
indent Fix a few mandoc issues 2020-10-09 19:12:44 +00:00
ipcrm
ipcs
iscsictl iscsi.conf(5): Fix a mandoc warning 2020-11-20 16:41:32 +00:00
join
jot
kdump Rename NO_WERROR -> MK_WERROR=no 2021-01-07 09:31:03 +00:00
keylogin
keylogout
killall
ktrace
ktrdump
kyua pkgbase: Install atf and kyua in the tests package 2021-01-04 16:20:47 +01:00
lam
last last(1): Add EXAMPLES section 2021-01-09 18:37:25 +01:00
lastcomm
ldd Fix ldd to work with more ELF files. 2021-01-29 10:53:50 -08:00
ldd32
leave
less
lessecho
lesskey
lex
limits
locale
localedef Add collation version support to querylocale(3). 2020-11-08 02:50:34 +00:00
locate Fix a grammar error on locate(1). 2020-12-11 08:04:54 +00:00
lock lock(1): Add EXAMPLES section 2020-12-11 19:27:21 +00:00
lockf
logger
login login(1): when exporting variables check the result of setenv(3) 2020-12-19 03:07:38 +00:00
logins
logname
look look(1): Add EXAMPLES section 2020-12-29 21:48:12 +01:00
lorder
lsvfs lsvfs(1): Add EXAMPLES section 2020-12-29 21:35:24 +01:00
lzmainfo
m4
mail Replace literal uses of /usr/local in C sources with _PATH_LOCALBASE 2020-10-27 11:29:11 +00:00
man man(1): Bump .Dd 2021-01-09 18:22:08 +01:00
mandoc
mesg
minigzip
ministat
mkcsmapper
mkcsmapper_static
mkdep
mkesdb
mkesdb_static
mkfifo
mkimg Fix -Wpointer-sign warnings in makefs and mkimg 2021-01-07 09:26:21 +00:00
mkstr
mktemp
mkuzip
morse
msgs
mt Add the LTO-9 density code to libmt and the mt(1) man page. 2020-12-10 21:06:06 +00:00
nc
ncal
netstat icmp6: Count packets dropped due to an invalid hop limit 2020-10-19 17:07:19 +00:00
newgrp
newkey
nfsstat nfsstat: delete unused fields 2020-10-24 05:52:29 +00:00
nice
nl
nm
nohup
number
objcopy
ofed ofed: fix the WITH_OFED_EXTRA build 2021-01-29 23:52:13 -06:00
opieinfo
opiekey
opiepasswd
pagesize
pamtest
passwd
paste
patch patch(1): Fix a few mandoc related issues 2020-12-19 13:00:17 +00:00
pathchk
perror
pom
posixshmcontrol
pr
primes
printenv
printf
proccontrol
procstat Decode and report native eventfd descriptors from libprocstat and procstat. 2020-12-27 12:57:27 +02:00
protect
quota
random
rctl Drop "All rights reserved" from all my stuff. This includes 2020-10-28 13:46:11 +00:00
readelf readelf: Add -z decompression support 2020-10-31 15:27:45 +00:00
renice renice(8): Clarify "who" parameters. 2020-10-27 12:32:17 +00:00
resizewin
rev
revoke
rpcgen
rpcinfo
rs
rup
ruptime
rusers
rwall
rwho
script Add some examples to script.1 2021-01-05 16:32:27 +01:00
sdiff
sdiotool
sed
seq
setchannel Fix a few mandoc issues 2020-10-09 14:03:45 +00:00
shar
showmount
size
smbutil
sockstat Add "-n" flag to sockstat. 2020-12-30 13:45:53 -05:00
soelim
sort
split
ssh-copy-id
stat
stdbuf
strings
su
svn
systat Adjust to display more than 999 sleeping threads 2020-12-27 22:32:22 +01:00
tabs
tail tail: fix "tail -F" file rotation detection 2021-02-01 16:21:14 -08:00
talk
tar bsdcat,cpio,tar: derive version string from archive.h 2020-12-29 14:21:50 -08:00
tcopy
tee
telnet
tests
tftp Fix a few mandoc issues 2020-10-09 14:03:45 +00:00
time
timeout
tip
top
touch
tput
tr
true
truncate
truss truss: Decode sendfile(2) arguments 2021-02-05 11:28:29 -05:00
tset
tsort
tty
ul ul(1): Remove references to colcrt(1) and nroff(1) 2020-10-07 14:43:16 +00:00
uname uname(1): Fix a typo in the man page date 2020-12-19 12:55:27 +00:00
unexpand
unifdef
uniq
units
unvis
unzip unzip: Sync with NetBSD upstream. 2021-01-02 10:50:08 +09:00
usbhidaction Correct USB HID item in examples 2020-10-28 08:29:31 +00:00
usbhidctl
users
uudecode
uuencode
vacation
vgrind
vi
vis
vmstat vmstat: drop the HighUse field from malloc dump 2020-11-09 23:00:29 +00:00
vtfontcvt
w
wall
wc
what
whereis
which
who
whois
write
xargs xargs: compile yesexpr as ERE 2020-12-12 15:38:32 +00:00
xinstall install(1): Avoid unncessary fstatfs() calls and use mmap() based on size 2020-10-14 12:28:41 +00:00
xo
xohtml
xolint
xopo
xstr
xz
xzdec
yacc
yes
ypcat
ypmatch
ypwhich
zstd
Makefile lastcomm(1): Only install if MK_ACCT is on 2021-02-06 20:41:39 +01:00
Makefile.amd64
Makefile.arm
Makefile.i386
Makefile.inc
Makefile.powerpc