diff ueda/unet-bind/starpoints.c @ 101:ffab0a4424ad

ueda: unet-bind program moved into sensibly named unet-bind subdir
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 29 Sep 2019 22:42:41 +0000
parents ueda/sverp-bind/starpoints.c@65a515c20db8
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ueda/unet-bind/starpoints.c	Sun Sep 29 22:42:41 2019 +0000
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "struct.h"
+
+extern struct instance *enter_instance();
+
+extern char *starpoints_file;
+
+struct outcomp *starpoint_list_head;
+static struct outcomp **global_tailp = &starpoint_list_head;
+
+process_starpoints_file()
+{
+	FILE *stream;
+	char linebuf[256];
+	int lineno;
+	register char *cp;
+	char *instname, *numstr;
+	int npins;
+	register struct instance *inst;
+	register struct outcomp *oc;
+
+	stream = fopen(starpoints_file, "r");
+	if (!stream) {
+		perror(starpoints_file);
+		exit(1);
+	}
+	for (lineno = 1; fgets(linebuf, sizeof linebuf, stream); lineno++) {
+		cp = index(linebuf, '\n');
+		if (!cp) {
+			fprintf(stderr,
+			"error: %s line %d is too long or unterminated\n",
+				starpoints_file, lineno);
+			exit(1);
+		}
+		*cp = '\0';
+		for (cp = linebuf; isspace(*cp); cp++)
+			;
+		if (*cp == '\0' || *cp == '#')
+			continue;
+		instname = cp;
+		while (*cp && !isspace(*cp))
+			cp++;
+		if (*cp)
+			*cp++ = '\0';
+		while (isspace(*cp))
+			cp++;
+		if (*cp == '\0' || *cp == '#') {
+npins_error:		fprintf(stderr,
+"error in %s line %d: expected number of pins after the instance name\n",
+				starpoints_file, lineno);
+			exit(1);
+		}
+		numstr = cp;
+		while (*cp && !isspace(*cp))
+			cp++;
+		if (*cp)
+			*cp++ = '\0';
+		if (!string_is_valid_decnum(numstr))
+			goto npins_error;
+		npins = atoi(numstr);
+		if (npins < 2) {
+			fprintf(stderr,
+		"error in %s line %d: a starpoint must have 2 or more pins\n",
+				starpoints_file, lineno);
+			exit(1);
+		}
+		inst = enter_instance(instname);
+		oc = (struct outcomp *)
+			malloc(sizeof(struct outcomp) +
+			       sizeof(struct pinconn *) * npins);
+		if (!oc) {
+			perror("malloc");
+			exit(1);
+		}
+		bzero(oc, sizeof(struct outcomp) +
+			  sizeof(struct pinconn *) * npins);
+		oc->name = inst->name;
+		oc->npins = npins;
+		oc->conn_array = (struct pinconn **)(oc + 1);
+		inst->outcomp = oc;
+		*global_tailp = oc;
+		global_tailp = &oc->next;
+	}
+	fclose(stream);
+}