Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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@
  • Loading branch information...
commit 7d496117dea8d904a26adf1e120c539fa8c9e99f 1 parent 7e3ca73
Otto Moerbeek authored committed
Showing with 15 additions and 3 deletions.
  1. +15 −3 grep.c
View
18 grep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.c,v 1.33 2005/04/03 19:18:33 jaredy Exp $ */
+/* $OpenBSD: grep.c,v 1.34 2006/02/09 09:54:46 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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.