1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-07-01 02:23:16 +03:00

b2/bom.c (bom_parse_line): check that components reference are unique

This commit is contained in:
Werner Almesberger 2012-05-23 16:31:54 -03:00
parent ddd22ba16c
commit 9445f2c85b
2 changed files with 25 additions and 8 deletions

View File

@ -11,6 +11,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include "util.h" #include "util.h"
@ -22,17 +23,23 @@ struct bom *bom = NULL;
int n_bom = 0; 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 *bom_parse_line(const char *s)
{ {
struct bom *b; struct bom *b;
const char *t; const char *ref, *t;
char *f; char *f;
bom = realloc(bom, sizeof(struct bom)*(n_bom+1));
if (!bom)
abort();
b = bom+n_bom++;
if (*s++ != '|') if (*s++ != '|')
abort(); abort();
while (*s == ' ' || *s == '\t') while (*s == ' ' || *s == '\t')
@ -40,7 +47,17 @@ struct bom *bom_parse_line(const char *s)
for (t = s+1; *t && !isspace(*t); t++); for (t = s+1; *t && !isspace(*t); t++);
if (!*t) if (!*t)
yyerror("invalid BOM record (1)\n"); 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->sym = NULL;
b->fields = NULL; b->fields = NULL;
b->n_fields = 0; b->n_fields = 0;

View File

@ -29,6 +29,6 @@ extern struct bom *bom;
extern int n_bom; extern int n_bom;
struct bom *bom_parse_line(const char *line); struct bom *bom_parse_line(const char *s);
#endif /* !BOM_H */ #endif /* !BOM_H */