diff --git a/b2/Makefile b/b2/Makefile index 0754d97..d578867 100644 --- a/b2/Makefile +++ b/b2/Makefile @@ -83,4 +83,4 @@ spotless: clean # ----- Experiments ----------------------------------------------------------- try: - $(VALGRIND) ./boom HIERARCHY -c CHAR + $(VALGRIND) ./boom HIERARCHY -c CHAR -i INV diff --git a/b2/db.c b/b2/db.c index e15717c..12e508c 100644 --- a/b2/db.c +++ b/b2/db.c @@ -168,6 +168,18 @@ void part_add_stock(struct part *part, struct stock *stock) } +static void dump_stock(FILE *file, const struct stock *s) +{ + const struct price *p; + + fprintf(file, " %s %d %d %s %g", + s->cat, s->avail, s->package, "???", s->add); + for (p = s->price; p; p = p->next) + fprintf(file, " %d %g", p->qty, p->value); + fprintf(file, "\n"); +} + + void part_dump(FILE *file, const struct part *part) { const struct param *p; @@ -181,5 +193,6 @@ void part_dump(FILE *file, const struct part *part) } fprintf(file, "\n"); } - if (part->stock); + if (part->stock) + dump_stock(file, part->stock); } diff --git a/b2/lang.y b/b2/lang.y index 0c0f894..04b0bd9 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -378,9 +378,7 @@ characteristics: part: WORD WORD params TOK_NL { - $$ = part_lookup($1, $2); - if (!$$) - $$ = part_add($1, $2); + $$ = part_add($1, $2); if ($$->param) yyerror("parameters already defined"); $$->param = $3; @@ -414,14 +412,15 @@ param: inventory: | TOK_NL | inventory_item inventory + { + part_dump(stderr, $1); + } ; inventory_item: WORD WORD stock TOK_NL { - $$ = part_lookup($1, $2); - if (!$$) - $$ = part_add($1, $2); + $$ = part_add($1, $2); part_add_stock($$, $3); } ;