diff --git a/b2/bom.c b/b2/bom.c index 371d773..4fe7820 100644 --- a/b2/bom.c +++ b/b2/bom.c @@ -11,6 +11,7 @@ #include +#include #include #include "util.h" @@ -22,17 +23,23 @@ struct bom *bom = NULL; int n_bom = 0; +static struct bom *bom_find(const char *ref) +{ + struct bom *b; + + for (b = bom; b != bom+n_bom; b++) + if (b->ref == ref) + return b; + return NULL; +} + + struct bom *bom_parse_line(const char *s) { struct bom *b; - const char *t; + const char *ref, *t; char *f; - bom = realloc(bom, sizeof(struct bom)*(n_bom+1)); - if (!bom) - abort(); - b = bom+n_bom++; - if (*s++ != '|') abort(); while (*s == ' ' || *s == '\t') @@ -40,7 +47,17 @@ struct bom *bom_parse_line(const char *s) for (t = s+1; *t && !isspace(*t); t++); if (!*t) yyerror("invalid BOM record (1)\n"); - b->ref = stralloc_n(s, t-s); + + ref = unique_n(s, t-s); + if (bom_find(ref)) + yyerrorf("duplicate component reference %s", ref); + + bom = realloc(bom, sizeof(struct bom)*(n_bom+1)); + if (!bom) + abort(); + b = bom+n_bom++; + + b->ref = ref; b->sym = NULL; b->fields = NULL; b->n_fields = 0; diff --git a/b2/bom.h b/b2/bom.h index 63d3f65..c8de71c 100644 --- a/b2/bom.h +++ b/b2/bom.h @@ -29,6 +29,6 @@ extern struct bom *bom; extern int n_bom; -struct bom *bom_parse_line(const char *line); +struct bom *bom_parse_line(const char *s); #endif /* !BOM_H */