=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/grep/grep.c,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- src/usr.bin/grep/grep.c 2005/04/03 19:12:40 1.32 +++ src/usr.bin/grep/grep.c 2005/04/03 19:18:33 1.33 @@ -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 #include #include +#include #include #include @@ -98,6 +99,12 @@ 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 @@ } static void -read_patterns(char *fn) +read_patterns(const char *fn) { FILE *f; char *line; @@ -230,9 +237,11 @@ 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 @@ 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; @@ -419,6 +430,13 @@ } 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();