1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-06-28 22:01:40 +03:00

b2/: add parsing of part inventories (WIP)

Also simplify representation of packaging variants.
This commit is contained in:
Werner Almesberger 2012-04-30 20:03:10 -03:00
parent 1394c6b61c
commit e99a9f4705
6 changed files with 154 additions and 9 deletions

2
b2/INV Normal file
View File

@ -0,0 +1,2 @@
FOO R101X CT 1234 1 USD 0 1 0.1 10 0.8 100 6
FOO R101X-T TR 1234 3000 USD 0 3000 13

10
b2/db.c
View File

@ -158,6 +158,16 @@ void part_finalize(struct part *part, const struct action *act)
}
void part_add_stock(struct part *part, struct stock *stock)
{
if (!part->stock) {
part->stock = stock;
return;
}
yyerrorf("part %s %s already has stock", part->domain, part->name);
}
void part_dump(FILE *file, const struct part *part)
{
const struct param *p;

44
b2/db.h
View File

@ -28,28 +28,57 @@ struct currency {
struct currency *next;
};
/*
* If quantity increases, next entry is next higher discount.
* If quantity decreases, next entries are prices after reaching the large
* quantity.
*
* Examples:
*
* An order of 12 units with the prices below
*
* a) 1 0.5 10 4.0 100 30.0
* b) 1 0.5 10 4.0 1 0.4 100 30.0
*
* would cost
*
* a) 1*4.0+2*0.5 = 5.0
* b) 1*4.0+2*0.4 = 4.8
*/
struct price {
int qty; /* order quantity */
double value; /* per quantity cost */
const struct currency *curr;
int fract; /* 0 if > qty at same price; 1 if multiples of qty */
struct price *next; /* next lower qty */
struct price *next; /* next qty */
};
struct provider {
const char *name;
double shipping; /* S&H cost */
double minimum; /* minimum order */
double minimum; /* value of minimum order, before S&H */
const struct currency *curr;
struct provider *next;
};
/*
* Handling of multiple forms of packaging:
*
* - category is a keyword that identifies the packaging type, e.g.,
* T for tape/tray, MAN for manual feeding, etc.
* - a query can be constrained to a set of categories
* - conversion options (e.g., "Digi-Reel") can be expressed as additional
* entries
*
* @@@ To do: shared availability
*/
struct stock {
const char *cat; /* category */
int avail; /* items in stock */
int package; /* "natural" quantity (reel, tray, bag, etc.) */
struct price *manual; /* single parts, for manual assembly only */
double reeling; /* cost of converting "manual" to "fab"; <0 if n/a */
struct price *fab; /* for automated assembly */
const struct currency *curr;
double add; /* additive element of cost */
struct price *price;
} stock;
struct part {
@ -66,6 +95,7 @@ struct part *part_lookup(const char *domain, const char *name);
struct part *part_add(const char *domain, const char *name);
void part_alias(struct part *a, struct part *b);
void part_finalize(struct part *part, const struct action *act);
void part_add_stock(struct part *part, struct stock *stock);
void part_dump(FILE *file, const struct part *part);
#endif /* !DB_H */

View File

@ -15,6 +15,7 @@
void parse_hierarchy(void);
void parse_characteristics(void);
void parse_inventory(void);
void yywarnf(const char *fmt, ...);
void yyerrorf(const char *fmt, ...);

View File

@ -44,6 +44,15 @@ void parse_characteristics(void)
yyparse();
}
void parse_inventory(void)
{
start_token = START_INVENTORY;
expose_nl = 1;
lineno = 1;
yyparse();
}
%}

View File

@ -64,6 +64,8 @@ static const struct field *top_field(void)
%union {
const char *s;
int num;
double fnum;
struct equiv *equiv;
struct names *names;
struct format *format;
@ -74,13 +76,17 @@ static const struct field *top_field(void)
struct action act;
struct part *part;
struct param *param;
struct price *price;
struct stock *stock;
};
%token START_HIERARCHY START_CHAR
%token START_HIERARCHY START_CHAR START_INVENTORY
%token TOK_LE TOK_GE TOK_NL
%token <s> WORD
%type <num> int
%type <fnum> float
%type <equiv> nameqs
%type <names> names nameq
%type <format> format
@ -89,16 +95,23 @@ static const struct field *top_field(void)
%type <sel> selectors
%type <cond> conditions condition
%type <act> opt_wildcard action
%type <part> part
%type <part> part inventory_item
%type <param> param params
%type <price> prices price
%type <stock> stock
%%
all:
START_HIERARCHY hierarchy
| START_CHAR characteristics
| START_INVENTORY inventory
;
/* ----- Characteristics hierarchy ----------------------------------------- */
hierarchy:
nameset hierarchy
| action
@ -349,6 +362,10 @@ format:
}
;
/* ----- Part characteristics --------------------------------------------- */
characteristics:
| TOK_NL
| part characteristics
@ -389,3 +406,79 @@ param:
$$->value.u.name = $3;
}
;
/* ----- Part inventory ---------------------------------------------------- */
inventory:
| TOK_NL
| inventory_item inventory
;
inventory_item:
WORD WORD stock TOK_NL
{
$$ = part_lookup($1, $2);
if (!$$)
$$ = part_add($1, $2);
part_add_stock($$, $3);
}
;
stock:
WORD int int WORD float prices
{
$$ = alloc_type(struct stock);
$$->cat = $1;
$$->avail = $2;
$$->package = $3;
$$->curr = NULL; /* @@@ later -- currency($4); */
$$->add = $5;
$$->price = $6;
}
;
prices:
price
{
$$ = $1;
}
| price prices
{
$$ = $1;
$$->next = $2;
}
;
price:
int float
{
$$ = alloc_type(struct price);
$$->qty = $1;
$$->value = $2;
$$->next = NULL;
}
;
int:
WORD
{
char *end;
$$ = strtol($1, &end, 10);
if (*end)
yyerrorf("\"%s\" is not an integer", $1);
}
;
float:
WORD
{
char *end;
$$ = strtod($1, &end);
if (*end)
yyerrorf("\"%s\" is not a number", $1);
}
;