diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-03-07 20:59:57 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-03-07 20:59:57 +0000 |
commit | cdd815ccd41f1b1eca11b80ee5fd1e51be894e49 (patch) | |
tree | b1fc1c37ecfb85c0092b52304abbd180e05bda24 | |
parent | ea22a29567439182b87eee29574320ed4cb57bce (diff) |
Break patterns containing newlines into multiple patterns like POSIX says.
Report by Ralf dot Wildenhues at gmx dot de;
testing by jmc@ ok beck@ millert@
-rw-r--r-- | usr.bin/grep/grep.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index eedc610ba94..70d8dff38e7 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.34 2006/02/09 09:54:46 otto Exp $ */ +/* $OpenBSD: grep.c,v 1.35 2006/03/07 20:59:56 otto Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -204,6 +204,18 @@ add_pattern(char *pat, size_t len) } static void +add_patterns(char *pats) +{ + char *nl; + + while ((nl = strchr(pats, '\n')) != NULL) { + add_pattern(pats, nl - pats); + pats = nl + 1; + } + add_pattern(pats, strlen(pats)); +} + +static void read_patterns(const char *fn) { FILE *f; @@ -359,7 +371,7 @@ main(int argc, char *argv[]) cflag = 1; break; case 'e': - add_pattern(optarg, strlen(optarg)); + add_patterns(optarg); break; case 'f': patfile = grep_malloc(sizeof(*patfile)); @@ -440,7 +452,7 @@ main(int argc, char *argv[]) usage(); if (patterns == 0) { - add_pattern(*argv, strlen(*argv)); + add_patterns(*argv); --argc; ++argv; } |