annotate ueda/libunet/unetrd.c @ 54:a930e05cf908

pads2gpcb/decals.c: silk circle extraction implemented
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sun, 31 Jan 2016 01:57:38 +0000
parents 33e4c4cdf493
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module provides library functions for reading and parsing
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 * netlist files in our unet format.
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4 */
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <ctype.h>
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "unetrd.h"
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 open_unet_input_file(filename, state)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 char *filename;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 struct unetrd_state *state;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 state->filename = filename;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 state->stream = fopen(filename, "r");
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 if (!state->stream) {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 perror(filename);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 state->lineno = 0;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 static void
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 handle_name_only(state, out, rest)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 struct unetrd_state *state;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 struct unetrd_out *out;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 char *rest;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 char *cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33
20
dda8e455c863 unet-bind works to the point of reporting unbound instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 18
diff changeset
34 for (cp = rest; isspace(*cp); cp++)
9
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 ;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 if (*cp == '\0' || *cp == '#') {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 fprintf(stderr, "%s line %d: a name is expected after %s\n",
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 state->filename, state->lineno, out->keyword);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 out->objname = cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 while (*cp && !isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 if (*cp)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45 *cp++ = '\0';
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 while (isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 if (*cp && *cp != '#') {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 fprintf(stderr,
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50 "%s line %d: unexpected extra fields on %s line\n",
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51 state->filename, state->lineno, out->keyword);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 static void
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
57 handle_component_opening(state, out, rest)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
58 struct unetrd_state *state;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
59 struct unetrd_out *out;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
60 char *rest;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
61 {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
62 char *cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
63
20
dda8e455c863 unet-bind works to the point of reporting unbound instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 18
diff changeset
64 for (cp = rest; isspace(*cp); cp++)
9
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
65 ;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
66 if (*cp == '\0' || *cp == '#') {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
67 fprintf(stderr, "%s line %d: a name is expected after %s\n",
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
68 state->filename, state->lineno, out->keyword);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
69 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
70 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
71 out->objname = cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
72 while (*cp && !isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
73 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
74 if (*cp)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
75 *cp++ = '\0';
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
76 while (isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
77 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
78 if (*cp != '{') {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
79 fprintf(stderr,
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
80 "%s line %d: expected '{' at the end of %s line\n",
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
81 state->filename, state->lineno, out->keyword);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
82 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
83 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
84 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
85
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
86 static void
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
87 handle_pin_line(state, out, rest)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
88 struct unetrd_state *state;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
89 struct unetrd_out *out;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
90 char *rest;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
91 {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
92 char *cp = rest, *fields[3];
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
93 int i;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
94
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
95 for (i = 0; i < 3; i++) {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
96 while (isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
97 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
98 if (*cp == '\0' || *cp == '#') {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
99 error: fprintf(stderr,
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
100 "%s line %d: invalid syntax on %s line\n",
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
101 state->filename, state->lineno, out->keyword);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
102 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
103 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
104 fields[i] = cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
105 while (*cp && !isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
106 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
107 if (*cp)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
108 *cp++ = '\0';
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
109 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
110 out->objname = fields[0];
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
111 if (strcmp(fields[1], "="))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
112 goto error;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
113 if (!strcmp(fields[2], "NET")) {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
114 while (isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
115 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
116 if (*cp == '\0' || *cp == '#')
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
117 goto error;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
118 out->connect_to_net = cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
119 while (*cp && !isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
120 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
121 if (*cp)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
122 *cp++ = '\0';
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
123 } else if (!strcmp(fields[2], "NC")) {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
124 out->connect_to_net = 0;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
125 while (isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
126 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
127 if (*cp++ != '(')
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
128 goto error;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
129 out->nc_comment = cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
130 while (*cp && *cp != ')')
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
131 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
132 if (*cp != ')')
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
133 goto error;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
134 *cp++ = '\0';
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
135 } else
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
136 goto error;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
137 while (isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
138 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
139 if (*cp && *cp != '#') {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
140 fprintf(stderr,
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
141 "%s line %d: unexpected extra fields on %s line\n",
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
142 state->filename, state->lineno, out->keyword);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
143 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
144 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
145 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
146
28
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
147 static void
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
148 handle_attr(state, out, rest)
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
149 struct unetrd_state *state;
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
150 struct unetrd_out *out;
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
151 char *rest;
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
152 {
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
153 char *cp;
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
154
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
155 for (cp = rest; isspace(*cp); cp++)
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
156 ;
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
157 if (*cp == '\0' || *cp == '#') {
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
158 error: fprintf(stderr, "%s line %d: invalid syntax on ATTR line\n",
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
159 state->filename, state->lineno);
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
160 exit(1);
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
161 }
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
162 out->objname = cp;
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
163 cp = index(cp, '=');
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
164 if (!cp)
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
165 goto error;
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
166 *cp++ = '\0';
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
167 out->attr_value = cp;
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
168 }
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
169
9
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
170 static struct objmap {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
171 char *keyword;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
172 int typecode;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
173 void (*handler)();
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
174 } objmap[] = {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
175 {"}", UNETOBJ_CLOSINGBRACE, 0},
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
176 {"NET", UNETOBJ_NET, handle_name_only},
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
177 {"COMPONENT", UNETOBJ_COMPONENT, handle_component_opening},
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
178 {"STARPOINT", UNETOBJ_STARPOINT, handle_component_opening},
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
179 {"PRIMITIVE", UNETOBJ_PRIMITIVE, handle_name_only},
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
180 {"ALTNAME", UNETOBJ_ALTNAME, handle_name_only},
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
181 {"PIN", UNETOBJ_PIN, handle_pin_line},
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
182 {"PINMAP", UNETOBJ_PINMAP, handle_pin_line},
28
33e4c4cdf493 libunet: reading of ATTR lines implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 20
diff changeset
183 {"ATTR", UNETOBJ_ATTR, handle_attr},
9
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
184 {0, 0, 0}
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
185 };
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
186
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
187 read_unet_line(state, out)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
188 struct unetrd_state *state;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
189 struct unetrd_out *out;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
190 {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
191 static char linebuf[256];
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
192 char *cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
193 struct objmap *tp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
194
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
195 /* read lines until we get a non-empty, non-comment line or EOF */
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
196 for (;;) {
18
52000ae7a6cf ueda/libunet/unetrd.c: close the stdio stream on EOF
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 9
diff changeset
197 if (!fgets(linebuf, sizeof linebuf, state->stream)) {
52000ae7a6cf ueda/libunet/unetrd.c: close the stdio stream on EOF
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 9
diff changeset
198 fclose(state->stream);
9
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
199 return(0);
18
52000ae7a6cf ueda/libunet/unetrd.c: close the stdio stream on EOF
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 9
diff changeset
200 }
9
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
201 state->lineno++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
202 cp = index(linebuf, '\n');
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
203 if (!cp) {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
204 fprintf(stderr,
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
205 "error: %s line %d is too long or unterminated\n",
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
206 state->filename, state->lineno);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
207 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
208 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
209 *cp = '\0';
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
210 for (cp = linebuf; isspace(*cp); cp++)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
211 ;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
212 if (*cp && *cp != '#')
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
213 break;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
214 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
215 out->keyword = cp;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
216 while (*cp && !isspace(*cp))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
217 cp++;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
218 if (*cp)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
219 *cp++ = '\0';
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
220 for (tp = objmap; tp->keyword; tp++)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
221 if (!strcmp(tp->keyword, out->keyword))
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
222 break;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
223 if (!tp->keyword) {
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
224 fprintf(stderr, "%s line %d: object type \"%s\" unknown\n",
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
225 state->filename, state->lineno, out->keyword);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
226 exit(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
227 }
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
228 out->typecode = tp->typecode;
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
229 if (tp->handler)
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
230 tp->handler(state, out, cp);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
231 return(1);
faeb83c43f1c libunet started
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
232 }