view ueda/uschem-netlist/nlcomp.c @ 113:43a2bebe7f00

USB_CONN_1734035.fp: mask opening for non-plated holes
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Jun 2020 03:08:14 +0000
parents cd92449fdb51
children
line wrap: on
line source

#include <sys/types.h>
#include <stdio.h>
#include "../libueda/mcl.h"
#include "netlist.h"

extern char *malloc();

extern struct component components[];
extern int ncomponents;

extern char *get_comp_attr();

struct nlcomp *netlist_comps;

alloc_nlcomp_array()
{
	register int i;

	netlist_comps = (struct nlcomp *)
				malloc(sizeof(struct nlcomp) * ncomponents);
	if (!netlist_comps) {
		perror("malloc");
		exit(1);
	}
	bzero(netlist_comps, sizeof(struct nlcomp) * ncomponents);
	for (i = 0; i < ncomponents; i++) {
		netlist_comps[i].mclcomp = components + i;
		fill_nlcomp(netlist_comps + i);
	}
}

fill_nlcomp(nlc)
	register struct nlcomp *nlc;
{
	char *npins_attr;
	register int n;
	register struct pinconn **pintab;

	npins_attr = get_comp_attr(nlc->mclcomp, "npins");
	if (!npins_attr)
		return;
	n = atoi(npins_attr);
	if (n <= 0) {
		fprintf(stderr, "%s: invalid npins attribute\n",
			nlc->mclcomp->name);
		exit(1);
	}
	nlc->npins = n;
	pintab = (struct pinconn **) malloc(sizeof(struct pinconn *) * n);
	if (!pintab) {
		perror("malloc");
		exit(1);
	}
	bzero(pintab, sizeof(struct pinconn *) * n);
	nlc->pintab = pintab;
}

struct nlcomp *
mclcomp_to_nlcomp(comp)
	struct component *comp;
{
	return(netlist_comps + (comp - components));
}