view ueda/mclutils/csvattr.c @ 154:2328205328a9 default tip

m4-fp: WR-FPC 1mm pitch FFC/FPC connectors
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 25 Oct 2022 07:36:09 +0000
parents 125fc4ef7eb0
children
line wrap: on
line source

/*
 * This program generates a CSV output listing all components in their
 * MCL order and carrying a selected set of attributes as columns.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "../libueda/mcl.h"

extern char *MCLfile;
extern struct component components[];
extern int ncomponents;
extern char *get_comp_attr();

main(argc, argv)
	char **argv;
{
	extern int optind;
	register int c, ai;
	register struct component *comp;
	register char *attr;

	while ((c = getopt(argc, argv, "M:")) != EOF)
		switch (c) {
		case 'M':
			MCLfile = optarg;
			break;
		default:
			/* getopt prints the error message */
			exit(1);
		}

	read_MCL();
	/* emit CSV header */
	fputs("Refdes", stdout);
	for (ai = optind; ai < argc; ai++)
		printf(",%s", argv[ai]);
	putchar('\n');

	for (comp = components, c = 0; c < ncomponents; comp++, c++) {
		fputs(comp->name, stdout);
		for (ai = optind; ai < argc; ai++) {
			attr = get_comp_attr(comp, argv[ai]);
			if (!attr)
				attr = "";
			printf(",%s", attr);
		}
		putchar('\n');
	}
	exit(0);
}