From 21702781bcc5154defda0b722d0f1c51ac416816 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 22 May 2012 13:51:57 -0300 Subject: [PATCH] b2/: use re_nsub instead of maintaining our own equivalent We still need to count parentheses in prepare_re for the current index into "units", but the rest can ue re_nsub. --- b2/subst.c | 12 ++++++------ b2/subst.h | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/b2/subst.c b/b2/subst.c index 7168ded..04ed9be 100644 --- a/b2/subst.c +++ b/b2/subst.c @@ -59,12 +59,12 @@ static void unit_expr(char **res, int *res_len, char unit) } -static char *prepare_re(const char *re, int *parens, char *units) +static char *prepare_re(const char *re, char *units) { char *res = NULL; int res_len = 0; + int parens = 0; - *parens = 0; memset(units, 0, 10); append_char(&res, &res_len, '^'); while (*re) { @@ -85,11 +85,11 @@ static char *prepare_re(const char *re, int *parens, char *units) re++; break; case '(': - (*parens)++; + parens++; if (re[1] == '#' && re[2]) { if (!isalpha(re[2]) || re[3] != ')') yyerrorf("invalid (#unit) syntax"); - units[*parens-1] = re[2]; + units[parens-1] = re[2]; unit_expr(&res, &res_len, re[2]); re += 3; break; @@ -115,7 +115,7 @@ struct subst *subst_match(const char *src, const char *re) sub = alloc_subst(st_match); sub->u.match.src = src; - tmp = prepare_re(re, &sub->u.match.parens, sub->u.match.units); + tmp = prepare_re(re, sub->u.match.units); err = regcomp(&sub->u.match.re, tmp, REG_EXTENDED); free(tmp); if (err) { @@ -326,7 +326,7 @@ static void check_chunks(const struct chunk *c, const struct parent *parent, if (!parent) yyerrorf("$%c without match", c->u.sub ? c->u.sub+'0' : '$'); - parens = parent->sub->u.match.parens; + parens = parent->sub->u.match.re.re_nsub; if (c->u.sub > parens) yyerrorf("$%d but only %d parenthes%s", c->u.sub, parens, diff --git a/b2/subst.h b/b2/subst.h index 62e8718..70b6a15 100644 --- a/b2/subst.h +++ b/b2/subst.h @@ -56,7 +56,6 @@ struct subst { regex_t re; struct subst *block; char units[NMATCH-1]; - int parens; /* number of parentheses */ } match; struct { const char *dst;