changeset 143:7c0fd80782c8

unet2protel utility added
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 19 Sep 2020 23:46:46 +0000
parents 7bdce91da1a5
children ffadaa339478
files .hgignore ueda/unet-utils/Makefile ueda/unet-utils/unet2protel.c
diffstat 3 files changed, 175 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sat Sep 19 22:50:24 2020 +0000
+++ b/.hgignore	Sat Sep 19 23:46:46 2020 +0000
@@ -13,6 +13,7 @@
 ^ueda/unet-utils/unet-excise$
 ^ueda/unet-utils/unet2pads$
 ^ueda/unet-utils/unet2pcb$
+^ueda/unet-utils/unet2protel$
 ^ueda/unet-utils/unet2tedax$
 ^ueda/utils/cutelements$
 ^ueda/utils/instfileelem$
--- a/ueda/unet-utils/Makefile	Sat Sep 19 22:50:24 2020 +0000
+++ b/ueda/unet-utils/Makefile	Sat Sep 19 23:46:46 2020 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	unet-destar unet-excise unet2pads unet2pcb unet2tedax
+PROGS=	unet-destar unet-excise unet2pads unet2pcb unet2protel unet2tedax
 LIBUNET=../libunet/libunet.a
 BINDIR=	/usr/local/bin
 
@@ -19,4 +19,5 @@
 unet-excise:	unet-excise.o
 unet2pads:	unet2pads.o
 unet2pcb:	unet2pcb.o
+unet2protel:	unet2protel.o
 unet2tedax:	unet2tedax.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ueda/unet-utils/unet2protel.c	Sat Sep 19 23:46:46 2020 +0000
@@ -0,0 +1,172 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../libunet/unetrd.h"
+#include "../libunet/nethash.h"
+
+extern struct net *enter_net_object();
+extern struct net *find_net_by_name();
+extern struct net *net_list_head;
+
+static char *input_filename, *output_filename;
+static struct unetrd_state rdstate;
+static struct unetrd_out rdout;
+static FILE *outFILE;
+
+struct netextra {
+	struct	netmember *head;
+	struct	netmember **tailp;
+};
+
+struct netmember {
+	char	*name;
+	struct	netmember *next;
+};
+
+static void
+process_pin_connect(compname)
+	char *compname;
+{
+	register struct net *n;
+	register struct netextra *nx;
+	register struct netmember *nm;
+
+	n = find_net_by_name(rdout.connect_to_net);
+	nx = (struct netextra *)(n + 1);
+	nm = (struct netmember *) malloc(sizeof(struct netmember) +
+					 strlen(compname) +
+					 strlen(rdout.objname) + 2);
+	if (!nm) {
+		perror("malloc");
+		exit(1);
+	}
+	nm->name = (char *)(nm + 1);
+	sprintf(nm->name, "%s-%s", compname, rdout.objname);
+	nm->next = 0;
+	*nx->tailp = nm;
+	nx->tailp = &nm->next;
+}
+
+static void
+process_component()
+{
+	char compname[64];
+
+	strcpy(compname, 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:
+		case UNETOBJ_ATTR:
+			continue;
+		case UNETOBJ_PIN:
+			if (rdout.connect_to_net)
+				process_pin_connect(compname);
+			continue;
+		case UNETOBJ_PINMAP:
+			fprintf(stderr,
+	"%s line %d: PINMAP objects not expected in unet2protel input\n",
+				input_filename, rdstate.lineno);
+			exit(1);
+		default:
+			fprintf(stderr,
+		"%s line %d: object type %s unexpected in COMPONENT block\n",
+				input_filename, rdstate.lineno, rdout.keyword);
+			exit(1);
+		}
+	}
+}
+
+static void
+process_input_unet()
+{
+	struct net *n;
+	struct netextra *nx;
+
+	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:
+			n = enter_net_object(rdout.objname,
+						sizeof(struct netextra));
+			nx = (struct netextra *)(n + 1);
+			nx->head = 0;
+			nx->tailp = &nx->head;
+			continue;
+		case UNETOBJ_COMPONENT:
+			process_component();
+			continue;
+		case UNETOBJ_STARPOINT:
+			fprintf(stderr,
+"error: STARPOINT objects not expected in unet2protel 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);
+		}
+	}
+}
+
+static
+emit_net(net)
+	struct net *net;
+{
+	struct netextra *nx;
+	register struct netmember *nm;
+
+	nx = (struct netextra *)(net + 1);
+	fprintf(outFILE, "(\n%s\n", net->name);
+	for (nm = nx->head; nm; nm = nm->next)
+		fprintf(outFILE, "%s\n", nm->name);
+	fputs(")\n", outFILE);
+}
+
+static void
+generate_output()
+{
+	register struct net *n;
+
+	if (output_filename) {
+		outFILE = fopen(output_filename, "w");
+		if (!outFILE) {
+			perror(output_filename);
+			exit(1);
+		}
+	} else
+		outFILE = stdout;
+	for (n = net_list_head; n; n = n->nextinlist)
+		emit_net(n);
+	if (outFILE != stdout)
+		fclose(outFILE);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	if (argc < 2 || argc > 3) {
+		fprintf(stderr, "usage: %s input.unet [output-file]\n",
+			argv[0]);
+		exit(1);
+	}
+	input_filename = argv[1];
+	output_filename = argv[2];
+	process_input_unet();
+	generate_output();
+	exit(0);
+}