annotate ueda/libueda/readmcl.c @ 154:2328205328a9 default tip

m4-fp: WR-FPC 1mm pitch FFC/FPC connectors
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 25 Oct 2022 07:36:09 +0000
parents c91e7a30fab3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * This is the MCL parser for the uEDA suite.
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 */
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <stdio.h>
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <ctype.h>
2
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
7 #include <stdlib.h>
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
8 #include <string.h>
0
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "mcl.h"
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 extern char *copystr();
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 #define MAX_COMPS 1024
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 #define MAX_PARTDEFS 128
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 #define MAX_ATTRS 2048
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 #define MAX_REFDES_ON_LINE 16
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 char *MCLfile = "MCL";
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 /* the following vars capture the distilled output of the parser */
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 struct component components[MAX_COMPS], partdefs[MAX_PARTDEFS];
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 int ncomponents, npartdefs;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 static struct attrib attrs[MAX_ATTRS];
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 static int nattrs;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 /* the following static vars are used only in the reading & parsing process */
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 static FILE *mclf;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 static char line[1024]; /* size arbitrary, sizeof used in the code */
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 static int lineno;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 static struct component *curcomp;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 static char *curcomp_refdes[MAX_REFDES_ON_LINE];
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 static int curcomp_nrefdes;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35
2
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
36 static
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
37 setup_partdef(np)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
38 register char *np;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
39 {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
40 register char *cp;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
41
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
42 while (isspace(*np))
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
43 np++;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
44 cp = index(np, ':');
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
45 if (!cp || cp == np || cp[1]) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
46 fprintf(stderr, "%s: line %d: invalid part definition\n",
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
47 MCLfile, lineno);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
48 exit(1);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
49 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
50 *cp = '\0';
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
51 if (npartdefs >= MAX_PARTDEFS) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
52 fprintf(stderr, "%s: line %d: too many part definitions\n",
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
53 MCLfile, lineno);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
54 exit(1);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
55 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
56 curcomp = partdefs + npartdefs;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
57 curcomp->name = copystr(np);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
58 curcomp->attrs = attrs + nattrs;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
59 curcomp->nattrs = 0;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
60 npartdefs++;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
61 curcomp_nrefdes = 0;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
62 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
63
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
64 static
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
65 parse_refdes_list()
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
66 {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
67 int i;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
68 register char *cp, *np;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
69 register int c;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
70
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
71 for (cp = line, i = 0; ; ) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
72 if (!isupper(*cp)) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
73 inv: fprintf(stderr, "%s: line %d: invalid refdes line\n",
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
74 MCLfile, lineno);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
75 exit(1);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
76 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
77 for (np = cp; isalnum(*cp); cp++)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
78 ;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
79 c = *cp;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
80 if (c != ':' && c != ',')
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
81 goto inv;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
82 *cp++ = '\0';
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
83 curcomp_refdes[i++] = copystr(np);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
84 if (c == ':')
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
85 break;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
86 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
87 curcomp_nrefdes = i;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
88 if (*cp)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
89 goto inv;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
90 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
91
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
92 static
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
93 clone_component()
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
94 {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
95 register int i;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
96 register struct component *newcomp;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
97
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
98 for (i = 1; i < curcomp_nrefdes; i++) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
99 if (ncomponents >= MAX_COMPS) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
100 fprintf(stderr, "%s: %s: too many components\n",
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
101 MCLfile, curcomp_refdes[i]);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
102 exit(1);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
103 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
104 newcomp = components + ncomponents;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
105 bcopy(curcomp, newcomp, sizeof(struct component));
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
106 newcomp->name = curcomp_refdes[i];
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
107 ncomponents++;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
108 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
109 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
110
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
111 static
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
112 finish_component()
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
113 {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
114 extern char *get_comp_attr();
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
115
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
116 if (curcomp_nrefdes == 0)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
117 return; /* nothing to do for part defs */
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
118 if (!curcomp->partdef &&
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
119 (get_comp_attr(curcomp, "manufacturer") &&
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
120 get_comp_attr(curcomp, "manufacturer_part_number") ||
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
121 get_comp_attr(curcomp, "bom_part_title")))
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
122 curcomp->partdef = curcomp; /* self-defines part */
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
123 if (curcomp_nrefdes > 1)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
124 clone_component();
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
125 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
126
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
127 static
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
128 handle_part_ref(partname)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
129 char *partname;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
130 {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
131 register struct component *part;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
132 register int i;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
133
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
134 if (curcomp_nrefdes == 0) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
135 fprintf(stderr,
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
136 "%s: line %d: can't use a part reference in a part definition!\n",
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
137 MCLfile, lineno);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
138 exit(1);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
139 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
140 if (!strcmp(partname, "none")) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
141 curcomp->partdef = NULL;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
142 return;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
143 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
144 if (!strcmp(partname, "yes")) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
145 curcomp->partdef = curcomp; /* self-defines the part */
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
146 return;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
147 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
148 for (part = partdefs, i = 0; i < npartdefs; part++, i++)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
149 if (!strcmp(part->name, partname)) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
150 gotit: curcomp->partdef = part;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
151 return;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
152 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
153 /* can also refer to a previous component that self-defines a part */
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
154 for (part = components, i = 0; i < ncomponents-1; part++, i++)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
155 if (!strcmp(part->name, partname)) {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
156 if (part->partdef == part)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
157 goto gotit;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
158 else {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
159 fprintf(stderr,
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
160 "%s: line %d: can't use %s as a part because it doesn't define a part\n",
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
161 MCLfile, lineno, partname);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
162 exit(1);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
163 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
164 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
165 fprintf(stderr, "%s: line %d: part %s not defined\n", MCLfile, lineno,
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
166 partname);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
167 exit(1);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
168 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
169
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
170 static
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
171 get_line()
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
172 {
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
173 register char *cp;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
174
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
175 if (fgets(line, sizeof line, mclf) == NULL)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
176 return(0);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
177 lineno++;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
178 /* strip trailing comments and whitespace */
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
179 cp = index(line, '#');
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
180 if (!cp)
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
181 cp = index(line, '\0');
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
182 while (cp > line && isspace(cp[-1]))
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
183 cp--;
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
184 *cp = '\0';
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
185 return(1);
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
186 }
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
187
0
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
188 read_MCL()
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
189 {
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
190 register char *cp, *name, *value;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
191
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
192 mclf = fopen(MCLfile, "r");
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
193 if (!mclf) {
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
194 perror(MCLfile);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
195 exit(1);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
196 }
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
197
2
c91e7a30fab3 ueda/libueda Linuxified
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 0
diff changeset
198 for (lineno = 0, curcomp = NULL; get_line(); ) {
0
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
199 /* ignore blank lines and comments */
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
200 if (line[0] == '\0' || line[0] == '#')
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
201 continue;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
202 if (!strncmp(line, "part", 4) && isspace(line[4])) {
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
203 finish_component();
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
204 setup_partdef(line + 5);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
205 } else if (!isspace(line[0])) { /* refdes */
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
206 finish_component();
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
207 parse_refdes_list();
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
208 if (ncomponents >= MAX_COMPS) {
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
209 fprintf(stderr,
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
210 "%s: line %d: too many components\n",
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
211 MCLfile, lineno);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
212 exit(1);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
213 }
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
214 curcomp = components + ncomponents;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
215 curcomp->name = curcomp_refdes[0];
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
216 curcomp->attrs = attrs + nattrs;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
217 curcomp->nattrs = 0;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
218 ncomponents++;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
219 } else { /* attribute */
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
220 for (cp = line; isspace(*cp); cp++)
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
221 ;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
222 name = cp;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
223 cp = index(cp, '=');
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
224 if (!cp) {
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
225 invattr: fprintf(stderr,
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
226 "%s: line %d: invalid attribute line\n",
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
227 MCLfile, lineno);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
228 exit(1);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
229 }
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
230 *cp = '\0';
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
231 value = cp + 1;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
232 if (name[0] == '\0')
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
233 goto invattr;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
234 if (!curcomp) {
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
235 fprintf(stderr,
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
236 "%s: line %d: attribute listed without a component\n",
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
237 MCLfile, lineno);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
238 exit(1);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
239 }
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
240 if (value[0] == '\0') {
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
241 fprintf(stderr,
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
242 "%s: line %d: attribute must have a value\n",
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
243 MCLfile, lineno);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
244 exit(1);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
245 }
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
246 if (nattrs >= MAX_ATTRS) {
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
247 fprintf(stderr,
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
248 "%s: line %d: too many attributes\n",
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
249 MCLfile, lineno);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
250 exit(1);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
251 }
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
252 attrs[nattrs].name = copystr(name);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
253 attrs[nattrs].value = copystr(value);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
254 nattrs++;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
255 curcomp->nattrs++;
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
256 if (!strcmp(name, "part"))
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
257 handle_part_ref(value);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
258 }
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
259 }
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
260 fclose(mclf);
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
261 finish_component();
cd92449fdb51 initial import of ueda and ifctf-part-lib from ifctfvax CVS
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
262 }