diff ueda/libuschem/pinref.c @ 0:cd92449fdb51

initial import of ueda and ifctf-part-lib from ifctfvax CVS
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 20 Jul 2015 00:24:37 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ueda/libuschem/pinref.c	Mon Jul 20 00:24:37 2015 +0000
@@ -0,0 +1,56 @@
+/*
+ * pin name reference parsing
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <ctype.h>
+#include "schemstruct.h"
+
+extern struct schemobj *find_component_instance();
+
+parse_pin_nameref(schem, lineno, nameref, compp, soughtpin, bynum)
+	struct schem *schem;
+	int lineno;
+	char *nameref;
+	struct schemobj **compp;
+	char **soughtpin;
+	int *bynum;
+{
+	register char *cp;
+	char chsave;
+	register struct schemobj *comp;
+
+	cp = nameref;
+	if (!isalnum(*cp)) {
+inv:		fprintf(stderr,
+		"%s: line %d: \"%s\" is not a valid pin name reference\n",
+			schem->orig_filename, lineno, nameref);
+		return(-1);
+	}
+	while (isalnum(*cp))
+		cp++;
+	chsave = *cp;
+	switch (*cp) {
+	case '.':
+		*bynum = 0;
+		break;
+	case '-':
+		*bynum = 1;
+		break;
+	default:
+		goto inv;
+	}
+	*cp = '\0';
+	comp = find_component_instance(schem, nameref);
+	if (!comp)
+		fprintf(stderr,
+			"%s: line %d: component instance %s not found\n",
+			schem->orig_filename, lineno, nameref);
+	*cp++ = chsave;
+	*compp = comp;
+	if (!isgraph(*cp))
+		goto inv;
+	*soughtpin = cp;
+	return(comp ? 0 : -1);
+}