2012-04-25 23:14:39 +03:00
|
|
|
/*
|
|
|
|
* 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>
|
2012-05-01 02:11:53 +03:00
|
|
|
#include <string.h>
|
2012-04-25 23:14:39 +03:00
|
|
|
|
2012-05-21 01:01:49 +03:00
|
|
|
#include "util.h"
|
2012-04-26 09:02:48 +03:00
|
|
|
#include "lang.h"
|
2012-05-21 05:16:51 +03:00
|
|
|
#include "param.h"
|
2012-05-21 01:01:49 +03:00
|
|
|
#include "subex.h"
|
2012-05-22 03:20:23 +03:00
|
|
|
#include "db.h"
|
2012-05-21 01:01:49 +03:00
|
|
|
|
|
|
|
|
2012-05-22 01:19:04 +03:00
|
|
|
static struct param *vars = NULL, **last_var = &vars;
|
2012-05-22 03:20:23 +03:00
|
|
|
static int select_parts = 0;
|
2012-05-21 01:01:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2012-05-21 05:16:51 +03:00
|
|
|
*last_var = make_var(tmp, rel_eq, eq+1);
|
2012-05-21 01:01:49 +03:00
|
|
|
last_var = &(*last_var)->next;
|
2012-05-22 01:19:04 +03:00
|
|
|
free(tmp);
|
2012-05-21 01:01:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void do_substitutions(void)
|
|
|
|
{
|
2012-05-22 01:19:04 +03:00
|
|
|
struct param *out;
|
|
|
|
const struct param *var;
|
2012-05-22 03:20:23 +03:00
|
|
|
const struct part **parts, **p;
|
2012-05-21 01:01:49 +03:00
|
|
|
|
|
|
|
out = substitute(substitutions, vars);
|
2012-05-22 03:20:23 +03:00
|
|
|
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);
|
2012-05-21 05:16:51 +03:00
|
|
|
}
|
2012-05-21 01:01:49 +03:00
|
|
|
}
|
2012-04-25 23:14:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void usage(const char *name)
|
2012-03-18 18:24:12 +02:00
|
|
|
{
|
2012-05-01 02:11:53 +03:00
|
|
|
fprintf(stderr,
|
2012-05-21 01:01:49 +03:00
|
|
|
"usage: %s file [[-type] file ...] [-q var=value ...] ...\n\n"
|
2012-05-01 02:11:53 +03:00
|
|
|
" 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"
|
2012-05-20 17:18:18 +03:00
|
|
|
" -s substitutions\n"
|
2012-05-21 01:01:49 +03:00
|
|
|
" -q var=value ...\n"
|
2012-05-22 03:20:23 +03:00
|
|
|
" -Q var=value ...\n"
|
2012-05-01 02:11:53 +03:00
|
|
|
, name);
|
2012-04-25 23:14:39 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-05-21 01:01:49 +03:00
|
|
|
void (*process)(const char *name) = parse_hierarchy;
|
2012-04-28 17:46:42 +03:00
|
|
|
int i;
|
|
|
|
|
2012-05-01 02:11:53 +03:00
|
|
|
for (i = 1; i != argc; i++) {
|
|
|
|
if (*argv[i] == '-') {
|
|
|
|
if (!strcmp(argv[i], "-c"))
|
2012-05-21 01:01:49 +03:00
|
|
|
process = parse_characteristics;
|
2012-05-01 02:11:53 +03:00
|
|
|
else if (!strcmp(argv[i], "-i"))
|
2012-05-21 01:01:49 +03:00
|
|
|
process = parse_inventory;
|
2012-05-01 04:49:33 +03:00
|
|
|
else if (!strcmp(argv[i], "-x"))
|
2012-05-21 01:01:49 +03:00
|
|
|
process = parse_currencies;
|
2012-05-01 20:57:12 +03:00
|
|
|
else if (!strcmp(argv[i], "-p"))
|
2012-05-21 01:01:49 +03:00
|
|
|
process = parse_providers;
|
2012-05-20 17:18:18 +03:00
|
|
|
else if (!strcmp(argv[i], "-s"))
|
2012-05-21 01:01:49 +03:00
|
|
|
process = parse_substitutions;
|
|
|
|
else if (!strcmp(argv[i], "-q"))
|
|
|
|
process = add_var;
|
2012-05-22 03:20:23 +03:00
|
|
|
else if (!strcmp(argv[i], "-Q")) {
|
|
|
|
process = add_var;
|
|
|
|
select_parts = 1;
|
|
|
|
} else
|
2012-05-01 02:11:53 +03:00
|
|
|
usage(*argv);
|
|
|
|
} else {
|
2012-05-21 01:01:49 +03:00
|
|
|
process(argv[i]);
|
2012-05-01 02:11:53 +03:00
|
|
|
}
|
2012-04-28 17:46:42 +03:00
|
|
|
}
|
2012-05-21 01:01:49 +03:00
|
|
|
if (vars)
|
|
|
|
do_substitutions();
|
2012-03-18 18:24:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|