@ -189,29 +189,31 @@ static struct grep_expr *compile_pattern_expr(struct grep_pat **list)
return compile_pattern_or(list);
return compile_pattern_or(list);
}
}
void compile_grep_patterns(struct grep_opt *opt)
static struct grep_expr *prep_header_patterns(struct grep_opt *opt)
{
{
struct grep_pat *p;
struct grep_pat *p;
struct grep_expr *header_expr = NULL;
struct grep_expr *header_expr;
if (opt->header_list) {
if (!opt->header_list)
p = opt->header_list;
return NULL;
header_expr = compile_pattern_expr(&p);
p = opt->header_list;
if (p)
header_expr = compile_pattern_expr(&p);
die("incomplete pattern expression: %s", p->pattern);
if (p)
for (p = opt->header_list; p; p = p->next) {
die("incomplete pattern expression: %s", p->pattern);
switch (p->token) {
for (p = opt->header_list; p; p = p->next) {
case GREP_PATTERN: /* atom */
if (p->token != GREP_PATTERN_HEAD)
case GREP_PATTERN_HEAD:
die("bug: a non-header pattern in grep header list.");
case GREP_PATTERN_BODY:
if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)
compile_regexp(p, opt);
die("bug: unknown header field %d", p->field);
break;
compile_regexp(p, opt);
default:
opt->extended = 1;
break;
}
}
}
}
return header_expr;
}
void compile_grep_patterns(struct grep_opt *opt)
{
struct grep_pat *p;
struct grep_expr *header_expr = prep_header_patterns(opt);
for (p = opt->pattern_list; p; p = p->next) {
for (p = opt->pattern_list; p; p = p->next) {
switch (p->token) {
switch (p->token) {
@ -231,9 +233,6 @@ void compile_grep_patterns(struct grep_opt *opt)
else if (!opt->extended)
else if (!opt->extended)
return;
return;
/* Then bundle them up in an expression.
* A classic recursive descent parser would do.
*/
p = opt->pattern_list;
p = opt->pattern_list;
if (p)
if (p)
opt->pattern_expression = compile_pattern_expr(&p);
opt->pattern_expression = compile_pattern_expr(&p);