From cdd815ccd41f1b1eca11b80ee5fd1e51be894e49 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 7 Mar 2006 20:59:57 +0000 Subject: 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@ --- usr.bin/grep/grep.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'usr.bin/grep') 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 @@ -203,6 +203,18 @@ add_pattern(char *pat, size_t len) ++patterns; } +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) { @@ -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; } -- cgit v1.2.3