mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-22 10:06:16 +02:00
b2/: add regular expression conversion debugging (option -R)
This commit is contained in:
parent
12b21f032c
commit
da1010f92a
15
b2/boom.c
15
b2/boom.c
@ -75,6 +75,15 @@ static void do_substitutions(void)
|
||||
}
|
||||
|
||||
|
||||
static void parse_re(const char *re)
|
||||
{
|
||||
char *res;
|
||||
|
||||
subst_match(NULL, re, &res);
|
||||
printf("%s\n", res);
|
||||
}
|
||||
|
||||
|
||||
static void dump_hierarchy(struct action act)
|
||||
{
|
||||
fields_dump(stderr, act.fields);
|
||||
@ -124,6 +133,7 @@ static void usage(const char *name)
|
||||
" -N name for the next file, override the name in diagnostics\n"
|
||||
" -q var=value ... run substitutions with the specified inputs\n"
|
||||
" -Q var=value ... run substitutions and then do parametric search\n"
|
||||
" -R regex parse and print regular expression\n"
|
||||
, name);
|
||||
exit(1);
|
||||
}
|
||||
@ -178,6 +188,11 @@ int main(int argc, char **argv)
|
||||
process = add_var;
|
||||
query = 1;
|
||||
select_parts = 1;
|
||||
} else if (!strcmp(argv[i], "-R")) {
|
||||
i++;
|
||||
if (!argv[i])
|
||||
usage(*argv);
|
||||
parse_re(argv[i]);
|
||||
} else
|
||||
usage(*argv);
|
||||
}
|
||||
|
@ -619,7 +619,7 @@ block:
|
||||
if ($4) {
|
||||
if ($2 != rel_eq)
|
||||
yyerror("only = allow for matching");
|
||||
$$ = subst_match($1, $3);
|
||||
$$ = subst_match($1, $3, NULL);
|
||||
$$->u.match.block = $4;
|
||||
} else {
|
||||
$$ = subst_assign($1, $2, $3);
|
||||
|
@ -113,7 +113,7 @@ static char *prepare_re(const char *re, char *units)
|
||||
}
|
||||
|
||||
|
||||
struct subst *subst_match(const char *src, const char *re)
|
||||
struct subst *subst_match(const char *src, const char *re, char **res)
|
||||
{
|
||||
char error[1000];
|
||||
struct subst *sub;
|
||||
@ -124,7 +124,10 @@ struct subst *subst_match(const char *src, const char *re)
|
||||
sub->u.match.src = src;
|
||||
tmp = prepare_re(re, sub->u.match.units);
|
||||
err = regcomp(&sub->u.match.re, tmp, REG_EXTENDED);
|
||||
free(tmp);
|
||||
if (res)
|
||||
*res = tmp;
|
||||
else
|
||||
free(tmp);
|
||||
if (err) {
|
||||
regerror(err, &sub->u.match.re, error, sizeof(error));
|
||||
yyerrorf("%s", error);
|
||||
|
@ -76,7 +76,7 @@ struct subst {
|
||||
extern const char *fn;
|
||||
|
||||
|
||||
struct subst *subst_match(const char *src, const char *re);
|
||||
struct subst *subst_match(const char *src, const char *re, char **res);
|
||||
struct subst *subst_assign(const char *dst, enum relop op, const char *pat);
|
||||
struct subst *subst_end(void);
|
||||
struct subst *subst_ignore(void);
|
||||
|
Loading…
Reference in New Issue
Block a user