From 24a32525e2f8843da436c5878593a7a822a5e47a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 30 Apr 2012 20:40:11 -0300 Subject: [PATCH] b2/: add dumping of stock information Also use part_add without first calling part_lookup, since the latter is implicit. --- b2/Makefile | 2 +- b2/db.c | 15 ++++++++++++++- b2/lang.y | 11 +++++------ 3 files changed, 20 insertions(+), 8 deletions(-) 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); } ;