diff ueda/unet-utils/unet-excise.c @ 142:7bdce91da1a5

unet-excise utility added
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 19 Sep 2020 22:50:24 +0000
parents
children
line wrap: on
line diff
--- /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);
+}