FreeCalypso > hg > ueda-linux
comparison ueda/mclutils/bomtally.c @ 83:88cdef7e6b1b
BOM tallying code factored out of ueda-mkbom
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 23 Feb 2017 19:27:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
82:20c6f84c75e7 | 83:88cdef7e6b1b |
---|---|
1 /* | |
2 * This code generates a tallied form of the BOM from the MCL, | |
3 * to be used for generation of various BOM output formats. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <unistd.h> | |
11 #include "../libueda/mcl.h" | |
12 #include "bomstruct.h" | |
13 | |
14 extern struct component components[]; | |
15 extern int ncomponents; | |
16 extern char *get_comp_attr(); | |
17 extern struct component *find_partdef_by_name(); | |
18 | |
19 extern int check_completeness, refdes_lists; | |
20 extern struct bompart *bomhead; | |
21 | |
22 tally_parts() | |
23 { | |
24 int c; | |
25 register struct component *comp; | |
26 register char *attr; | |
27 struct component *socket; | |
28 | |
29 for (comp = components, c = 0; c < ncomponents; comp++, c++) { | |
30 if (!check_component_popopt(comp)) | |
31 continue; | |
32 if (comp->partdef == NULL) { | |
33 attr = get_comp_attr(comp, "part"); | |
34 if (attr && !strcmp(attr, "none")) | |
35 continue; | |
36 if (check_completeness) | |
37 fprintf(stderr, "%s has no part defined\n", | |
38 comp->name); | |
39 continue; | |
40 } | |
41 add_part_to_bom(comp->partdef, comp->name); | |
42 attr = get_comp_attr(comp, "socket"); | |
43 if (attr) { | |
44 socket = find_partdef_by_name(attr); | |
45 if (socket) | |
46 add_part_to_bom(socket, comp->name); | |
47 else | |
48 fprintf(stderr, | |
49 "%s: socket part %s not found\n", | |
50 comp->name, attr); | |
51 } | |
52 } | |
53 } | |
54 | |
55 add_part_to_bom(part, refdes) | |
56 struct component *part; | |
57 char *refdes; | |
58 { | |
59 register struct bompart *bp, **bpp; | |
60 | |
61 for (bpp = &bomhead; bp = *bpp; bpp = &bp->next) | |
62 if (bp->part == part) { | |
63 bp->qty++; | |
64 if (refdes_lists) | |
65 add_refdes_to_bompart(bp, refdes); | |
66 return; | |
67 } | |
68 /* new part */ | |
69 bp = (struct bompart *) malloc(sizeof(struct bompart)); | |
70 if (bp == NULL) { | |
71 perror("malloc"); | |
72 exit(1); | |
73 } | |
74 bp->part = part; | |
75 bp->qty = 1; | |
76 bp->next = NULL; | |
77 bp->refdeslist = NULL; | |
78 *bpp = bp; | |
79 if (refdes_lists) | |
80 add_refdes_to_bompart(bp, refdes); | |
81 } | |
82 | |
83 add_refdes_to_bompart(bp, refdes) | |
84 struct bompart *bp; | |
85 char *refdes; | |
86 { | |
87 register struct refdeslist *le, **lep; | |
88 | |
89 if (!bp->refdeslist) { | |
90 lep = &bp->refdeslist; | |
91 goto add_new; | |
92 } | |
93 for (le = bp->refdeslist; le->next; le = le->next) | |
94 ; | |
95 if (is_refdes_sequential(le->last, refdes)) { | |
96 le->last = refdes; | |
97 return(1); | |
98 } | |
99 lep = &le->next; | |
100 add_new: | |
101 le = (struct refdeslist *) malloc(sizeof(struct refdeslist)); | |
102 if (!le) { | |
103 perror("malloc"); | |
104 exit(1); | |
105 } | |
106 le->first = refdes; | |
107 le->last = refdes; | |
108 le->next = NULL; | |
109 *lep = le; | |
110 return(0); | |
111 } |