summaryrefslogtreecommitdiff
path: root/usr.bin/grep
AgeCommit message (Collapse)Author
2023-11-15procline: only reduce mcount once per line, not once per match.Todd C. Miller
This makes "grep -m" behave like GNU grep (where the -m option originated). From Crystal Kolipe.
2023-01-04- use Fl instead of Ar for print0; from josiah frentsosJason McIntyre
- while here, describe it as a primary rather than an option
2022-07-12grep: simplify printline, no functional changesOmar Polo
in the previous revision (1.66) I added an extra variable to track wether we have printed the separator or not. Well, that's what the `n' variable is for, so no need to duplicate the logic.
2022-06-26add --null to usage() forgot in previous commit. reminded by jmc@, thanks!op
2022-06-26grep: add --null flagop
makes grep print an ASCII NUL byte after the file name to make the output unambiguous even in the presence of file names with funny characters. A previous iteration of this diff was improved by benno@ and tedu@ and discussed also with sthen@ and deraadt@. deraadt@ also improved the manpage changes in this version of the diff. OK deraadt@
2022-05-30grep(1): print full context when using match countDave Voutila
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@
2021-12-28Fix printing of -- marker when using -A as noted by gnezdo@Otto Moerbeek
ok millert@
2021-12-15grep: Add missing unistd.h and limits.h includesTheo Buehler
Both binary.c and file.c currently pull in unistd.h via zlib's zconf.h. binary.c uses SEEK_SET and file.c a bunch of things like close(), isatty(), lseek(). In addition file.c needs limits.h for PATH_MAX. ok deraadt
2021-03-10zlib functions take a gzFile not gzFile * (gzFile is already a pointer).Todd C. Miller
From Josh Rickmar.
2020-07-23Change line counter from int to unsigned long long to reduce overflow.Martijn van Duren
In case unsigned long long is miraculously still too small add an additional overflow detection so we stop counting and add a marker to couter output. Input on earlier diff guenther@ OK millert
2019-12-03With -R and an implicit ".", don't prepend file paths with "./"Jeremie Courreges-Anglas
Looks nicer and matches the output of GNU grep. ok millert@ deraadt@ visa@ miod@
2019-12-03Document implicit "." default file for -Rkn
OK visa deraadt
2019-12-02With -R assume that "." was passed instead of printing a warningJeremie Courreges-Anglas
Saner default behavior that matches GNU grep. Diff from miod@, support from espie@, ok visa@ millert@
2019-10-07jmc is a stickler for consistency.Ted Unangst
2019-10-07add --label to usage. thx jmcTed Unangst
2019-10-07two compat features to allow the zstdgrep script to work.Ted Unangst
add --label option to prefix the output instead of filename. allow using - to mean stdin. ok deraadt
2019-07-18Delete documentation of --max-count, which is merely an alias ofIngo Schwarze
the documented -m. As a rule, we only document long options when users can't avoid them because they lack a short version. As suggested by tedu@, as an exception, leave --context documented because -C is awkward in so far as it takes an optional option argument, which is fragile and error-prone and hence generally discouraged, including by POSIX. Two years ago, kettenis@, deraadt@, and tedu@ all agreed that this is what should be done, and jmc@ was happy to accept the direction, but somehow everybody forgot to commit.
2019-07-17when combining -o and -b, print the byte offset of the pattern, not line.Ted Unangst
originally from chrisz
2019-01-31convert fgetln to getline. this improves portability and sets a goodTed Unangst
better example for other code to follow. in the common case, grep uses mmap anyway (so no functional change). despite fgetln doing sneaky things with stdio internals, preliminary analysis by lauri suggests this may actually reduce the number of allocations. from Lauri Tirkkonen.
2019-01-27mmap support was broken in previous submitted diff from lauri tirkkonenTheo de Raadt
2019-01-23rework grep_open to be more careful about directories.Ted Unangst
cleaner, but should be no functional change. from Lauri Tirkkonen
2017-12-10- add max-count to SYNOPSISJason McIntyre
- list long options with short, where they have an equivalent - sync usage() - minor tweaks
2017-12-09Add support for the non-standard grep -m extension.Paul Irofti
grep -m num stops after a maximum of num matches are found. We support -m0 to match GNU behaviour, but we do not allow negative numbers. Manpage help from jmc@, OK deraadt@.
2017-04-03initialize regmatch_t always, fixes grep -o ""Ted Unangst
from Michael Santos
2016-08-25when using -o, we may restart a match in the middle of the line.Ted Unangst
set NOTBOL so that anchored patterns don't match. from a patch by Daniël de Kok in freebsd bug 201650 ok martijn
2016-04-04Reverse search optimization makes no sense (and doesn't work) ifOtto Moerbeek
we are looking for all matches in a line; ok natano@ miilert@ tedu@
2016-03-30for some time now mandoc has not required MLINKS to functionJason McIntyre
correctly - logically complete that now by removing MLINKS from base; authors need only to ensure there is an entry in NAME for any function/ util being added. MLINKS will still work, and remain for perl to ease upgrades; ok nicm (curses) bcook (ssl) ok schwarze, who provided a lot of feedback and assistance ok tb natano jung
2015-12-22cast toupper's argument to unsigned charmmcc
ok millert@
2015-12-22The loop index in grep_cmp() should be size_t to match the type ofTodd C. Miller
the length parameter. The return value of grep_cmp() is only used in a boolean context so make it return bool instead of the index. OK mmcc@
2015-12-14Use long long rather than off_t for line_no to ensure that it's alwaysmmcc
64 bits. ok kettenis@
2015-12-07Represent line numbers with off_t rather than int. This preventsmmcc
overflow on huge inputs. ok millert@, deraadt@
2015-11-28fix exit status on pledge(2) error, where it should be >1Gleydson Soares
OK millert@ deraadt@
2015-10-09Change all tame callers to namechange to pledge(2).Theo de Raadt
2015-10-03grep only opens files read-only, reads via stdio or other methods, performsTheo de Raadt
computation, and outputs result to stdout. (note: in the tame model, malloc is implicit because stdio needs it, and mmap is implicit since malloc needs it; libz is satisfied by this environment also). this tame change consists of 1 line, setting "stdio rpath" before getopt. this protection is fairly strict. grep could be improved further by computing a wpathlist based on argv, keeping -R in mind. feel free to take a shot at it. grep was an early target of capsicum also. know anyone running capsicum grep? ok doug
2015-08-27use strtonum to parse the number of lines of context.David Gwynne
this provides better error messages. ok deraadt@ guenther@
2015-06-25Put fts_close() where missing.Masao Uebayashi
Not bugs in short-lived commands that call exit() -> _exit() immediately, but for idempotency. Originally found in ls(1) by Valgrind. Changes for other commands are from deraadt@. Reviewed by me, tested in snapshots. OK deraadt@
2015-04-30Add warning when user specifies -R but no files, like GNU grep.Todd C. Miller
OK schwarze@ ian@
2015-03-16Don't include limits.h or sys/limits.h since grep.h already does itTodd C. Miller
for us.
2015-03-16Include limits.h, not sys/limits.h and include stdint.h for SIZE_MAX.Todd C. Miller
2015-02-06SIZE_MAX is standard, we should be using it in preference to theTodd C. Miller
obsolete SIZE_T_MAX. OK miod@ beck@
2015-01-16Replace <sys/param.h> with <limits.h> and other less dirty headers whereTheo de Raadt
possible. Annotate <sys/param.h> lines with their current reasons. Switch to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where sensible to avoid pulling in the pollution. These are the files confirmed through binary verification. ok guenther, millert, doug (helped with the verification protocol)
2015-01-13An article on medium.com highlighted that grepDaniel Dickman
was available in v4. To quote Ken Thompson, grep appeared "sometime before the 4th edition." ok schwarze@
2015-01-101. They're flags, not counters. Set to one instead of incrementing.Ted Unangst
2. The G flag is useless and never checked. Remove it. ok millert
2014-12-01use reallocarray()Theo de Raadt
2014-11-26Prefer setvbuf() to setlinebuf() for portability; ok deraadt@Todd C. Miller
2014-11-26Make option string/struct const (since it is...). I've had thisTodd C. Miller
in my tree for ages.
2014-11-08Check the mode flag being passed in to mmopen() instead of ignoring it.Brad Smith
Pointed out by LLVM. mmfile.c:51:7: warning: explicitly assigning a variable of type 'char *' to itself [-Wself-assign] ok millert@
2014-05-20Use errc/warnc to simplify code.Philip Guenther
Also, in 'ftp', always put the error message last, after the hostname/ipaddr. ok jsing@ krw@ millert@
2013-11-26unsigned char casts for ctypeTheo de Raadt
ok krw
2013-11-12simple prototype repairsTheo de Raadt