summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d7eb527)
raw | patch | inline | side by side (parent: d7eb527)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Sat, 7 Mar 2009 12:30:27 +0000 (13:30 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 7 Mar 2009 19:34:57 +0000 (11:34 -0800) |
Push pmatch and eflags to the callers of match_one_pattern(), which
allows them to specify regex execution flags and to get the location
of a match.
Since we only use the first element of the matches array and aren't
interested in submatches, no provision is made for callers to
provide a larger array.
eflags are ignored for fixed patterns, but that's OK, since they
only have a meaning in connection with regular expressions
containing ^ or $.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
allows them to specify regex execution flags and to get the location
of a match.
Since we only use the first element of the matches array and aren't
interested in submatches, no provision is made for callers to
provide a larger array.
eflags are ignored for fixed patterns, but that's OK, since they
only have a meaning in connection with regular expressions
containing ^ or $.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c | patch | blob | history |
index f45518233fe7ffaf7412010b1af900bde2dcb370..bdcff7b9e4959b618028edb6759fb4aa36db45f1 100644 (file)
--- a/grep.c
+++ b/grep.c
};
static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
- enum grep_context ctx)
+ enum grep_context ctx,
+ regmatch_t *pmatch, int eflags)
{
int hit = 0;
int saved_ch = 0;
- regmatch_t pmatch[10];
if ((p->token != GREP_PATTERN) &&
((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))
}
again:
- if (!p->fixed) {
- regex_t *exp = &p->regexp;
- hit = !regexec(exp, bol, ARRAY_SIZE(pmatch),
- pmatch, 0);
- }
- else {
+ if (p->fixed)
hit = !fixmatch(p->pattern, bol, pmatch);
- }
+ else
+ hit = !regexec(&p->regexp, bol, 1, pmatch, eflags);
if (hit && p->word_regexp) {
if ((pmatch[0].rm_so < 0) ||
enum grep_context ctx, int collect_hits)
{
int h = 0;
+ regmatch_t match;
switch (x->node) {
case GREP_NODE_ATOM:
- h = match_one_pattern(x->u.atom, bol, eol, ctx);
+ h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);
break;
case GREP_NODE_NOT:
h = !match_expr_eval(x->u.unary, bol, eol, ctx, 0);
enum grep_context ctx, int collect_hits)
{
struct grep_pat *p;
+ regmatch_t match;
+
if (opt->extended)
return match_expr(opt, bol, eol, ctx, collect_hits);
/* we do not call with collect_hits without being extended */
for (p = opt->pattern_list; p; p = p->next) {
- if (match_one_pattern(p, bol, eol, ctx))
+ if (match_one_pattern(p, bol, eol, ctx, &match, 0))
return 1;
}
return 0;