diff ueda/libuschem/parser_assist.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/parser_assist.c	Mon Jul 20 00:24:37 2015 +0000
@@ -0,0 +1,115 @@
+/*
+ * Routines to help the schematic parser, mostly allocation of data
+ * structures.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <strings.h>
+#include "schemstruct.h"
+#include "parserint.h"
+
+extern char *malloc();
+
+extern struct schem_parse_state schem_parse_state;
+
+struct schemobj *
+parser_alloc_obj(objtype)
+{
+	register struct schemobj *obj;
+
+	obj = (struct schemobj *) malloc(sizeof(struct schemobj));
+	if (!obj) {
+		perror("malloc");
+		exit(1);
+	}
+	bzero(obj, sizeof(struct schemobj));
+	obj->obj_type = objtype;
+	obj->obj_lineno = schem_parse_state.lineno;
+	return(obj);
+}
+
+struct decoration *
+parser_alloc_decor(type)
+{
+	register struct decoration *dec;
+
+	dec = (struct decoration *) malloc(sizeof(struct decoration));
+	if (!dec) {
+		perror("malloc");
+		exit(1);
+	}
+	bzero(dec, sizeof(struct decoration));
+	dec->decor_type = type;
+	dec->decor_lineno = schem_parse_state.lineno;
+	return(dec);
+}
+
+struct netpoint *
+parser_alloc_netpoint(type)
+{
+	register struct netpoint *netpt;
+
+	netpt = (struct netpoint *) malloc(sizeof(struct netpoint));
+	if (!netpt) {
+		perror("malloc");
+		exit(1);
+	}
+	bzero(netpt, sizeof(struct netpoint));
+	netpt->netpt_type = type;
+	return(netpt);
+}
+
+parser_add_object(obj)
+	struct schemobj *obj;
+{
+	schemobj_insert_before((struct schemobj *) schem_parse_state.schem,
+				obj);
+}
+
+/* drawing sizes for graphical schematics */
+
+struct drawing_size_kwtab drawing_size_keywords[] = {
+	{"A", 11000,  8500},
+	{"B", 17000, 11000},
+	{"C", 22000, 17000},
+	{"D", 34000, 22000},
+	{"E", 44000, 34000},
+	{NULL, 0, 0}
+};
+
+struct xypair
+parse_drawing_size_spec(str)
+	char *str;
+{
+	struct drawing_size_kwtab *kwp;
+	struct xypair retval;
+	register char *cp, *np;
+
+	for (kwp = drawing_size_keywords; kwp->keyword; kwp++)
+		if (!strcmp(str, kwp->keyword)) {
+			retval.x = kwp->xdim;
+			retval.y = kwp->ydim;
+			return(retval);
+		}
+
+	cp = str;
+	if (!isdigit(*cp)) {
+inv:		rdschem_error("invalid drawing size specification");
+		exit(1);
+	}
+	for (np = cp; isdigit(*cp); cp++)
+		;
+	if (*cp++ != 'x')
+		goto inv;
+	retval.x = atoi(np);
+	if (!isdigit(*cp))
+		goto inv;
+	for (np = cp; isdigit(*cp); cp++)
+		;
+	if (*cp)
+		goto inv;
+	retval.y = atoi(np);
+	return(retval);
+}