From b0ed4364dcc2731df283bc1a60418b75e52da3c4 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 30 May 2012 12:58:29 -0300 Subject: [PATCH] b2/: new option -v to control verbosity level; move hierarchy dump from parser to boom.c --- b2/Makefile | 2 +- b2/boom.c | 20 ++++++++++++++++++-- b2/lang.y | 4 ---- b2/test/Common | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/b2/Makefile b/b2/Makefile index 5e526a6..2740777 100644 --- a/b2/Makefile +++ b/b2/Makefile @@ -91,7 +91,7 @@ spotless: clean # ----- Experiments ----------------------------------------------------------- try: - $(VALGRIND) ./boom HIERARCHY -c CHAR -x CURR -p PROVIDER -i INV \ + $(VALGRIND) ./boom -v HIERARCHY -c CHAR -x CURR -p PROVIDER -i INV \ -s SUBST # ----- Tests ----------------------------------------------------------------- diff --git a/b2/boom.c b/b2/boom.c index 1bf5e1a..96c74e5 100644 --- a/b2/boom.c +++ b/b2/boom.c @@ -17,12 +17,14 @@ #include "util.h" #include "lang.h" #include "param.h" +#include "chr.h" #include "subex.h" #include "db.h" static struct param *vars = NULL, **last_var = &vars; static int select_parts = 0; +static int verbose = 0; static void add_var(const char *arg) @@ -72,10 +74,19 @@ static void do_substitutions(void) } +static void dump_hierarchy(struct action act) +{ + fields_dump(stderr, act.fields); + if (act.fields) + fprintf(stderr, "\n"); + rules_dump(stderr, act.rules); +} + + static void usage(const char *name) { fprintf(stderr, -"usage: %s file [[-N name] [-type] file ...] [(-q|-Q) var=value ...] ...\n\n" +"usage: %s file [-v] [[-N name] [-type] file ...] [(-q|-Q) var=value ...] ...\n\n" " file types:\n" " -c characteristics\n" " -i inventory\n" @@ -85,6 +96,7 @@ static void usage(const char *name) " -b KiCad eeschema BOM\n" " -X symbols (BOM supplement)\n" " other options:\n" +" -v ... increase verbosity level\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 and then do parametric search\n" @@ -104,7 +116,9 @@ int main(int argc, char **argv) if (!strcmp(argv[i], "-N")) { i++; file_name_override = argv[i]; - } else if (!strcmp(argv[i], "-c")) + } else if (!strcmp(argv[i], "-v")) + verbose++; + else if (!strcmp(argv[i], "-c")) process = parse_characteristics; else if (!strcmp(argv[i], "-i")) process = parse_inventory; @@ -127,6 +141,8 @@ int main(int argc, char **argv) usage(*argv); } else { process(argv[i]); + if (verbose && process == parse_hierarchy) + dump_hierarchy(hierarchy); } } if (vars) diff --git a/b2/lang.y b/b2/lang.y index ad8dd92..91d18d6 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -156,10 +156,6 @@ hierarchy: | action { $$ = $1; - fields_dump(stderr, $1.fields); - if ($1.fields) - fprintf(stderr, "\n"); - rules_dump(stderr, $1.rules); } ; diff --git a/b2/test/Common b/b2/test/Common index bb52920..2843f74 100755 --- a/b2/test/Common +++ b/b2/test/Common @@ -20,7 +20,7 @@ run_boom() args="$args -$n <(sed -n '1,/^!-$n/d;/^!-/q;p' _in)" fi done - eval $VALGRIND ../boom "$args" "$@" + eval $VALGRIND ../boom -v "$args" "$@" }