mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-23 05:19:21 +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;
|
char *res = NULL;
|
||||||
int res_len = 0;
|
int res_len = 0;
|
||||||
|
int parens = 0;
|
||||||
|
|
||||||
*parens = 0;
|
|
||||||
memset(units, 0, 10);
|
memset(units, 0, 10);
|
||||||
append_char(&res, &res_len, '^');
|
append_char(&res, &res_len, '^');
|
||||||
while (*re) {
|
while (*re) {
|
||||||
@ -85,11 +85,11 @@ static char *prepare_re(const char *re, int *parens, char *units)
|
|||||||
re++;
|
re++;
|
||||||
break;
|
break;
|
||||||
case '(':
|
case '(':
|
||||||
(*parens)++;
|
parens++;
|
||||||
if (re[1] == '#' && re[2]) {
|
if (re[1] == '#' && re[2]) {
|
||||||
if (!isalpha(re[2]) || re[3] != ')')
|
if (!isalpha(re[2]) || re[3] != ')')
|
||||||
yyerrorf("invalid (#unit) syntax");
|
yyerrorf("invalid (#unit) syntax");
|
||||||
units[*parens-1] = re[2];
|
units[parens-1] = re[2];
|
||||||
unit_expr(&res, &res_len, re[2]);
|
unit_expr(&res, &res_len, re[2]);
|
||||||
re += 3;
|
re += 3;
|
||||||
break;
|
break;
|
||||||
@ -115,7 +115,7 @@ struct subst *subst_match(const char *src, const char *re)
|
|||||||
|
|
||||||
sub = alloc_subst(st_match);
|
sub = alloc_subst(st_match);
|
||||||
sub->u.match.src = src;
|
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);
|
err = regcomp(&sub->u.match.re, tmp, REG_EXTENDED);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -326,7 +326,7 @@ static void check_chunks(const struct chunk *c, const struct parent *parent,
|
|||||||
if (!parent)
|
if (!parent)
|
||||||
yyerrorf("$%c without match",
|
yyerrorf("$%c without match",
|
||||||
c->u.sub ? c->u.sub+'0' : '$');
|
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)
|
if (c->u.sub > parens)
|
||||||
yyerrorf("$%d but only %d parenthes%s",
|
yyerrorf("$%d but only %d parenthes%s",
|
||||||
c->u.sub, parens,
|
c->u.sub, parens,
|
||||||
|
@ -56,7 +56,6 @@ struct subst {
|
|||||||
regex_t re;
|
regex_t re;
|
||||||
struct subst *block;
|
struct subst *block;
|
||||||
char units[NMATCH-1];
|
char units[NMATCH-1];
|
||||||
int parens; /* number of parentheses */
|
|
||||||
} match;
|
} match;
|
||||||
struct {
|
struct {
|
||||||
const char *dst;
|
const char *dst;
|
||||||
|
Loading…
Reference in New Issue
Block a user