Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/grep If transforming patterns with \<...\> to implic...



details:   https://anonhg.NetBSD.org/src/rev/1819d1eaffca
branches:  trunk
changeset: 762764:1819d1eaffca
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sun Feb 27 17:33:37 2011 +0000

description:
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.

diffstat:

 usr.bin/grep/fastgrep.c |  5 +++--
 usr.bin/grep/grep.h     |  3 ++-
 usr.bin/grep/util.c     |  7 ++++---
 3 files changed, 9 insertions(+), 6 deletions(-)

diffs (74 lines):

diff -r fec6b8596596 -r 1819d1eaffca usr.bin/grep/fastgrep.c
--- a/usr.bin/grep/fastgrep.c   Sun Feb 27 17:31:08 2011 +0000
+++ b/usr.bin/grep/fastgrep.c   Sun Feb 27 17:33:37 2011 +0000
@@ -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;
        }
 
        /*
diff -r fec6b8596596 -r 1819d1eaffca usr.bin/grep/grep.h
--- a/usr.bin/grep/grep.h       Sun Feb 27 17:31:08 2011 +0000
+++ b/usr.bin/grep/grep.h       Sun Feb 27 17:33:37 2011 +0000
@@ -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() */
diff -r fec6b8596596 -r 1819d1eaffca usr.bin/grep/util.c
--- a/usr.bin/grep/util.c       Sun Feb 27 17:31:08 2011 +0000
+++ b/usr.bin/grep/util.c       Sun Feb 27 17:33:37 2011 +0000
@@ -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' ';



Home | Main Index | Thread Index | Old Index