diff options
author | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-04-03 19:18:34 +0000 |
---|---|---|
committer | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-04-03 19:18:34 +0000 |
commit | 5ce55a1aa8032e2c661665ee5b384c195b0ea87b (patch) | |
tree | 19135a2b23b7abeaf857337dce33d49d72122d8b /usr.bin/grep/grep.c | |
parent | fbf0d37c9a2047d9c4d607bf2b2f73055c912f3c (diff) |
Make the processing of patterns collected from files specified by -f
delayed so options that affect pattern-building (such as -w) can be
applied evenly to all such patterns.
ok and help otto, ok millert
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r-- | usr.bin/grep/grep.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 4c64b94afe5..0a90cd39578 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.32 2005/04/03 19:12:40 otto Exp $ */ +/* $OpenBSD: grep.c,v 1.33 2005/04/03 19:18:33 jaredy Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -29,6 +29,7 @@ #include <sys/types.h> #include <sys/limits.h> #include <sys/stat.h> +#include <sys/queue.h> #include <ctype.h> #include <err.h> @@ -98,6 +99,12 @@ int first; /* flag whether or not this is our first match */ int tail; /* lines left to print */ int lead; /* number of lines in leading context queue */ +struct patfile { + const char *pf_file; + SLIST_ENTRY(patfile) pf_next; +}; +SLIST_HEAD(, patfile) patfilelh; + extern char *__progname; static void @@ -199,7 +206,7 @@ add_pattern(char *pat, size_t len) } static void -read_patterns(char *fn) +read_patterns(const char *fn) { FILE *f; char *line; @@ -230,9 +237,11 @@ int main(int argc, char *argv[]) { int c, lastc, prevoptind, newarg, i; + struct patfile *patfile, *pf_next; long l; char *ep; + SLIST_INIT(&patfilelh); switch (__progname[0]) { case 'e': Eflag++; @@ -355,7 +364,9 @@ main(int argc, char *argv[]) add_pattern(optarg, strlen(optarg)); break; case 'f': - read_patterns(optarg); + patfile = grep_malloc(sizeof(*patfile)); + patfile->pf_file = optarg; + SLIST_INSERT_HEAD(&patfilelh, patfile, pf_next); break; case 'h': oflag = 0; @@ -420,6 +431,13 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + for (patfile = SLIST_FIRST(&patfilelh); patfile != NULL; + patfile = pf_next) { + pf_next = SLIST_NEXT(patfile, pf_next); + read_patterns(patfile->pf_file); + free(patfile); + } + if (argc == 0 && patterns == 0) usage(); |