Deleted Added
full compact
2c2
< /* $FreeBSD: head/usr.bin/grep/util.c 224938 2011-08-17 13:58:39Z gabor $ */
---
> /* $FreeBSD: head/usr.bin/grep/util.c 226035 2011-10-05 09:56:43Z gabor $ */
33c33
< __FBSDID("$FreeBSD: head/usr.bin/grep/util.c 224938 2011-08-17 13:58:39Z gabor $");
---
> __FBSDID("$FreeBSD: head/usr.bin/grep/util.c 226035 2011-10-05 09:56:43Z gabor $");
51a52
> #include "fastmatch.h"
235,241c236,237
<
< /* Count the matches if we have a match limit */
< if (mflag) {
< mcount -= t;
< if (mcount <= 0)
< break;
< }
---
> if (mflag && mcount < 0)
> break;
283,287c279,282
< if (!matchall) {
< /* Loop to process the whole line */
< while (st <= l->len) {
< pmatch.rm_so = st;
< pmatch.rm_eo = l->len;
---
> /* Loop to process the whole line */
> while (st <= l->len) {
> pmatch.rm_so = st;
> pmatch.rm_eo = l->len;
289,315c284,305
< /* Loop to compare with all the patterns */
< for (i = 0; i < patterns; i++) {
< /*
< * XXX: grep_search() is a workaround for speed up and should be
< * removed in the future. See fastgrep.c.
< */
< if (fg_pattern[i].pattern)
< r = grep_search(&fg_pattern[i],
< (unsigned char *)l->dat,
< l->len, &pmatch);
< else
< r = regexec(&r_pattern[i], l->dat, 1,
< &pmatch, eflags);
< r = (r == 0) ? 0 : REG_NOMATCH;
< st = (cflags & REG_NOSUB)
< ? (size_t)l->len
< : (size_t)pmatch.rm_eo;
< if (r == REG_NOMATCH)
< continue;
< /* Check for full match */
< if (r == 0 && xflag)
< if (pmatch.rm_so != 0 ||
< (size_t)pmatch.rm_eo != l->len)
< r = REG_NOMATCH;
< /* Check for whole word match */
< if (r == 0 && (wflag || fg_pattern[i].word)) {
< wint_t wbegin, wend;
---
> /* Loop to compare with all the patterns */
> for (i = 0; i < patterns; i++) {
> if (fg_pattern[i].pattern)
> r = fastexec(&fg_pattern[i],
> l->dat, 1, &pmatch, eflags);
> else
> r = regexec(&r_pattern[i], l->dat, 1,
> &pmatch, eflags);
> r = (r == 0) ? 0 : REG_NOMATCH;
> st = (cflags & REG_NOSUB)
> ? (size_t)l->len
> : (size_t)pmatch.rm_eo;
> if (r == REG_NOMATCH)
> continue;
> /* Check for full match */
> if (r == 0 && xflag)
> if (pmatch.rm_so != 0 ||
> (size_t)pmatch.rm_eo != l->len)
> r = REG_NOMATCH;
> /* Check for whole word match */
> if (r == 0 && (wflag || fg_pattern[i].word)) {
> wint_t wbegin, wend;
317,340c307,319
< wbegin = wend = L' ';
< if (pmatch.rm_so != 0 &&
< sscanf(&l->dat[pmatch.rm_so - 1],
< "%lc", &wbegin) != 1)
< r = REG_NOMATCH;
< 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))
< r = REG_NOMATCH;
< }
< if (r == 0) {
< if (m == 0)
< c++;
< if (m < MAX_LINE_MATCHES)
< matches[m++] = pmatch;
< /* matches - skip further patterns */
< if ((color == NULL && !oflag) ||
< qflag || lflag)
< break;
< }
---
> wbegin = wend = L' ';
> if (pmatch.rm_so != 0 &&
> sscanf(&l->dat[pmatch.rm_so - 1],
> "%lc", &wbegin) != 1)
> r = REG_NOMATCH;
> 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))
> r = REG_NOMATCH;
342,345c321,329
<
< if (vflag) {
< c = !c;
< break;
---
> if (r == 0) {
> if (m == 0)
> c++;
> if (m < MAX_LINE_MATCHES)
> matches[m++] = pmatch;
> /* matches - skip further patterns */
> if ((color == NULL && !oflag) ||
> qflag || lflag)
> break;
347,349c331
< /* One pass if we are not recording matches */
< if ((color == NULL && !oflag) || qflag || lflag)
< break;
---
> }
351,352c333,335
< if (st == (size_t)pmatch.rm_so)
< break; /* No matches */
---
> if (vflag) {
> c = !c;
> break;
354,355d336
< } else
< c = !vflag;
356a338,350
> /* One pass if we are not recording matches */
> if ((color == NULL && !oflag) || qflag || lflag)
> break;
>
> if (st == (size_t)pmatch.rm_so)
> break; /* No matches */
> }
>
>
> /* Count the matches if we have a match limit */
> if (mflag)
> mcount -= c;
>