[Midnightbsd-cvs] src [8672] trunk/usr.bin/grep/grep.c: fix handling of the case when multipel patterns are specified in a single command line argument separated by newlines

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 16:39:46 EDT 2016


Revision: 8672
          http://svnweb.midnightbsd.org/src/?rev=8672
Author:   laffer1
Date:     2016-09-25 16:39:45 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
fix handling of the case when multipel patterns are specified in a single command line argument separated by newlines

Modified Paths:
--------------
    trunk/usr.bin/grep/grep.c

Modified: trunk/usr.bin/grep/grep.c
===================================================================
--- trunk/usr.bin/grep/grep.c	2016-09-25 20:37:18 UTC (rev 8671)
+++ trunk/usr.bin/grep/grep.c	2016-09-25 20:39:45 UTC (rev 8672)
@@ -477,7 +477,13 @@
 			grepbehave = GREP_EXTENDED;
 			break;
 		case 'e':
-			add_pattern(optarg, strlen(optarg));
+			{
+				char *token;
+				char *string = optarg;
+
+				while ((token = strsep(&string, "\n")) != NULL)
+					add_pattern(token, strlen(token));
+			}
 			needpattern = 0;
 			break;
 		case 'F':
@@ -666,7 +672,11 @@
 
 	/* Process patterns from command line */
 	if (aargc != 0 && needpattern) {
-		add_pattern(*aargv, strlen(*aargv));
+		char *token;
+		char *string = *aargv;
+
+		while ((token = strsep(&string, "\n")) != NULL)
+			add_pattern(token, strlen(token));
 		--aargc;
 		++aargv;
 	}



More information about the Midnightbsd-cvs mailing list