FreeCalypso > hg > ueda-linux
comparison ueda/mclutils/shortbom.c @ 0:cd92449fdb51
initial import of ueda and ifctf-part-lib from ifctfvax CVS
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 20 Jul 2015 00:24:37 +0000 |
parents | |
children | d098f8548b44 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cd92449fdb51 |
---|---|
1 /* | |
2 * This program generates a "short" BOM from the MCL. | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <strings.h> | |
7 #include "../libueda/mcl.h" | |
8 | |
9 extern char *optarg; | |
10 extern char *malloc(); | |
11 | |
12 extern char *MCLfile; | |
13 extern struct component components[]; | |
14 extern int ncomponents; | |
15 extern char *get_comp_attr(); | |
16 extern struct component *find_partdef_by_name(); | |
17 | |
18 struct bomline { | |
19 char *refdes; | |
20 char *manuf; | |
21 char *partno; | |
22 char *description; | |
23 }; | |
24 | |
25 int column_sep_width = 2, tabbed; | |
26 int assembly; | |
27 struct bomline *bombuf; | |
28 int nbomlines; | |
29 char unknownstr[] = "unknown"; | |
30 int refdes_col_width, manuf_col_width, partno_col_width; | |
31 | |
32 do_cmdline_opts(argc, argv) | |
33 char **argv; | |
34 { | |
35 register int c; | |
36 | |
37 while ((c = getopt(argc, argv, "aM:p:s:t")) != EOF) | |
38 switch (c) { | |
39 case 'a': | |
40 assembly++; | |
41 break; | |
42 case 'M': | |
43 MCLfile = optarg; | |
44 break; | |
45 case 'p': | |
46 set_popopt_list(optarg); | |
47 break; | |
48 case 's': | |
49 column_sep_width = atoi(optarg); | |
50 break; | |
51 case 't': | |
52 tabbed++; | |
53 break; | |
54 default: | |
55 /* getopt prints the error message */ | |
56 exit(1); | |
57 } | |
58 } | |
59 | |
60 main(argc, argv) | |
61 char **argv; | |
62 { | |
63 do_cmdline_opts(argc, argv); | |
64 read_MCL(); | |
65 bombuf = (struct bomline *) | |
66 malloc(sizeof(struct bomline) * (ncomponents+1)); | |
67 if (!bombuf) { | |
68 perror("malloc"); | |
69 exit(1); | |
70 } | |
71 bombuf[0].refdes = "Refdes"; | |
72 bombuf[0].manuf = "Manuf"; | |
73 bombuf[0].partno = "Part #"; | |
74 bombuf[0].description = "Description"; | |
75 construct_bom(); | |
76 if (tabbed) | |
77 tabbed_output(); | |
78 else { | |
79 compute_col_widths(); | |
80 output(); | |
81 } | |
82 exit(0); | |
83 } | |
84 | |
85 construct_bom() | |
86 { | |
87 int c, i; | |
88 register struct component *comp, *part; | |
89 register char *attr; | |
90 | |
91 for (comp = components, c = 0, i = 1; c < ncomponents; comp++, c++) { | |
92 if (!check_component_popopt(comp)) | |
93 continue; | |
94 attr = get_comp_attr(comp, "part"); | |
95 if (attr && !strcmp(attr, "none")) | |
96 continue; | |
97 bombuf[i].refdes = comp->name; | |
98 if (assembly && (attr = get_comp_attr(comp, "socket"))) { | |
99 part = find_partdef_by_name(attr); | |
100 if (!part) { | |
101 fprintf(stderr, | |
102 "%s: socket part %s not found\n", | |
103 comp->name, attr); | |
104 continue; | |
105 } | |
106 } else | |
107 part = comp; | |
108 attr = get_comp_attr(part, "manufacturer"); | |
109 if (attr) | |
110 bombuf[i].manuf = attr; | |
111 else | |
112 bombuf[i].manuf = unknownstr; | |
113 if (attr = get_comp_attr(part, "manufacturer_part_number")) | |
114 bombuf[i].partno = attr; | |
115 else if (attr = get_comp_attr(part, "device")) | |
116 bombuf[i].partno = attr; | |
117 else | |
118 bombuf[i].partno = unknownstr; | |
119 bombuf[i].description = get_comp_attr(part, "description"); | |
120 i++; | |
121 } | |
122 nbomlines = i; | |
123 } | |
124 | |
125 compute_col_widths() | |
126 { | |
127 int c; | |
128 register int i; | |
129 register struct bomline *line; | |
130 | |
131 for (line = bombuf, c = 0; c < nbomlines; line++, c++) { | |
132 i = strlen(line->refdes); | |
133 if (i > refdes_col_width) | |
134 refdes_col_width = i; | |
135 i = strlen(line->manuf); | |
136 if (i > manuf_col_width) | |
137 manuf_col_width = i; | |
138 i = strlen(line->partno); | |
139 if (i > partno_col_width) | |
140 partno_col_width = i; | |
141 } | |
142 } | |
143 | |
144 output() | |
145 { | |
146 int c; | |
147 register int i; | |
148 register struct bomline *line; | |
149 | |
150 for (line = bombuf, c = 0; c < nbomlines; line++, c++) { | |
151 fputs(line->refdes, stdout); | |
152 i = refdes_col_width + column_sep_width - strlen(line->refdes); | |
153 while (i--) | |
154 putchar(' '); | |
155 fputs(line->manuf, stdout); | |
156 i = manuf_col_width + column_sep_width - strlen(line->manuf); | |
157 while (i--) | |
158 putchar(' '); | |
159 fputs(line->partno, stdout); | |
160 if (line->description) { | |
161 i = partno_col_width + column_sep_width - | |
162 strlen(line->partno); | |
163 while (i--) | |
164 putchar(' '); | |
165 fputs(line->description, stdout); | |
166 } | |
167 putchar('\n'); | |
168 } | |
169 } | |
170 | |
171 tabbed_output() | |
172 { | |
173 int c; | |
174 register struct bomline *line; | |
175 | |
176 for (line = bombuf+1, c = 1; c < nbomlines; line++, c++) { | |
177 printf("%s\t%s\t%s", line->refdes, line->manuf, line->partno); | |
178 if (line->description) | |
179 printf("\t%s", line->description); | |
180 putchar('\n'); | |
181 } | |
182 } |