mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 01:32:48 +02:00
b2/: run variable substitution on BOM entries (untested)
This commit is contained in:
parent
4fb17f6e95
commit
ec04163f44
50
b2/bom.c
50
b2/bom.c
@ -13,9 +13,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "lang.h"
|
||||
#include "relop.h"
|
||||
#include "param.h"
|
||||
#include "subst.h"
|
||||
#include "subex.h"
|
||||
#include "bom.h"
|
||||
|
||||
|
||||
@ -61,6 +66,7 @@ struct bom *bom_parse_line(const char *s)
|
||||
b->sym = NULL;
|
||||
b->fields = NULL;
|
||||
b->n_fields = 0;
|
||||
b->vars = 0;
|
||||
|
||||
for (s = t; *t && *t != '\n'; s = t+1) {
|
||||
while (*s == ' ' || *s == '\t')
|
||||
@ -99,3 +105,47 @@ void bom_set_sym(const char *ref, const char *sym)
|
||||
yyerrorf("symbol is already set in \"%s\"", ref);
|
||||
b->sym = sym;
|
||||
}
|
||||
|
||||
|
||||
static void add_var(struct param ***last, struct param *var)
|
||||
{
|
||||
**last = var;
|
||||
*last = &var->next;
|
||||
}
|
||||
|
||||
|
||||
int bom_subst(struct bom *b, const struct subst *sub)
|
||||
{
|
||||
char tmp[4];
|
||||
struct param *vars = NULL, **last = &vars;
|
||||
struct param *out;
|
||||
int i, res;
|
||||
|
||||
/* must be last, for removal with n_bom-- to work */
|
||||
assert(b == bom+n_bom-1);
|
||||
|
||||
/* set input variables */
|
||||
add_var(&last, make_var("REF", rel_eq, b->ref));
|
||||
if (b->n_fields && *b->fields[0])
|
||||
add_var(&last, make_var("VAL", rel_eq, b->fields[0]));
|
||||
if (b->n_fields > 1 && *b->fields[1])
|
||||
add_var(&last, make_var("FP", rel_eq, b->fields[1]));
|
||||
else
|
||||
yywarnf("\"%s\" has no footprint", b->ref);
|
||||
for (i = 2; i != b->n_fields; i++)
|
||||
if (*b->fields[i]) {
|
||||
sprintf(tmp, "F%d", i-1);
|
||||
add_var(&last, make_var(tmp, rel_eq, b->fields[i]));
|
||||
}
|
||||
if (b->sym)
|
||||
add_var(&last, make_var("SYM", rel_eq, b->sym));
|
||||
|
||||
/* run substitutions */
|
||||
res = substitute(sub, vars, &out);
|
||||
free_vars(vars);
|
||||
if (res)
|
||||
b->vars = out;
|
||||
else
|
||||
n_bom--;
|
||||
return res;
|
||||
}
|
||||
|
2
b2/bom.h
2
b2/bom.h
@ -14,6 +14,7 @@
|
||||
#define BOM_H
|
||||
|
||||
#include "param.h"
|
||||
#include "subst.h"
|
||||
|
||||
|
||||
struct bom {
|
||||
@ -30,5 +31,6 @@ extern int n_bom;
|
||||
|
||||
struct bom *bom_parse_line(const char *s);
|
||||
void bom_set_sym(const char *ref, const char *sym);
|
||||
int bom_subst(struct bom *b, const struct subst *sub);
|
||||
|
||||
#endif /* !BOM_H */
|
||||
|
11
b2/lang.l
11
b2/lang.l
@ -103,6 +103,15 @@ void parse_symbols(const char *name)
|
||||
do_parse(name, START_SYMBOLS, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
static void process_bom_line(const char *s)
|
||||
{
|
||||
struct bom *b;
|
||||
|
||||
b = bom_parse_line(s);
|
||||
bom_subst(b, substitutions);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
@ -138,7 +147,7 @@ PAT "\\"[^\t\n]|[^ \t\n\\]
|
||||
<BOM>"eeschema \("[^\n]* { hash = 0;
|
||||
return BOM_EESCHEMA; }
|
||||
<BOM>"|"[^\n]* { if (hash == 1)
|
||||
bom_parse_line(yytext); }
|
||||
process_bom_line(yytext); }
|
||||
<BOM>"#End Cmp" { YY_FLUSH_BUFFER;
|
||||
return 0; }
|
||||
<BOM>#[^\n]* hash++;
|
||||
|
Loading…
Reference in New Issue
Block a user