changeset 84:422385f10084

ueda-csvbom utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 23 Feb 2017 19:55:51 +0000
parents 88cdef7e6b1b
children fd5de6e22f08
files .hgignore ueda/mclutils/Makefile ueda/mclutils/csvbom.c
diffstat 3 files changed, 122 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Feb 23 19:27:14 2017 +0000
+++ b/.hgignore	Thu Feb 23 19:55:51 2017 +0000
@@ -2,6 +2,7 @@
 
 \.[oa]$
 
+^ueda/mclutils/csvbom$
 ^ueda/mclutils/getfps$
 ^ueda/mclutils/mkbom$
 ^ueda/mclutils/shortbom$
--- a/ueda/mclutils/Makefile	Thu Feb 23 19:27:14 2017 +0000
+++ b/ueda/mclutils/Makefile	Thu Feb 23 19:55:51 2017 +0000
@@ -1,11 +1,14 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	getfps mkbom shortbom
+PROGS=	csvbom getfps mkbom shortbom
 LIBUEDA=../libueda/libueda.a
 BINDIR=	/usr/local/bin
 
 all:	${PROGS}
 
+csvbom:	csvbom.o bomtally.o seqrefdes.o ${LIBUEDA}
+	${CC} ${CFLAGS} -o $@ $@.o bomtally.o seqrefdes.o ${LIBUEDA}
+
 getfps:	getfps.o ${LIBUEDA}
 	${CC} ${CFLAGS} -o $@ $@.o ${LIBUEDA}
 
@@ -16,6 +19,7 @@
 	${CC} ${CFLAGS} -o $@ $@.o ${LIBUEDA}
 
 install:
+	install -c -o bin -g bin -m 755 csvbom ${BINDIR}/ueda-csvbom
 	install -c -o bin -g bin -m 755 getfps ${BINDIR}/ueda-getfps
 	install -c -o bin -g bin -m 755 mkbom ${BINDIR}/ueda-mkbom
 	install -c -o bin -g bin -m 755 shortbom ${BINDIR}/ueda-shortbom
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ueda/mclutils/csvbom.c	Thu Feb 23 19:55:51 2017 +0000
@@ -0,0 +1,116 @@
+/*
+ * This program generates a BOM in CSV format whose content is a subset
+ * of what is generated by ueda-mkbom; it is intended for passing BOM
+ * information to assembly shops who would then import into M$ Excel.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include "../libueda/mcl.h"
+#include "bomstruct.h"
+
+extern char *MCLfile;
+extern char *get_comp_attr(), *get_comp_multiattr();
+
+int check_completeness, refdes_lists = 1;
+struct bompart *bomhead;
+
+do_cmdline_opts(argc, argv)
+	char **argv;
+{
+	register int c;
+
+	while ((c = getopt(argc, argv, "cM:p:")) != EOF)
+		switch (c) {
+		case 'c':
+			check_completeness++;
+			break;
+		case 'M':
+			MCLfile = optarg;
+			break;
+		case 'p':
+			set_popopt_list(optarg);
+			break;
+		default:
+			/* getopt prints the error message */
+			exit(1);
+		}
+}
+
+main(argc, argv)
+	char **argv;
+{
+	do_cmdline_opts(argc, argv);
+	read_MCL();
+	tally_parts();
+	output();
+	exit(0);
+}
+
+output()
+{
+	register struct component *part;
+	register struct bompart *bp;
+	register char *attr;
+	static char unknownstr[] = "unknown";
+
+	puts("Manufacturer,Part number,Description,Qty,Refdes list");
+
+	for (bp = bomhead; bp; bp = bp->next) {
+		part = bp->part;
+		attr = get_comp_attr(part, "manufacturer");
+		if (attr)
+			emit_csv_string(attr);
+		else
+			emit_csv_string(unknownstr);
+		putchar(',');
+		if (attr = get_comp_attr(part, "manufacturer_part_number"))
+			emit_csv_string(attr);
+		else if (attr = get_comp_attr(part, "device"))
+			emit_csv_string(attr);
+		else
+			emit_csv_string(unknownstr);
+		putchar(',');
+		if (attr = get_comp_attr(part, "description"))
+			emit_csv_string(attr);
+		printf(",%d,", bp->qty);
+		emit_refdes_list(bp->refdeslist);
+		putchar('\n');
+	}
+}
+
+emit_csv_string(str)
+	char *str;
+{
+	char *cp;
+	int c;
+
+	if (!index(str, ',') && !index(str, '"')) {
+		fputs(str, stdout);
+		return;
+	}
+	putchar('"');
+	for (cp = str; c = *cp++; ) {
+		if (c == '"')
+			putchar(c);
+		putchar(c);
+	}
+	putchar('"');
+}
+
+emit_refdes_list(le)
+	register struct refdeslist *le;
+{
+	putchar('"');
+	for (; le; le = le->next) {
+		printf("%s", le->first);
+		if (le->last != le->first)
+			printf("-%s", le->last);
+		if (le->next)
+			putchar(',');
+	}
+	putchar('"');
+}