1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 19:39:22 +02:00
eda-tools/b2/boom.c

98 lines
1.9 KiB
C
Raw Normal View History

/*
* boom.c - BOOM, main function
*
* Copyright 2012 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "util.h"
2012-04-26 09:02:48 +03:00
#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)
2012-03-18 18:24:12 +02:00
{
fprintf(stderr,
"usage: %s file [[-type] file ...] [-q var=value ...] ...\n\n"
" file types:\n"
" -c characteristics\n"
" -i inventory\n"
2012-05-01 04:49:33 +03:00
" -x currency exchange\n"
2012-05-01 20:57:12 +03:00
" -p providers\n"
" -s substitutions\n"
" -q var=value ...\n"
, name);
exit(1);
}
int main(int argc, char **argv)
{
void (*process)(const char *name) = parse_hierarchy;
int i;
for (i = 1; i != argc; i++) {
if (*argv[i] == '-') {
if (!strcmp(argv[i], "-c"))
process = parse_characteristics;
else if (!strcmp(argv[i], "-i"))
process = parse_inventory;
2012-05-01 04:49:33 +03:00
else if (!strcmp(argv[i], "-x"))
process = parse_currencies;
2012-05-01 20:57:12 +03:00
else if (!strcmp(argv[i], "-p"))
process = parse_providers;
else if (!strcmp(argv[i], "-s"))
process = parse_substitutions;
else if (!strcmp(argv[i], "-q"))
process = add_var;
else
usage(*argv);
} else {
process(argv[i]);
}
}
if (vars)
do_substitutions();
2012-03-18 18:24:12 +02:00
return 0;
}