summaryrefslogtreecommitdiff
path: root/usr.bin/grep/util.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-05-07 19:07:00 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-05-07 19:07:00 +0000
commit6fc86aa950e91afb7752710554577d8c1c798b07 (patch)
tree9f7af63df097846045ecf8732cd925ba963794e4 /usr.bin/grep/util.c
parent1f52be7ba110744f0694dbb08768efcffa8c8910 (diff)
Make grep -w behave the same for the fastcomp and the regex case,
by teaching fastcomp what word boundaries are according to regex. ok millert@
Diffstat (limited to 'usr.bin/grep/util.c')
-rw-r--r--usr.bin/grep/util.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 9e8fff9aea7..c0a019197a7 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.25 2004/05/07 14:51:42 millert Exp $ */
+/* $OpenBSD: util.c,v 1.26 2004/05/07 19:06:59 otto Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -412,8 +412,16 @@ fastcomp(fastgrep_t *fg, const char *pattern)
return (0);
}
+/*
+ * Word boundaries using regular expressions are defined as the point
+ * of transition from a non-word char to a word char, or vice versa.
+ * This means that grep -w +a and grep -w a+ never match anything,
+ * because they lack a starting or ending transition, but grep -w a+b
+ * does match a line containing a+b.
+ */
#define wmatch(d, l, s, e) \
- ((s == 0 || !isword(d[s-1])) && (e == l || !isword(d[e])))
+ ((s == 0 || !isword(d[s-1])) && (e == l || !isword(d[e])) && \
+ e > s && isword(d[s]) && isword(d[e-1]))
static int
grep_search(fastgrep_t *fg, unsigned char *data, size_t dataLen, regmatch_t *pmatch)