diff --git a/b2/CHAR b/b2/CHAR index 4e3a66c..7c27fec 100644 --- a/b2/CHAR +++ b/b2/CHAR @@ -1,2 +1,2 @@ -FOO R101X FP=0603 R=100R TOL=5% -FOO R102Y FP=0603 R=1k TOL=1% +FOO R101X T=R FP=0603 R=100R TOL=5% GAGA=1 +FOO R102Y T=R FP=0603 R=1k TOL=1% diff --git a/b2/db.c b/b2/db.c index 1f45359..96fc525 100644 --- a/b2/db.c +++ b/b2/db.c @@ -10,9 +10,12 @@ */ +#include #include #include "util.h" +#include "lang.h" +#include "chr.h" #include "db.h" @@ -80,3 +83,72 @@ void part_alias(struct part *a, struct part *b) b->prev = a; tmp->prev = tmp2; } + + +static void convert_params(struct param **params, + const struct field *f, struct param ***res) +{ + struct param **p, *prm; + const struct selector *sel; + const struct condition *cond; + + while (f) { + for (p = params; *p; p = &(*p)->next) + if ((*p)->u.name == f->name) + break; + if (!*p) { + f = f->next; + continue; + } + + /* remove from list */ + prm = *p; + *p = prm->next; + + /* convert parameter */ + prm->u.field = f; + if (!evaluate(f->fmt, prm->value.u.name, &prm->value)) + yyerrorf("invalid value for %s", f->name); + + /* add to result list */ + **res = prm; + *res = &prm->next; + prm->next = NULL; + + /* process selections */ + for (sel = f->sel; sel; sel = sel->next) { + for (cond = sel->cond; cond; cond = cond->next) + if (compare(f->fmt, &prm->value, cond->relop, + &cond->value)) + break; + if (cond) { + convert_params(params, sel->act.fields, res); + convert_params(params, sel->act.rules, res); + break; + } + } + if (!sel) { + convert_params(params, f->any.fields, res); + convert_params(params, f->any.rules, res); + } + + f = f->next; + } +} + + +void part_finalize(struct part *part, const struct field *field) +{ + struct param *param = part->param; + struct param **res = &part->param; + struct param *next; + + part->param = NULL; + convert_params(¶m, field, &res); + while (param) { + yywarnf("extra parameter: %s", param->u.name); + next = param->next; + free(param); + param = next; + } +} diff --git a/b2/db.h b/b2/db.h index db6ec41..0adfbb1 100644 --- a/b2/db.h +++ b/b2/db.h @@ -62,5 +62,6 @@ struct part { struct part *part_lookup(const char *domain, const char *name); struct part *part_add(const char *domain, const char *name); void part_alias(struct part *a, struct part *b); +void part_finalize(struct part *part, const struct field *field); #endif /* !DB_H */ diff --git a/b2/lang.y b/b2/lang.y index 0d6eefc..15a0404 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -23,6 +23,8 @@ #include "y.tab.h" +static const struct field *hierarchy; + static struct field_stack { const struct field *field; struct field_stack *next; @@ -101,6 +103,7 @@ hierarchy: nameset hierarchy | rule { + hierarchy = $1; field_dump(stderr, $1); } ; @@ -348,6 +351,9 @@ format: characteristics: | TOK_NL | part characteristics + { + part_finalize($1, hierarchy); + } ; part: