FreeCalypso > hg > ueda-linux
view ueda/libuschem/parser_assist.c @ 139:bf188727e606
donl-rename-parts reader: no tEDAx-style escapes
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 07 Sep 2020 04:25:11 +0000 |
parents | cd92449fdb51 |
children |
line wrap: on
line source
/* * 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); }