/* * bom.c - BOM data * * Copyright 2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include #include #include "util.h" #include "lang.h" #include "bom.h" struct bom *bom = NULL; int n_bom = 0; struct bom *bom_parse_line(const char *s) { struct bom *b; const char *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') s++; for (t = s+1; *t && !isspace(*t); t++); if (!*t) yyerror("invalid BOM record (1)\n"); b->ref = stralloc_n(s, t-s); b->sym = NULL; b->fields = NULL; b->n_fields = 0; for (s = t; *t && *t != '\n'; s = t+1) { while (*s == ' ' || *s == '\t') s++; if (*s == ';' || *s == '\n') { f = NULL; t = s; } else { for (t = s+1; *t && *t != ';' && !isspace(*t); t++); f = stralloc_n(s, t-s); while (*t == ' ' || *t == '\t') t++; } /* VAL, FP, F1 ... */ b->fields = realloc(b->fields, sizeof(const char *)*(b->n_fields+1)); if (!b->fields) abort(); b->fields[b->n_fields] = f ? unique(f) : unique(""); b->n_fields++; free(f); } return b; }