comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:cd92449fdb51
1 /*
2 * Routines to help the schematic parser, mostly allocation of data
3 * structures.
4 */
5
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <ctype.h>
9 #include <strings.h>
10 #include "schemstruct.h"
11 #include "parserint.h"
12
13 extern char *malloc();
14
15 extern struct schem_parse_state schem_parse_state;
16
17 struct schemobj *
18 parser_alloc_obj(objtype)
19 {
20 register struct schemobj *obj;
21
22 obj = (struct schemobj *) malloc(sizeof(struct schemobj));
23 if (!obj) {
24 perror("malloc");
25 exit(1);
26 }
27 bzero(obj, sizeof(struct schemobj));
28 obj->obj_type = objtype;
29 obj->obj_lineno = schem_parse_state.lineno;
30 return(obj);
31 }
32
33 struct decoration *
34 parser_alloc_decor(type)
35 {
36 register struct decoration *dec;
37
38 dec = (struct decoration *) malloc(sizeof(struct decoration));
39 if (!dec) {
40 perror("malloc");
41 exit(1);
42 }
43 bzero(dec, sizeof(struct decoration));
44 dec->decor_type = type;
45 dec->decor_lineno = schem_parse_state.lineno;
46 return(dec);
47 }
48
49 struct netpoint *
50 parser_alloc_netpoint(type)
51 {
52 register struct netpoint *netpt;
53
54 netpt = (struct netpoint *) malloc(sizeof(struct netpoint));
55 if (!netpt) {
56 perror("malloc");
57 exit(1);
58 }
59 bzero(netpt, sizeof(struct netpoint));
60 netpt->netpt_type = type;
61 return(netpt);
62 }
63
64 parser_add_object(obj)
65 struct schemobj *obj;
66 {
67 schemobj_insert_before((struct schemobj *) schem_parse_state.schem,
68 obj);
69 }
70
71 /* drawing sizes for graphical schematics */
72
73 struct drawing_size_kwtab drawing_size_keywords[] = {
74 {"A", 11000, 8500},
75 {"B", 17000, 11000},
76 {"C", 22000, 17000},
77 {"D", 34000, 22000},
78 {"E", 44000, 34000},
79 {NULL, 0, 0}
80 };
81
82 struct xypair
83 parse_drawing_size_spec(str)
84 char *str;
85 {
86 struct drawing_size_kwtab *kwp;
87 struct xypair retval;
88 register char *cp, *np;
89
90 for (kwp = drawing_size_keywords; kwp->keyword; kwp++)
91 if (!strcmp(str, kwp->keyword)) {
92 retval.x = kwp->xdim;
93 retval.y = kwp->ydim;
94 return(retval);
95 }
96
97 cp = str;
98 if (!isdigit(*cp)) {
99 inv: rdschem_error("invalid drawing size specification");
100 exit(1);
101 }
102 for (np = cp; isdigit(*cp); cp++)
103 ;
104 if (*cp++ != 'x')
105 goto inv;
106 retval.x = atoi(np);
107 if (!isdigit(*cp))
108 goto inv;
109 for (np = cp; isdigit(*cp); cp++)
110 ;
111 if (*cp)
112 goto inv;
113 retval.y = atoi(np);
114 return(retval);
115 }