FreeCalypso > hg > ueda-linux
comparison ueda/mclutils/csvbom.c @ 84:422385f10084
ueda-csvbom utility written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 23 Feb 2017 19:55:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
83:88cdef7e6b1b | 84:422385f10084 |
---|---|
1 /* | |
2 * This program generates a BOM in CSV format whose content is a subset | |
3 * of what is generated by ueda-mkbom; it is intended for passing BOM | |
4 * information to assembly shops who would then import into M$ Excel. | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <unistd.h> | |
12 #include "../libueda/mcl.h" | |
13 #include "bomstruct.h" | |
14 | |
15 extern char *MCLfile; | |
16 extern char *get_comp_attr(), *get_comp_multiattr(); | |
17 | |
18 int check_completeness, refdes_lists = 1; | |
19 struct bompart *bomhead; | |
20 | |
21 do_cmdline_opts(argc, argv) | |
22 char **argv; | |
23 { | |
24 register int c; | |
25 | |
26 while ((c = getopt(argc, argv, "cM:p:")) != EOF) | |
27 switch (c) { | |
28 case 'c': | |
29 check_completeness++; | |
30 break; | |
31 case 'M': | |
32 MCLfile = optarg; | |
33 break; | |
34 case 'p': | |
35 set_popopt_list(optarg); | |
36 break; | |
37 default: | |
38 /* getopt prints the error message */ | |
39 exit(1); | |
40 } | |
41 } | |
42 | |
43 main(argc, argv) | |
44 char **argv; | |
45 { | |
46 do_cmdline_opts(argc, argv); | |
47 read_MCL(); | |
48 tally_parts(); | |
49 output(); | |
50 exit(0); | |
51 } | |
52 | |
53 output() | |
54 { | |
55 register struct component *part; | |
56 register struct bompart *bp; | |
57 register char *attr; | |
58 static char unknownstr[] = "unknown"; | |
59 | |
60 puts("Manufacturer,Part number,Description,Qty,Refdes list"); | |
61 | |
62 for (bp = bomhead; bp; bp = bp->next) { | |
63 part = bp->part; | |
64 attr = get_comp_attr(part, "manufacturer"); | |
65 if (attr) | |
66 emit_csv_string(attr); | |
67 else | |
68 emit_csv_string(unknownstr); | |
69 putchar(','); | |
70 if (attr = get_comp_attr(part, "manufacturer_part_number")) | |
71 emit_csv_string(attr); | |
72 else if (attr = get_comp_attr(part, "device")) | |
73 emit_csv_string(attr); | |
74 else | |
75 emit_csv_string(unknownstr); | |
76 putchar(','); | |
77 if (attr = get_comp_attr(part, "description")) | |
78 emit_csv_string(attr); | |
79 printf(",%d,", bp->qty); | |
80 emit_refdes_list(bp->refdeslist); | |
81 putchar('\n'); | |
82 } | |
83 } | |
84 | |
85 emit_csv_string(str) | |
86 char *str; | |
87 { | |
88 char *cp; | |
89 int c; | |
90 | |
91 if (!index(str, ',') && !index(str, '"')) { | |
92 fputs(str, stdout); | |
93 return; | |
94 } | |
95 putchar('"'); | |
96 for (cp = str; c = *cp++; ) { | |
97 if (c == '"') | |
98 putchar(c); | |
99 putchar(c); | |
100 } | |
101 putchar('"'); | |
102 } | |
103 | |
104 emit_refdes_list(le) | |
105 register struct refdeslist *le; | |
106 { | |
107 putchar('"'); | |
108 for (; le; le = le->next) { | |
109 printf("%s", le->first); | |
110 if (le->last != le->first) | |
111 printf("-%s", le->last); | |
112 if (le->next) | |
113 putchar(','); | |
114 } | |
115 putchar('"'); | |
116 } |