mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-12-23 09:05:31 +02:00
b2/boom.c: add substitution query mode (option -q)
This commit is contained in:
parent
04d858e047
commit
8e6357f4fa
54
b2/boom.c
54
b2/boom.c
@ -14,19 +14,53 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "lang.h"
|
||||
#include "subex.h"
|
||||
|
||||
|
||||
static struct var *vars = NULL, **last_var = &vars;
|
||||
|
||||
|
||||
static void add_var(const char *arg)
|
||||
{
|
||||
char *tmp = stralloc(arg);
|
||||
char *eq;
|
||||
|
||||
eq = strchr(tmp, '=');
|
||||
if (!eq) {
|
||||
fprintf(stderr, "no = in variable setting\n");
|
||||
exit(1);
|
||||
}
|
||||
*eq = 0;
|
||||
*last_var = make_var(tmp, eq+1);
|
||||
last_var = &(*last_var)->next;
|
||||
}
|
||||
|
||||
|
||||
static void do_substitutions(void)
|
||||
{
|
||||
struct var *out;
|
||||
const struct var *var;
|
||||
|
||||
out = substitute(substitutions, vars);
|
||||
for (var = out; var; var = var->next)
|
||||
printf("%s=%s\n", var->name, var->value);
|
||||
free_vars(out);
|
||||
}
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s file [[-type] file ...] ...\n\n"
|
||||
"usage: %s file [[-type] file ...] [-q var=value ...] ...\n\n"
|
||||
" file types:\n"
|
||||
" -c characteristics\n"
|
||||
" -i inventory\n"
|
||||
" -x currency exchange\n"
|
||||
" -p providers\n"
|
||||
" -s substitutions\n"
|
||||
" -q var=value ...\n"
|
||||
, name);
|
||||
exit(1);
|
||||
}
|
||||
@ -34,26 +68,30 @@ static void usage(const char *name)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void (*parse)(const char *name) = parse_hierarchy;
|
||||
void (*process)(const char *name) = parse_hierarchy;
|
||||
int i;
|
||||
|
||||
for (i = 1; i != argc; i++) {
|
||||
if (*argv[i] == '-') {
|
||||
if (!strcmp(argv[i], "-c"))
|
||||
parse = parse_characteristics;
|
||||
process = parse_characteristics;
|
||||
else if (!strcmp(argv[i], "-i"))
|
||||
parse = parse_inventory;
|
||||
process = parse_inventory;
|
||||
else if (!strcmp(argv[i], "-x"))
|
||||
parse = parse_currencies;
|
||||
process = parse_currencies;
|
||||
else if (!strcmp(argv[i], "-p"))
|
||||
parse = parse_providers;
|
||||
process = parse_providers;
|
||||
else if (!strcmp(argv[i], "-s"))
|
||||
parse = parse_substitutions;
|
||||
process = parse_substitutions;
|
||||
else if (!strcmp(argv[i], "-q"))
|
||||
process = add_var;
|
||||
else
|
||||
usage(*argv);
|
||||
} else {
|
||||
parse(argv[i]);
|
||||
process(argv[i]);
|
||||
}
|
||||
}
|
||||
if (vars)
|
||||
do_substitutions();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user