mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-23 01:32:49 +02:00
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.
This commit is contained in:
parent
148d5e85ac
commit
21702781bc
12
b2/subst.c
12
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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user