Module Name:    src
Committed By:   joerg
Date:           Sun Feb 27 17:33:37 UTC 2011

Modified Files:
        src/usr.bin/grep: fastgrep.c grep.h util.c

Log Message:
If transforming patterns with \<...\> to implicit word bounaries, don't
change the global wflag, but use a per pattern flag derived from it.
Fixes usage of grep with multiple -w arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/grep/fastgrep.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/grep/grep.h
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/grep/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/grep/fastgrep.c
diff -u src/usr.bin/grep/fastgrep.c:1.3 src/usr.bin/grep/fastgrep.c:1.4
--- src/usr.bin/grep/fastgrep.c:1.3	Thu Feb 17 22:03:25 2011
+++ src/usr.bin/grep/fastgrep.c	Sun Feb 27 17:33:37 2011
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fastgrep.c,v 1.3 2011/02/17 22:03:25 joerg Exp $");
+__RCSID("$NetBSD: fastgrep.c,v 1.4 2011/02/27 17:33:37 joerg Exp $");
 
 #include <limits.h>
 #include <stdbool.h>
@@ -88,6 +88,7 @@
 	fg->bol = false;
 	fg->eol = false;
 	fg->reversed = false;
+	fg->word = wflag;
 
 	/* Remove end-of-line character ('$'). */
 	if (fg->len > 0 && pat[fg->len - 1] == '$') {
@@ -108,7 +109,7 @@
 		fg->len -= 14;
 		pat += 7;
 		/* Word boundary is handled separately in util.c */
-		wflag = true;
+		fg->word = true;
 	}
 
 	/*

Index: src/usr.bin/grep/grep.h
diff -u src/usr.bin/grep/grep.h:1.4 src/usr.bin/grep/grep.h:1.5
--- src/usr.bin/grep/grep.h:1.4	Wed Feb 16 01:31:33 2011
+++ src/usr.bin/grep/grep.h	Sun Feb 27 17:33:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: grep.h,v 1.4 2011/02/16 01:31:33 joerg Exp $	*/
+/*	$NetBSD: grep.h,v 1.5 2011/02/27 17:33:37 joerg Exp $	*/
 /*	$OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $	*/
 /*	$FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $	*/
 
@@ -103,6 +103,7 @@
 	bool		 bol;
 	bool		 eol;
 	bool		 reversed;
+	bool		 word;
 } fastgrep_t;
 
 /* Flags passed to regcomp() and regexec() */

Index: src/usr.bin/grep/util.c
diff -u src/usr.bin/grep/util.c:1.8 src/usr.bin/grep/util.c:1.9
--- src/usr.bin/grep/util.c:1.8	Wed Feb 16 18:35:39 2011
+++ src/usr.bin/grep/util.c	Sun Feb 27 17:33:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.8 2011/02/16 18:35:39 joerg Exp $	*/
+/*	$NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $	*/
 /*	$FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $	*/
 /*	$OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $	*/
 
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: util.c,v 1.8 2011/02/16 18:35:39 joerg Exp $");
+__RCSID("$NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -323,7 +323,8 @@
 					    (size_t)pmatch.rm_eo != l->len)
 						r = REG_NOMATCH;
 				/* Check for whole word match */
-				if (r == 0 && wflag && pmatch.rm_so != 0) {
+				if (r == 0 && fg_pattern[i].word &&
+				    pmatch.rm_so != 0) {
 					wint_t wbegin, wend;
 
 					wbegin = wend = L' ';

Reply via email to