changeset 142:7bdce91da1a5

unet-excise utility added
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 19 Sep 2020 22:50:24 +0000
parents fddb020e9b68
children 7c0fd80782c8
files .hgignore ueda/unet-utils/Makefile ueda/unet-utils/unet-excise.c
diffstat 3 files changed, 128 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Sep 07 05:13:35 2020 +0000
+++ b/.hgignore	Sat Sep 19 22:50:24 2020 +0000
@@ -10,6 +10,7 @@
 ^ueda/sverp/ueda-sverp$
 ^ueda/unet-bind/unet-bind$
 ^ueda/unet-utils/unet-destar$
+^ueda/unet-utils/unet-excise$
 ^ueda/unet-utils/unet2pads$
 ^ueda/unet-utils/unet2pcb$
 ^ueda/unet-utils/unet2tedax$
--- a/ueda/unet-utils/Makefile	Mon Sep 07 05:13:35 2020 +0000
+++ b/ueda/unet-utils/Makefile	Sat Sep 19 22:50:24 2020 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	unet-destar unet2pads unet2pcb unet2tedax
+PROGS=	unet-destar unet-excise unet2pads unet2pcb unet2tedax
 LIBUNET=../libunet/libunet.a
 BINDIR=	/usr/local/bin
 
@@ -16,6 +16,7 @@
 	rm -f *.[ao] a.out core errs ${PROGS}
 
 unet-destar:	unet-destar.o
+unet-excise:	unet-excise.o
 unet2pads:	unet2pads.o
 unet2pcb:	unet2pcb.o
 unet2tedax:	unet2tedax.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ueda/unet-utils/unet-excise.c	Sat Sep 19 22:50:24 2020 +0000
@@ -0,0 +1,125 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../libunet/unetrd.h"
+
+static char *input_filename;
+static char **excise_nets;
+static struct unetrd_state rdstate;
+static struct unetrd_out rdout;
+
+static void
+process_net()
+{
+	char **ap;
+
+	for (ap = excise_nets; *ap; ap++) {
+		if (!strcmp(*ap, rdout.objname)) {
+			printf("# net %s excised\n", *ap);
+			return;
+		}
+	}
+	printf("NET %s\n", rdout.objname);
+}
+
+static void
+process_component_pin()
+{
+	char **ap;
+
+	if (!rdout.connect_to_net) {
+		printf("  %s %s = NC (%s)\n", rdout.keyword, rdout.objname,
+			rdout.nc_comment);
+		return;
+	}
+	for (ap = excise_nets; *ap; ap++) {
+		if (!strcmp(*ap, rdout.connect_to_net)) {
+			printf("  %s %s = NC (net %s excised)\n",
+				rdout.keyword, rdout.objname, *ap);
+			return;
+		}
+	}
+	printf("  %s %s = NET %s\n", rdout.keyword, rdout.objname,
+		rdout.connect_to_net);
+}
+
+static void
+process_component()
+{
+	printf("\nCOMPONENT %s {\n", rdout.objname);
+	for (;;) {
+		if (!read_unet_line(&rdstate, &rdout)) {
+			fprintf(stderr, "%s error: EOF in COMPONENT block\n",
+				input_filename);
+			exit(1);
+		}
+		if (rdout.typecode == UNETOBJ_CLOSINGBRACE)
+			break;
+		switch(rdout.typecode) {
+		case UNETOBJ_PRIMITIVE:
+		case UNETOBJ_ALTNAME:
+			printf("  %s %s\n", rdout.keyword, rdout.objname);
+			continue;
+		case UNETOBJ_ATTR:
+			printf("  ATTR %s=%s\n", rdout.objname,
+				rdout.attr_value);
+			continue;
+		case UNETOBJ_PIN:
+		case UNETOBJ_PINMAP:
+			process_component_pin();
+			continue;
+		default:
+			fprintf(stderr,
+		"%s line %d: object type %s unexpected in COMPONENT block\n",
+				input_filename, rdstate.lineno, rdout.keyword);
+			exit(1);
+		}
+	}
+	puts("}");
+}
+
+static void
+process_input_unet()
+{
+	open_unet_input_file(input_filename, &rdstate);
+	while (read_unet_line(&rdstate, &rdout)) {
+		switch(rdout.typecode) {
+		case UNETOBJ_CLOSINGBRACE:
+			fprintf(stderr,
+		"%s line %d: unexpected '}' outside of component block\n",
+				input_filename, rdstate.lineno);
+			exit(1);
+		case UNETOBJ_NET:
+			process_net();
+			continue;
+		case UNETOBJ_COMPONENT:
+			process_component();
+			continue;
+		case UNETOBJ_STARPOINT:
+			fprintf(stderr,
+"error: STARPOINT objects not expected in unet-excise input (%s line %d)\n",
+				input_filename, rdstate.lineno);
+			exit(1);
+		default:
+			fprintf(stderr,
+				"%s line %d: unexpected object type %s\n",
+				input_filename, rdstate.lineno, rdout.keyword);
+			exit(1);
+		}
+	}
+}
+
+main(argc, argv)
+	char **argv;
+{
+	if (argc < 3) {
+		fprintf(stderr, "usage: %s input.unet excise-net[s]\n",
+			argv[0]);
+		exit(1);
+	}
+	input_filename = argv[1];
+	excise_nets = argv + 2;
+	process_input_unet();
+	exit(0);
+}