summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep/grep.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* convert fgetln to getline. this improves portability and sets a goodtedu2019-01-311-3/+7
| | | | | | | | 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.
* rework grep_open to be more careful about directories.tedu2019-01-231-3/+1
| | | | | cleaner, but should be no functional change. from Lauri Tirkkonen
* - add max-count to SYNOPSISjmc2017-12-101-5/+6
| | | | | | - list long options with short, where they have an equivalent - sync usage() - minor tweaks
* Add support for the non-standard grep -m extension.pirofti2017-12-091-5/+18
| | | | | | | | 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@.
* fix exit status on pledge(2) error, where it should be >1gsoares2015-11-281-2/+2
| | | | OK millert@ deraadt@
* Change all tame callers to namechange to pledge(2).deraadt2015-10-091-3/+3
|
* grep only opens files read-only, reads via stdio or other methods, performsderaadt2015-10-031-1/+4
| | | | | | | | | | | | | | | 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
* use strtonum to parse the number of lines of context.dlg2015-08-271-10/+9
| | | | | | this provides better error messages. ok deraadt@ guenther@
* Add warning when user specifies -R but no files, like GNU grep.millert2015-04-301-1/+3
| | | | OK schwarze@ ian@
* Don't include limits.h or sys/limits.h since grep.h already does itmillert2015-03-161-2/+1
| | | | for us.
* 1. They're flags, not counters. Set to one instead of incrementing.tedu2015-01-101-21/+13
| | | | | 2. The G flag is useless and never checked. Remove it. ok millert
* use reallocarray()deraadt2014-12-011-3/+4
|
* Prefer setvbuf() to setlinebuf() for portability; ok deraadt@millert2014-11-261-2/+2
|
* Make option string/struct const (since it is...). I've had thismillert2014-11-261-4/+4
| | | | in my tree for ages.
* Fix exit status when there is an error reading a file.millert2012-12-291-2/+3
| | | | | Reported by Jeramey Crawford, fix adapted from FreeBSD. OK guenther@
* add support for -o to only print the match.tedu2011-07-081-5/+9
| | | | reminded this was useful by ajcoutot
* add -H (opposite of -h) to always print name. ok deraadt millerttedu2011-03-041-6/+11
|
* Remove the "fast" grep code if SMALL. This has the side effect of breakingtedu2010-07-021-2/+12
| | | | fgrep -w, but oh well. ok deraadt millert
* Fix "grep -e foo -w" crash. The problem lies in 'e' getopt clausejacekm2010-04-201-4/+17
| | | | | | | calling add_pattern, which in turn assumes that the getopt phase has already finished. OK otto@
* remove some non-POSIX standard non-GNU defacto standard options, mostlytedu2010-04-051-25/+6
| | | | | relating to symlinks that you can get with find. And a bonus fts flag fix. With a small tweak by guenther. ok deraadt guenther jmc millert nicm
* use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsgderaadt2007-09-021-3/+3
|
* - Be explicit on command line checking, instead of relying on patterns,kili2007-02-131-18/+9
| | | | | | | | | | | | | | | | which may be NULL (e.g. -e ''). - let add_pattern() decide how to deal with empty patterns, don't do magic in read_patterns(). This unbreaks stuff like grep -e '', and makes grep -f <file> more POSIX compliant. Semantics for grep -f /dev/null (or any other empty file) may be questionable, but this case isn't specified by POSIX, and matching nothing at all seems to be sane. Thanks to otto@, who mentioned potential problems related to the -x option with the first patch i sent. ok jaredy@ (some time ago), otto@, millert@
* Check length before checking index of len - 1.ray2006-11-021-2/+2
| | | | OK moritz@.
* Allow zero-length patterns with -x sojaredy2006-09-261-3/+3
| | | | | | | | | | $ grep -x "" matches empty lines as reported on misc@ by Martin Marusak <marusak@fhpv.unipo.sk>. Initial diff by otto@ with tweaks by me. ok otto
* Break patterns containing newlines into multiple patterns like POSIX says.otto2006-03-071-3/+15
| | | | | Report by Ralf dot Wildenhues at gmx dot de; testing by jmc@ ok beck@ millert@
* delint; remove redundant vars and functions; ok jaredy@otto2006-02-091-3/+1
|
* Make the processing of patterns collected from files specified by -fjaredy2005-04-031-3/+21
| | | | | | | delayed so options that affect pattern-building (such as -w) can be applied evenly to all such patterns. ok and help otto, ok millert
* Protect begin and end of word markers added to the pattern whenotto2005-04-031-6/+11
| | | | | | | using the -w option with parentheses, to avoid operators in the expressions binding to the markers. Compare [[:<:]]foo|bar[[:>:]] and [[:<:]](foo|bar)[[:>:]]. Problem spotted by aaron@; ok millert@ aaron@ jaredy@
* Remove block based mmap optimization. There are newline problemsotto2004-10-031-6/+1
| | | | | | | | | (PR 3940, 3941) which can be fixed, but if a match starts at the end of a block and continues into the next block, no match will be found. Measurements by millert@ showed that the improvements of this optimization are non-measurable anyway. Diff from Alexander Taler. ok millert@
* various fixes to make this page a bit clearer and hopefully a bitjmc2004-09-281-5/+5
| | | | | | more helpful; this includes some ideas/fixes from otto and jared;
* spacingderaadt2004-08-051-2/+2
|
* Add a new past path for fgrep that is just a simplified version ofmillert2004-05-071-31/+14
| | | | | | fastcomp. This makes fgrep faster and fixes the -w flag w/ fgrep. Also remove free_patterns() since calling free right before exit is silly. Problem noticed by espie@
* Implement --line-bufferedotto2004-04-021-3/+12
| | | | ok millert@ tedu@
* Fix anchors (^ or $) in -w mode broken by the last commit's -w overhaul.millert2004-02-041-3/+10
| | | | With this change we pass the updated regress. Tested and OK by ho@
* Previously, in -w mode, for each match on a line grep would checkmillert2004-01-251-4/+10
| | | | | | | | | | | | | | to see if the match was on a word boundary. However, this missed lines where the first match was not on a word boundary but a subsequent match was. Problem originally spotted by miod@ We fix this by using the [[:<:]] and [[:>:]] character classes for the slow path and by checking the word boundaries in grep_search() for the fast path instead of doing the checks after running regexec() or grep_search(). With this change, grep passes the new regress tests 15 and 16. problem originally spotted by espie@.
* Sync usage() with SYNOPSIS in grep(1).mcbride2003-12-111-4/+5
| | | | ok deraadt@ jmc@
* Fix "grep -number" support for multi-digit numbers. At issue ismillert2003-09-071-10/+10
| | | | | | the fact that optind refers to the *next* argument to be consumed by getopt(), not the current one. This means we have to keep track of when we are working with a new argv entry by hand. OK hugh@
* When reallocing pattern, use sizeof(*pattern) not sizeof(int).millert2003-07-161-3/+3
| | | | | Fixes a problem on sparc64 where sizeof(int) != sizeof(pointer). Based on a patch from Brian Poole; tedu@ OK
* range-check numeric arguments (-num, -A num, -B num)millert2003-07-141-8/+22
|
* grep should exit(2) on error, not exit(1) (1 means no matches found).millert2003-07-101-4/+4
| | | | deraadt@ OK
* knfderaadt2003-07-101-33/+33
|
* Fix parsing of -NUMBER. We now do things a digit at a time andmillert2003-07-101-8/+10
| | | | | keep track of what the last char from getopt was as well as the previous value of optind so we know when a new number has started.
* o remove useless cast to int from gzread() callmillert2003-06-251-8/+8
| | | | | o maxPatternLen should be size_t since that's what it is compared against o remove useless casts of NULL to various pointer types
* actually do fgrep. -G -F and -E are now mutally exclusive, and overridetedu2003-06-241-30/+36
| | | | the program name as expected. ok millert@
* strncpy -> memcpy per deraadt suggestion.tedu2003-06-231-2/+3
| | | | also add a note why we can't use strlcpy.
* go back to using strncpy. for long patterns, strlcpy reads too muchtedu2003-06-231-2/+3
| | | | of a potentially nontermined src.
* faster grep for simple patterns. derived from a patch by sean farley.tedu2003-06-231-5/+38
| | | | | this makes searching for constant strings much faster by avoiding regex. ok deraadt@
* minor tweaksderaadt2003-06-231-2/+3
|
* use strlcpy, not strncpy. ok deraadt@ millert@tedu2003-06-231-5/+4
|
* spellingtedu2003-06-231-2/+2
|