From 256a096220cf4eb4d5404c0e4c79fefc433dd089 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 21 May 2012 21:20:23 -0300 Subject: [PATCH] b2/boom.c: add parametric part selection (with option -Q) --- b2/boom.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/b2/boom.c b/b2/boom.c index 94e384c..83ea06e 100644 --- a/b2/boom.c +++ b/b2/boom.c @@ -18,9 +18,11 @@ #include "lang.h" #include "param.h" #include "subex.h" +#include "db.h" static struct param *vars = NULL, **last_var = &vars; +static int select_parts = 0; static void add_var(const char *arg) @@ -44,14 +46,26 @@ static void do_substitutions(void) { struct param *out; const struct param *var; + const struct part **parts, **p; out = substitute(substitutions, vars); - for (var = out; var; var = var->next) { - printf("%s", var->u.name); - dump_relop(stdout, var->op); - printf("%s\n", var->value.u.s); + if (select_parts) { + parts = select_parametric(out, &hierarchy); + if (!parts) { + fprintf(stderr, "no matches\n"); + } else { + for (p = parts; *p; p++) + printf("%s %s\n", (*p)->domain, (*p)->name); + free(parts); + } + } else { + for (var = out; var; var = var->next) { + printf("%s", var->u.name); + dump_relop(stdout, var->op); + printf("%s\n", var->value.u.s); + } + free_vars(out); } - free_vars(out); } @@ -66,6 +80,7 @@ static void usage(const char *name) " -p providers\n" " -s substitutions\n" " -q var=value ...\n" +" -Q var=value ...\n" , name); exit(1); } @@ -90,7 +105,10 @@ int main(int argc, char **argv) process = parse_substitutions; else if (!strcmp(argv[i], "-q")) process = add_var; - else + else if (!strcmp(argv[i], "-Q")) { + process = add_var; + select_parts = 1; + } else usage(*argv); } else { process(argv[i]);