diff options
| author | David E. O'Brien <obrien@FreeBSD.org> | 2000-01-04 03:25:40 +0000 |
|---|---|---|
| committer | David E. O'Brien <obrien@FreeBSD.org> | 2000-01-04 03:25:40 +0000 |
| commit | 7e5b33c6cdd936f5ce4e2fc75f233b566ed12e5f (patch) | |
| tree | 75c822f90c0f870f0f438b7a9838777108ac6432 /gnu/usr.bin/grep/search.c | |
| parent | e3bfb279840328221230244ac81668c55de1635a (diff) | |
Notes
Diffstat (limited to 'gnu/usr.bin/grep/search.c')
| -rw-r--r-- | gnu/usr.bin/grep/search.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/gnu/usr.bin/grep/search.c b/gnu/usr.bin/grep/search.c index a3ca56c399ed..4e3244ae533f 100644 --- a/gnu/usr.bin/grep/search.c +++ b/gnu/usr.bin/grep/search.c @@ -48,7 +48,6 @@ struct matcher matchers[] = { { "default", Gcompile, EGexecute }, { "grep", Gcompile, EGexecute }, { "egrep", Ecompile, EGexecute }, - { "posix-egrep", Ecompile, EGexecute }, { "awk", Ecompile, EGexecute }, { "fgrep", Fcompile, Fexecute }, { 0, 0, 0 }, @@ -61,7 +60,7 @@ struct matcher matchers[] = { static struct dfa dfa; /* Regex compiled regexp. */ -static struct re_pattern_buffer regex; +static struct re_pattern_buffer regexbuf; /* KWset compiled pattern. For Ecompile and Gcompile, we compile a list of strings, at least one of which is known to occur in @@ -140,9 +139,9 @@ Gcompile(pattern, size) const char *err; re_set_syntax(RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE); - dfasyntax(RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE, match_icase); + dfasyntax(RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE, match_icase, eolbyte); - if ((err = re_compile_pattern(pattern, size, ®ex)) != 0) + if ((err = re_compile_pattern(pattern, size, ®exbuf)) != 0) fatal(err, 0); /* In the match_words and match_lines cases, we use a different pattern @@ -155,7 +154,8 @@ Gcompile(pattern, size) (^|[^A-Za-z_])(userpattern)([^A-Za-z_]|$). In the whole-line case, we use the pattern: ^(userpattern)$. - BUG: Using [A-Za-z_] is locale-dependent! */ + BUG: Using [A-Za-z_] is locale-dependent! + So will use [:alnum:] */ char *n = malloc(size + 50); int i = 0; @@ -165,14 +165,14 @@ Gcompile(pattern, size) if (match_lines) strcpy(n, "^\\("); if (match_words) - strcpy(n, "\\(^\\|[^0-9A-Za-z_]\\)\\("); + strcpy(n, "\\(^\\|[^[:alnum:]_]\\)\\("); i = strlen(n); memcpy(n + i, pattern, size); i += size; if (match_words) - strcpy(n + i, "\\)\\([^0-9A-Za-z_]\\|$\\)"); + strcpy(n + i, "\\)\\([^[:alnum:]_]\\|$\\)"); if (match_lines) strcpy(n + i, "\\)$"); @@ -192,23 +192,18 @@ Ecompile(pattern, size) { const char *err; - if (strcmp(matcher, "posix-egrep") == 0) - { - re_set_syntax(RE_SYNTAX_POSIX_EGREP); - dfasyntax(RE_SYNTAX_POSIX_EGREP, match_icase); - } - else if (strcmp(matcher, "awk") == 0) + if (strcmp(matcher, "awk") == 0) { re_set_syntax(RE_SYNTAX_AWK); - dfasyntax(RE_SYNTAX_AWK, match_icase); + dfasyntax(RE_SYNTAX_AWK, match_icase, eolbyte); } else { - re_set_syntax(RE_SYNTAX_EGREP); - dfasyntax(RE_SYNTAX_EGREP, match_icase); + re_set_syntax (RE_SYNTAX_POSIX_EGREP); + dfasyntax (RE_SYNTAX_POSIX_EGREP, match_icase, eolbyte); } - if ((err = re_compile_pattern(pattern, size, ®ex)) != 0) + if ((err = re_compile_pattern(pattern, size, ®exbuf)) != 0) fatal(err, 0); /* In the match_words and match_lines cases, we use a different pattern @@ -221,7 +216,8 @@ Ecompile(pattern, size) (^|[^A-Za-z_])(userpattern)([^A-Za-z_]|$). In the whole-line case, we use the pattern: ^(userpattern)$. - BUG: Using [A-Za-z_] is locale-dependent! */ + BUG: Using [A-Za-z_] is locale-dependent! + so will use the char class */ char *n = malloc(size + 50); int i = 0; @@ -231,14 +227,14 @@ Ecompile(pattern, size) if (match_lines) strcpy(n, "^("); if (match_words) - strcpy(n, "(^|[^0-9A-Za-z_])("); + strcpy(n, "(^|[^[:alnum:]_])("); i = strlen(n); memcpy(n + i, pattern, size); i += size; if (match_words) - strcpy(n + i, ")([^0-9A-Za-z_]|$)"); + strcpy(n + i, ")([^[:alnum:]_]|$)"); if (match_lines) strcpy(n + i, ")$"); @@ -258,6 +254,7 @@ EGexecute(buf, size, endp) char **endp; { register char *buflim, *beg, *end, save; + char eol = eolbyte; int backref, start, len; struct kwsmatch kwsm; static struct re_registers regs; /* This is static on account of a BRAIN-DEAD @@ -275,10 +272,10 @@ EGexecute(buf, size, endp) goto failure; /* Narrow down to the line containing the candidate, and run it through DFA. */ - end = memchr(beg, '\n', buflim - beg); + end = memchr(beg, eol, buflim - beg); if (!end) end = buflim; - while (beg > buf && beg[-1] != '\n') + while (beg > buf && beg[-1] != eol) --beg; save = *end; if (kwsm.index < lastexact) @@ -302,10 +299,10 @@ EGexecute(buf, size, endp) if (!beg) goto failure; /* Narrow down to the line we've found. */ - end = memchr(beg, '\n', buflim - beg); + end = memchr(beg, eol, buflim - beg); if (!end) end = buflim; - while (beg > buf && beg[-1] != '\n') + while (beg > buf && beg[-1] != eol) --beg; /* Successful, no backreferences encountered! */ if (!backref) @@ -313,8 +310,8 @@ EGexecute(buf, size, endp) } /* If we've made it to this point, this means DFA has seen a probable match, and we need to run it through Regex. */ - regex.not_eol = 0; - if ((start = re_search(®ex, beg, end - beg, 0, end - beg, ®s)) >= 0) + regexbuf.not_eol = 0; + if ((start = re_search(®exbuf, beg, end - beg, 0, end - beg, ®s)) >= 0) { len = regs.end[0] - start; if ((!match_lines && !match_words) @@ -337,8 +334,8 @@ EGexecute(buf, size, endp) { /* Try a shorter length anchored at the same place. */ --len; - regex.not_eol = 1; - len = re_match(®ex, beg, start + len, start, ®s); + regexbuf.not_eol = 1; + len = re_match(®exbuf, beg, start + len, start, ®s); } if (len <= 0) { @@ -346,8 +343,8 @@ EGexecute(buf, size, endp) if (start == end - beg) break; ++start; - regex.not_eol = 0; - start = re_search(®ex, beg, end - beg, + regexbuf.not_eol = 0; + start = re_search(®exbuf, beg, end - beg, start, end - beg - start, ®s); len = regs.end[0] - start; } @@ -396,6 +393,7 @@ Fexecute(buf, size, endp) { register char *beg, *try, *end; register size_t len; + char eol = eolbyte; struct kwsmatch kwsmatch; for (beg = buf; beg <= buf + size; ++beg) @@ -405,9 +403,9 @@ Fexecute(buf, size, endp) len = kwsmatch.size[0]; if (match_lines) { - if (beg > buf && beg[-1] != '\n') + if (beg > buf && beg[-1] != eol) continue; - if (beg + len < buf + size && beg[len] != '\n') + if (beg + len < buf + size && beg[len] != eol) continue; goto success; } @@ -431,7 +429,7 @@ Fexecute(buf, size, endp) return 0; success: - if ((end = memchr(beg + len, '\n', (buf + size) - (beg + len))) != 0) + if ((end = memchr(beg + len, eol, (buf + size) - (beg + len))) != 0) ++end; else end = buf + size; |
