mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-22 21:23:10 +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)
|
static void dump_hierarchy(struct action act)
|
||||||
{
|
{
|
||||||
fields_dump(stderr, act.fields);
|
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"
|
" -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 with the specified inputs\n"
|
||||||
" -Q var=value ... run substitutions and then do parametric search\n"
|
" -Q var=value ... run substitutions and then do parametric search\n"
|
||||||
|
" -R regex parse and print regular expression\n"
|
||||||
, name);
|
, name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -178,6 +188,11 @@ int main(int argc, char **argv)
|
|||||||
process = add_var;
|
process = add_var;
|
||||||
query = 1;
|
query = 1;
|
||||||
select_parts = 1;
|
select_parts = 1;
|
||||||
|
} else if (!strcmp(argv[i], "-R")) {
|
||||||
|
i++;
|
||||||
|
if (!argv[i])
|
||||||
|
usage(*argv);
|
||||||
|
parse_re(argv[i]);
|
||||||
} else
|
} else
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
}
|
}
|
||||||
|
@ -619,7 +619,7 @@ block:
|
|||||||
if ($4) {
|
if ($4) {
|
||||||
if ($2 != rel_eq)
|
if ($2 != rel_eq)
|
||||||
yyerror("only = allow for matching");
|
yyerror("only = allow for matching");
|
||||||
$$ = subst_match($1, $3);
|
$$ = subst_match($1, $3, NULL);
|
||||||
$$->u.match.block = $4;
|
$$->u.match.block = $4;
|
||||||
} else {
|
} else {
|
||||||
$$ = subst_assign($1, $2, $3);
|
$$ = 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];
|
char error[1000];
|
||||||
struct subst *sub;
|
struct subst *sub;
|
||||||
@ -124,7 +124,10 @@ struct subst *subst_match(const char *src, const char *re)
|
|||||||
sub->u.match.src = src;
|
sub->u.match.src = src;
|
||||||
tmp = prepare_re(re, 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);
|
if (res)
|
||||||
|
*res = tmp;
|
||||||
|
else
|
||||||
|
free(tmp);
|
||||||
if (err) {
|
if (err) {
|
||||||
regerror(err, &sub->u.match.re, error, sizeof(error));
|
regerror(err, &sub->u.match.re, error, sizeof(error));
|
||||||
yyerrorf("%s", error);
|
yyerrorf("%s", error);
|
||||||
|
@ -76,7 +76,7 @@ struct subst {
|
|||||||
extern const char *fn;
|
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_assign(const char *dst, enum relop op, const char *pat);
|
||||||
struct subst *subst_end(void);
|
struct subst *subst_end(void);
|
||||||
struct subst *subst_ignore(void);
|
struct subst *subst_ignore(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user