summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin
diff options
context:
space:
mode:
authorwosch <wosch@FreeBSD.org>1996-09-27 19:44:46 +0000
committerwosch <wosch@FreeBSD.org>1996-09-27 19:44:46 +0000
commit75b1ede7c4efa5dab928435c5a17025962763a6d (patch)
treec7ceea5562d06dba74895dc5fb62b189fa29310d /gnu/usr.bin
parent5b3a6e6fa1d4ca3a20d7ca5f895760f15b15e389 (diff)
downloadFreeBSD-src-75b1ede7c4efa5dab928435c5a17025962763a6d.zip
FreeBSD-src-75b1ede7c4efa5dab928435c5a17025962763a6d.tar.gz
grep -q pattern file
search 'pattern' in whole file 'file', from top to bottom. This is not necessary; if grep found 'pattern' it can stop further searching in file 'file'. Example: $ time ./grep-old -q Adam /usr/share/dict/* 1.93 real 1.05 user 0.85 sys $ time ./grep-new -q Adam /usr/share/dict/* 0.14 real 0.06 user 0.06 sys
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r--gnu/usr.bin/grep/grep.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/gnu/usr.bin/grep/grep.c b/gnu/usr.bin/grep/grep.c
index ae30167..0353e26 100644
--- a/gnu/usr.bin/grep/grep.c
+++ b/gnu/usr.bin/grep/grep.c
@@ -343,6 +343,7 @@ static int out_line; /* Print line numbers. */
static int out_byte; /* Print byte offsets. */
static int out_before; /* Lines of leading context. */
static int out_after; /* Lines of trailing context. */
+static int count_matches; /* print a count of matching lines */
/* Internal variables to keep track of byte count, context, etc. */
static size_t totalcc; /* Total character count before bufbeg. */
@@ -589,6 +590,9 @@ grep(fd)
nlines += grepbuf(beg, lim);
if (pending)
prpending(lim);
+ /* optimization */
+ if (nlines && out_quiet && !count_matches)
+ return(nlines);
}
i = 0;
beg = lim;
@@ -659,7 +663,7 @@ main(argc, argv)
{
char *keys;
size_t keycc, oldcc, keyalloc;
- int keyfound, count_matches, no_filenames, list_files, suppress_errors;
+ int keyfound, no_filenames, list_files, suppress_errors;
int opt, cc, desc, count, status;
FILE *fp;
extern char *optarg;
OpenPOWER on IntegriCloud