mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-12-22 19:39:54 +02:00
b2/: add provider database (WIP)
This commit is contained in:
parent
c3a68453d0
commit
82d532e4a2
@ -83,4 +83,4 @@ spotless: clean
|
||||
# ----- Experiments -----------------------------------------------------------
|
||||
|
||||
try:
|
||||
$(VALGRIND) ./boom HIERARCHY -c CHAR -x CURR -i INV
|
||||
$(VALGRIND) ./boom HIERARCHY -c CHAR -x CURR -p PROVIDER -i INV
|
||||
|
1
b2/PROVIDER
Normal file
1
b2/PROVIDER
Normal file
@ -0,0 +1 @@
|
||||
FOO USD 0 0
|
@ -43,6 +43,7 @@ static void usage(const char *name)
|
||||
" -c characteristics\n"
|
||||
" -i inventory\n"
|
||||
" -x currency exchange\n"
|
||||
" -p providers\n"
|
||||
, name);
|
||||
exit(1);
|
||||
}
|
||||
@ -61,6 +62,8 @@ int main(int argc, char **argv)
|
||||
parse = parse_inventory;
|
||||
else if (!strcmp(argv[i], "-x"))
|
||||
parse = parse_currencies;
|
||||
else if (!strcmp(argv[i], "-p"))
|
||||
parse = parse_providers;
|
||||
else
|
||||
usage(*argv);
|
||||
} else {
|
||||
|
39
b2/db.c
39
b2/db.c
@ -257,3 +257,42 @@ void currency_exchange(struct currency *from, const struct currency *to,
|
||||
(*ex)->rate = rate;
|
||||
(*ex)->next = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* ----- Provider database ------------------------------------------------- */
|
||||
|
||||
|
||||
static struct provider *providers = NULL;
|
||||
|
||||
|
||||
struct provider *provider_lookup(const char *name)
|
||||
{
|
||||
struct provider *p;
|
||||
|
||||
for (p = providers; p; p = p->next)
|
||||
if (p->name == name)
|
||||
break;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
struct provider *provider_add(const char *name)
|
||||
{
|
||||
struct provider *p;
|
||||
|
||||
p = provider_lookup(name);
|
||||
if (p)
|
||||
return p;
|
||||
|
||||
p = alloc_type(struct provider);
|
||||
p->name = name;
|
||||
p->curr = NULL;
|
||||
p->shipping = 0;
|
||||
p->minimum = 0;
|
||||
p->next = providers;
|
||||
providers = p;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
5
b2/db.h
5
b2/db.h
@ -54,9 +54,9 @@ struct price {
|
||||
|
||||
struct provider {
|
||||
const char *name;
|
||||
const struct currency *curr;
|
||||
double shipping; /* S&H cost */
|
||||
double minimum; /* value of minimum order, before S&H */
|
||||
const struct currency *curr;
|
||||
struct provider *next;
|
||||
};
|
||||
|
||||
@ -105,4 +105,7 @@ struct currency *currency_add(const char *name);
|
||||
void currency_exchange(struct currency *from, const struct currency *to,
|
||||
double rate);
|
||||
|
||||
struct provider *provider_lookup(const char *name);
|
||||
struct provider *provider_add(const char *name);
|
||||
|
||||
#endif /* !DB_H */
|
||||
|
@ -17,6 +17,7 @@ void parse_hierarchy(void);
|
||||
void parse_characteristics(void);
|
||||
void parse_inventory(void);
|
||||
void parse_currencies(void);
|
||||
void parse_providers(void);
|
||||
|
||||
void yywarnf(const char *fmt, ...);
|
||||
void yyerrorf(const char *fmt, ...);
|
||||
|
10
b2/lang.l
10
b2/lang.l
@ -53,6 +53,7 @@ void parse_inventory(void)
|
||||
yyparse();
|
||||
}
|
||||
|
||||
|
||||
void parse_currencies(void)
|
||||
{
|
||||
start_token = START_EXCHANGE;
|
||||
@ -61,6 +62,15 @@ void parse_currencies(void)
|
||||
yyparse();
|
||||
}
|
||||
|
||||
|
||||
void parse_providers(void)
|
||||
{
|
||||
start_token = START_PROVIDERS;
|
||||
expose_nl = 1;
|
||||
lineno = 1;
|
||||
yyparse();
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
|
34
b2/lang.y
34
b2/lang.y
@ -80,11 +80,12 @@ static const struct field *top_field(void)
|
||||
struct param *param;
|
||||
struct price *price;
|
||||
struct stock *stock;
|
||||
struct provider *prov;
|
||||
};
|
||||
|
||||
|
||||
%token START_HIERARCHY START_CHAR START_INVENTORY
|
||||
%token START_EXCHANGE
|
||||
%token START_EXCHANGE START_PROVIDERS
|
||||
%token TOK_LE TOK_GE TOK_NL
|
||||
%token <s> WORD
|
||||
|
||||
@ -102,6 +103,7 @@ static const struct field *top_field(void)
|
||||
%type <param> param params
|
||||
%type <price> prices price
|
||||
%type <stock> stock
|
||||
%type <prov> providers provider
|
||||
|
||||
%%
|
||||
|
||||
@ -110,6 +112,7 @@ all:
|
||||
| START_CHAR characteristics
|
||||
| START_INVENTORY inventory
|
||||
| START_EXCHANGE exchange
|
||||
| START_PROVIDERS providers
|
||||
;
|
||||
|
||||
|
||||
@ -520,3 +523,32 @@ rate:
|
||||
currency_exchange(curr, to, $2);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
/* ----- Providers --------------------------------------------------------- */
|
||||
|
||||
|
||||
providers:
|
||||
{
|
||||
$$ = NULL;
|
||||
}
|
||||
| TOK_NL
|
||||
{
|
||||
$$ = NULL;
|
||||
}
|
||||
| provider providers
|
||||
{
|
||||
$$ = $1;
|
||||
$$->next = $2;
|
||||
}
|
||||
;
|
||||
|
||||
provider:
|
||||
WORD WORD float float TOK_NL
|
||||
{
|
||||
$$ = provider_add($1);
|
||||
$$->curr = currency_add($2);
|
||||
$$->shipping = $3;
|
||||
$$->minimum = $4;
|
||||
}
|
||||
;
|
||||
|
Loading…
Reference in New Issue
Block a user