changeset 140:d3eb3790386d

netdiff: donl-netmatch put together
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Sep 2020 04:57:37 +0000
parents bf188727e606
children fddb020e9b68
files .hgignore netdiff/match/Makefile netdiff/match/main.c netdiff/match/rdpass.c netdiff/match/struct.h
diffstat 5 files changed, 212 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Sep 07 04:25:11 2020 +0000
+++ b/.hgignore	Mon Sep 07 04:57:37 2020 +0000
@@ -19,6 +19,7 @@
 ^netdiff/convert/pads2donl$
 ^netdiff/convert/protel2donl$
 ^netdiff/convert/tedax2donl$
+^netdiff/match/donl-netmatch$
 ^netdiff/renpart/donl-rename-parts$
 
 ^pads2gpcb/pads2gpcb$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netdiff/match/Makefile	Mon Sep 07 04:57:37 2020 +0000
@@ -0,0 +1,16 @@
+CC=	gcc
+CFLAGS=	-O2
+PROG=	donl-netmatch
+OBJS=	main.o rdpass.o
+BINDIR=	/usr/local/bin
+
+all:	${PROG}
+
+${PROG}:	${OBJS}
+	${CC} ${CFLAGS} -o $@ ${OBJS}
+
+install:
+	install -c -o bin -g bin -m 755 ${PROG} ${BINDIR}
+
+clean:
+	rm -f *.[ao] a.out core errs ${PROG}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netdiff/match/main.c	Mon Sep 07 04:57:37 2020 +0000
@@ -0,0 +1,67 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "struct.h"
+
+char *infnames[2];
+struct pin_info *database;
+
+write_diffs_report(outfile)
+	char *outfile;
+{
+	FILE *outf;
+	struct pin_info *p;
+
+	outf = fopen(outfile, "w");
+	if (!outf) {
+		perror(outfile);
+		exit(1);
+	}
+	for (p = database; p; p = p->next) {
+		if (p->netnames[0] && !p->netnames[1])
+			fprintf(outf, "Pin %s only in %s: net %s\n",
+				p->pin_name, infnames[0], p->netnames[0]);
+		if (!p->netnames[0] && p->netnames[1])
+			fprintf(outf, "Pin %s only in %s: net %s\n",
+				p->pin_name, infnames[1], p->netnames[1]);
+	}
+	fclose(outf);
+}
+
+write_matching_nets(outfile)
+	char *outfile;
+{
+	FILE *outf;
+	struct pin_info *p;
+
+	outf = fopen(outfile, "w");
+	if (!outf) {
+		perror(outfile);
+		exit(1);
+	}
+	for (p = database; p; p = p->next) {
+		if (!p->netnames[0] || !p->netnames[1])
+			continue;
+		fprintf(outf, "%s\t%s\n", p->netnames[0], p->netnames[1]);
+	}
+	fclose(outf);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	int i;
+
+	if (argc != 5) {
+		fprintf(stderr,
+			"usage: %s net1 net2 diffs-report matching-nets\n",
+			argv[0]);
+		exit(1);
+	}
+	infnames[0] = argv[1];
+	infnames[1] = argv[2];
+	for (i = 0; i < 2; i++)
+		read_pass(i);
+	write_diffs_report(argv[3]);
+	write_matching_nets(argv[4]);
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netdiff/match/rdpass.c	Mon Sep 07 04:57:37 2020 +0000
@@ -0,0 +1,123 @@
+#include <ctype.h>
+#include <string.h>
+#include <strings.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "struct.h"
+
+extern char *infnames[2];
+extern struct pin_info *database;
+
+#define	MAX_FIELDS	2
+
+static int pass;
+static FILE *inf;
+static char linebuf[512];
+static int lineno;
+static char *fields[MAX_FIELDS];
+static unsigned nfields;
+
+static void
+parse_into_fields()
+{
+	char *cp;
+
+	nfields = 0;
+	for (cp = linebuf; ; ) {
+		while (isspace(*cp))
+			cp++;
+		if (*cp == '\0' || *cp == '#')
+			break;
+		if (nfields >= MAX_FIELDS) {
+			fprintf(stderr, "%s line %d: too many fields\n",
+				infnames[pass], lineno);
+			exit(1);
+		}
+		fields[nfields++] = cp;
+		while (*cp && !isspace(*cp))
+			cp++;
+		if (*cp)
+			*cp++ = '\0';
+	}
+}
+
+static void
+existing_pin(p, netname)
+	struct pin_info *p;
+	char *netname;
+{
+	char *dp;
+
+	if (p->netnames[pass]) {
+		fprintf(stderr, "%s line %d: multiple nets to pin %s\n",
+			infnames[pass], lineno, p->pin_name);
+		exit(1);
+	}
+	dp = malloc(strlen(netname) + 1);
+	if (!dp) {
+		perror("malloc");
+		exit(1);
+	}
+	strcpy(dp, netname);
+	p->netnames[pass] = dp;
+}
+
+static void
+process_connect(netname, pinname)
+	char *netname, *pinname;
+{
+	struct pin_info *p, **pp;
+	char *dp;
+
+	for (pp = &database; p = *pp; pp = &p->next) {
+		if (!strcmp(p->pin_name, pinname)) {
+			existing_pin(p, netname);
+			return;
+		}
+	}
+	p = malloc(sizeof(struct pin_info) + strlen(netname) + strlen(pinname)
+			+ 2);
+	if (!p) {
+		perror("malloc");
+		exit(1);
+	}
+	bzero(p, sizeof(struct pin_info));
+	dp = (char *)(p + 1);
+	p->pin_name = dp;
+	strcpy(dp, pinname);
+	dp += strlen(pinname) + 1;
+	p->netnames[pass] = dp;
+	strcpy(dp, netname);
+	*pp = p;
+}
+
+static void
+process_line()
+{
+	parse_into_fields();
+	if (!nfields)
+		return;
+	if (nfields != 2) {
+		fprintf(stderr, "%s line %d: expected 2 fields\n",
+			infnames[pass], lineno);
+		exit(1);
+	}
+	process_connect(fields[0], fields[1]);
+}
+
+read_pass(pass_no)
+{
+	pass = pass_no;
+	inf = fopen(infnames[pass], "r");
+	if (!inf) {
+		perror(infnames[pass]);
+		exit(1);
+	}
+	lineno = 0;
+	while (fgets(linebuf, sizeof linebuf, inf)) {
+		lineno++;
+		process_line();
+	}
+	fclose(inf);
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netdiff/match/struct.h	Mon Sep 07 04:57:37 2020 +0000
@@ -0,0 +1,5 @@
+struct pin_info {
+	char	*pin_name;
+	char	*netnames[2];
+	struct	pin_info *next;
+};