diff options
-rw-r--r-- | usr.bin/grep/grep.c | 13 | ||||
-rw-r--r-- | usr.bin/grep/util.c | 6 |
2 files changed, 13 insertions, 6 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 6e6a8cf6126..6c82ef40891 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.25 2004/01/25 21:36:00 millert Exp $ */ +/* $OpenBSD: grep.c,v 1.26 2004/02/04 18:38:52 millert Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -174,9 +174,16 @@ add_pattern(char *pat, size_t len) --len; /* pat may not be NUL-terminated */ if (wflag) { + int bol = 0, eol = 0; + if (pat[0] == '^') + bol = 1; + if (pat[len - 1] == '$') + eol = 1; pattern[patterns] = grep_malloc(len + 15); - snprintf(pattern[patterns], len + 15, "[[:<:]]%.*s[[:>:]]", - (int)len, pat); + snprintf(pattern[patterns], len + 15, "%s[[:<:]]%.*s[[:>:]]%s", + bol ? "^" : "", (int)len - bol - eol, pat + bol, + eol ? "$" : ""); + len += 14; } else { pattern[patterns] = grep_malloc(len + 1); memcpy(pattern[patterns], pat, len); diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index b0d96f31c17..824ff077bfb 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.23 2004/01/26 14:50:29 millert Exp $ */ +/* $OpenBSD: util.c,v 1.24 2004/02/04 18:38:52 millert Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -266,9 +266,9 @@ fastcomp(fastgrep_t *fg, const char *pattern) } /* Remove enclosing [[:<:]] and [[:>:]] (word match). */ - if (fg->patternLen > 14 + fg->bol + fg->eol && + if (fg->patternLen >= 14 && strncmp(pattern + fg->bol, "[[:<:]]", 7) == 0 && - strncmp(pattern + fg->patternLen - (7 + fg->eol), "[[:>:]]", 7) == 0) { + strncmp(pattern + fg->bol + fg->patternLen - 7, "[[:>:]]", 7) == 0) { fg->patternLen -= 14; fg->wmatch = 7; } |