summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep
diff options
context:
space:
mode:
authorgabor <gabor@FreeBSD.org>2011-06-12 12:44:02 +0000
committergabor <gabor@FreeBSD.org>2011-06-12 12:44:02 +0000
commitaf29896fe7cc22ecf57aac71fa6cf8fac9c32449 (patch)
treee3d6d690c87df7e9d8599e35bb6cb13fe825fd85 /usr.bin/grep
parent5f34a4c1c49bd32e09046627552c249a770ebbce (diff)
downloadFreeBSD-src-af29896fe7cc22ecf57aac71fa6cf8fac9c32449.zip
FreeBSD-src-af29896fe7cc22ecf57aac71fa6cf8fac9c32449.tar.gz
- Fix -w behavior
- Make -F and -w work together - Fix --color to colorize all of the matches PR: bin/156826 Submitted by: Yuri Pankov <yuri.pankov@gmail.com> Approved by: delphij (mentor)
Diffstat (limited to 'usr.bin/grep')
-rw-r--r--usr.bin/grep/fastgrep.c2
-rw-r--r--usr.bin/grep/util.c25
2 files changed, 13 insertions, 14 deletions
diff --git a/usr.bin/grep/fastgrep.c b/usr.bin/grep/fastgrep.c
index d5c9d31..bc8a3af 100644
--- a/usr.bin/grep/fastgrep.c
+++ b/usr.bin/grep/fastgrep.c
@@ -89,7 +89,7 @@ fastcomp(fastgrep_t *fg, const char *pat)
fg->bol = false;
fg->eol = false;
fg->reversed = false;
- fg->word = wflag;
+ fg->word = false;
/* Remove end-of-line character ('$'). */
if (fg->len > 0 && pat[fg->len - 1] == '$') {
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index dece127..758270d 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -301,18 +301,15 @@ procline(struct str *l, int nottext)
* XXX: grep_search() is a workaround for speed up and should be
* removed in the future. See fastgrep.c.
*/
- if (fg_pattern[i].pattern) {
+ if (fg_pattern[i].pattern)
r = grep_search(&fg_pattern[i],
(unsigned char *)l->dat,
l->len, &pmatch);
- r = (r == 0) ? 0 : REG_NOMATCH;
- st = pmatch.rm_eo;
- } else {
+ else
r = regexec(&r_pattern[i], l->dat, 1,
&pmatch, eflags);
- r = (r == 0) ? 0 : REG_NOMATCH;
- st = pmatch.rm_eo;
- }
+ r = (r == 0) ? 0 : REG_NOMATCH;
+ st = pmatch.rm_eo;
if (r == REG_NOMATCH)
continue;
/* Check for full match */
@@ -321,8 +318,7 @@ procline(struct str *l, int nottext)
(size_t)pmatch.rm_eo != l->len)
r = REG_NOMATCH;
/* Check for whole word match */
- if (r == 0 && fg_pattern[i].word &&
- pmatch.rm_so != 0) {
+ if (r == 0 && (wflag || fg_pattern[i].word)) {
wint_t wbegin, wend;
wbegin = wend = L' ';
@@ -330,11 +326,13 @@ procline(struct str *l, int nottext)
sscanf(&l->dat[pmatch.rm_so - 1],
"%lc", &wbegin) != 1)
r = REG_NOMATCH;
- else if ((size_t)pmatch.rm_eo != l->len &&
+ else if ((size_t)pmatch.rm_eo !=
+ l->len &&
sscanf(&l->dat[pmatch.rm_eo],
"%lc", &wend) != 1)
r = REG_NOMATCH;
- else if (iswword(wbegin) || iswword(wend))
+ else if (iswword(wbegin) ||
+ iswword(wend))
r = REG_NOMATCH;
}
if (r == 0) {
@@ -343,7 +341,8 @@ procline(struct str *l, int nottext)
if (m < MAX_LINE_MATCHES)
matches[m++] = pmatch;
/* matches - skip further patterns */
- if ((color != NULL && !oflag) || qflag || lflag)
+ if ((color == NULL && !oflag) ||
+ qflag || lflag)
break;
}
}
@@ -353,7 +352,7 @@ procline(struct str *l, int nottext)
break;
}
/* One pass if we are not recording matches */
- if ((color != NULL && !oflag) || qflag || lflag)
+ if ((color == NULL && !oflag) || qflag || lflag)
break;
if (st == (size_t)pmatch.rm_so)
OpenPOWER on IntegriCloud