annotate ueda/mclutils/csvbom.c @ 127:2da7374372a0

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