Deleted Added
full compact
config.y (111230) config.y (111582)
1%union {
2 char *str;
3 int val;
4 struct file_list *file;
5}
6
7%token ARCH
8%token COMMA
9%token CONFIG
10%token CPU
11%token DEVICE
1%union {
2 char *str;
3 int val;
4 struct file_list *file;
5}
6
7%token ARCH
8%token COMMA
9%token CONFIG
10%token CPU
11%token DEVICE
12%token NODEVICE
12%token ENV
13%token EQUALS
14%token HINTS
15%token IDENT
16%token MAXUSERS
13%token ENV
14%token EQUALS
15%token HINTS
16%token IDENT
17%token MAXUSERS
17%token NODEVICE
18%token PROFILE
19%token OPTIONS
18%token PROFILE
19%token OPTIONS
20%token NOOPTION
20%token MAKEOPTIONS
21%token MAKEOPTIONS
22%token NOMAKEOPTION
21%token SEMICOLON
22%token INCLUDE
23
24%token <str> ID
25%token <val> NUMBER
26
27%type <str> Save_id
28%type <str> Opt_value
29%type <str> Dev
30
31%{
32
33/*
34 * Copyright (c) 1988, 1993
35 * The Regents of the University of California. All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * @(#)config.y 8.1 (Berkeley) 6/6/93
23%token SEMICOLON
24%token INCLUDE
25
26%token <str> ID
27%token <val> NUMBER
28
29%type <str> Save_id
30%type <str> Opt_value
31%type <str> Dev
32
33%{
34
35/*
36 * Copyright (c) 1988, 1993
37 * The Regents of the University of California. All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by the University of
50 * California, Berkeley and its contributors.
51 * 4. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)config.y 8.1 (Berkeley) 6/6/93
66 * $FreeBSD: head/usr.sbin/config/config.y 111230 2003-02-21 23:17:00Z ru $
68 * $FreeBSD: head/usr.sbin/config/config.y 111582 2003-02-26 23:36:59Z ru $
67 */
68
69#include <ctype.h>
70#include <err.h>
71#include <stdio.h>
72#include <string.h>
73
74#include "config.h"
75
76struct device_head dtab;
77char *ident;
78char *env;
79int envmode;
80char *hints;
81int hintmode;
82int yyline;
83const char *yyfile;
84struct file_list_head ftab;
85char errbuf[80];
86int maxusers;
87
88#define ns(s) strdup(s)
89int include(const char *, int);
90void yyerror(const char *s);
91
92static char *
93devopt(char *dev)
94{
95 char *ret = malloc(strlen(dev) + 5);
96
97 sprintf(ret, "DEV_%s", dev);
98 raisestr(ret);
99 return ret;
100}
101
102%}
103%%
104Configuration:
105 Many_specs
106 ;
107
108Many_specs:
109 Many_specs Spec
110 |
111 /* lambda */
112 ;
113
114Spec:
115 Device_spec SEMICOLON
116 |
117 Config_spec SEMICOLON
118 |
119 SEMICOLON
120 |
121 error SEMICOLON
122 ;
123
124Config_spec:
125 ARCH Save_id
126 = {
127 machinename = $2;
128 } |
129 CPU Save_id
130 = {
131 struct cputype *cp =
132 (struct cputype *)malloc(sizeof (struct cputype));
133 memset(cp, 0, sizeof(*cp));
134 cp->cpu_name = $2;
135 SLIST_INSERT_HEAD(&cputype, cp, cpu_next);
136 } |
137 OPTIONS Opt_list
138 |
69 */
70
71#include <ctype.h>
72#include <err.h>
73#include <stdio.h>
74#include <string.h>
75
76#include "config.h"
77
78struct device_head dtab;
79char *ident;
80char *env;
81int envmode;
82char *hints;
83int hintmode;
84int yyline;
85const char *yyfile;
86struct file_list_head ftab;
87char errbuf[80];
88int maxusers;
89
90#define ns(s) strdup(s)
91int include(const char *, int);
92void yyerror(const char *s);
93
94static char *
95devopt(char *dev)
96{
97 char *ret = malloc(strlen(dev) + 5);
98
99 sprintf(ret, "DEV_%s", dev);
100 raisestr(ret);
101 return ret;
102}
103
104%}
105%%
106Configuration:
107 Many_specs
108 ;
109
110Many_specs:
111 Many_specs Spec
112 |
113 /* lambda */
114 ;
115
116Spec:
117 Device_spec SEMICOLON
118 |
119 Config_spec SEMICOLON
120 |
121 SEMICOLON
122 |
123 error SEMICOLON
124 ;
125
126Config_spec:
127 ARCH Save_id
128 = {
129 machinename = $2;
130 } |
131 CPU Save_id
132 = {
133 struct cputype *cp =
134 (struct cputype *)malloc(sizeof (struct cputype));
135 memset(cp, 0, sizeof(*cp));
136 cp->cpu_name = $2;
137 SLIST_INSERT_HEAD(&cputype, cp, cpu_next);
138 } |
139 OPTIONS Opt_list
140 |
141 NOOPTION Save_id
142 = { rmopt(&opt, $2); } |
139 MAKEOPTIONS Mkopt_list
140 |
143 MAKEOPTIONS Mkopt_list
144 |
145 NOMAKEOPTION Save_id
146 = { rmopt(&mkopt, $2); } |
141 IDENT ID
142 = { ident = $2; } |
143 System_spec
144 |
145 MAXUSERS NUMBER
146 = { maxusers = $2; } |
147 PROFILE NUMBER
148 = { profiling = $2; } |
149 ENV ID
150 = {
151 env = $2;
152 envmode = 1;
153 } |
154 HINTS ID
155 = {
156 hints = $2;
157 hintmode = 1;
158 } |
159 INCLUDE ID
160 = { include($2, 0); };
161
162System_spec:
163 CONFIG System_id System_parameter_list
164 = { errx(1, "%s:%d: root/dump/swap specifications obsolete",
165 yyfile, yyline);}
166 |
167 CONFIG System_id
168 ;
169
170System_id:
171 Save_id
172 = { newopt(&mkopt, ns("KERNEL"), $1); };
173
174System_parameter_list:
175 System_parameter_list ID
176 | ID
177 ;
178
179Opt_list:
180 Opt_list COMMA Option
181 |
182 Option
183 ;
184
185Option:
186 Save_id
187 = {
188 char *s;
189
190 newopt(&opt, $1, NULL);
191 if ((s = strchr($1, '=')))
192 errx(1, "%s:%d: The `=' in options should not be "
193 "quoted", yyfile, yyline);
194 } |
195 Save_id EQUALS Opt_value
196 = {
197 newopt(&opt, $1, $3);
198 } ;
199
200Opt_value:
201 ID
202 = { $$ = $1; } |
203 NUMBER
204 = {
205 char buf[80];
206
207 (void) snprintf(buf, sizeof(buf), "%d", $1);
208 $$ = ns(buf);
209 } ;
210
211Save_id:
212 ID
213 = { $$ = $1; }
214 ;
215
216Mkopt_list:
217 Mkopt_list COMMA Mkoption
218 |
219 Mkoption
220 ;
221
222Mkoption:
223 Save_id
224 = { newopt(&mkopt, $1, ns("")); } |
225 Save_id EQUALS Opt_value
226 = { newopt(&mkopt, $1, $3); } ;
227
228Dev:
229 ID
230 = { $$ = $1; }
231 ;
232
233Device_spec:
234 DEVICE Dev
235 = {
236 newopt(&opt, devopt($2), ns("1"));
237 /* and the device part */
238 newdev($2, UNKNOWN);
239 } |
240 DEVICE Dev NUMBER
241 = {
242 newopt(&opt, devopt($2), ns("1"));
243 /* and the device part */
244 newdev($2, $3);
245 if ($3 == 0)
246 errx(1, "%s:%d: devices with zero units are not "
247 "likely to be correct", yyfile, yyline);
248 } |
249 NODEVICE Dev
250 = {
147 IDENT ID
148 = { ident = $2; } |
149 System_spec
150 |
151 MAXUSERS NUMBER
152 = { maxusers = $2; } |
153 PROFILE NUMBER
154 = { profiling = $2; } |
155 ENV ID
156 = {
157 env = $2;
158 envmode = 1;
159 } |
160 HINTS ID
161 = {
162 hints = $2;
163 hintmode = 1;
164 } |
165 INCLUDE ID
166 = { include($2, 0); };
167
168System_spec:
169 CONFIG System_id System_parameter_list
170 = { errx(1, "%s:%d: root/dump/swap specifications obsolete",
171 yyfile, yyline);}
172 |
173 CONFIG System_id
174 ;
175
176System_id:
177 Save_id
178 = { newopt(&mkopt, ns("KERNEL"), $1); };
179
180System_parameter_list:
181 System_parameter_list ID
182 | ID
183 ;
184
185Opt_list:
186 Opt_list COMMA Option
187 |
188 Option
189 ;
190
191Option:
192 Save_id
193 = {
194 char *s;
195
196 newopt(&opt, $1, NULL);
197 if ((s = strchr($1, '=')))
198 errx(1, "%s:%d: The `=' in options should not be "
199 "quoted", yyfile, yyline);
200 } |
201 Save_id EQUALS Opt_value
202 = {
203 newopt(&opt, $1, $3);
204 } ;
205
206Opt_value:
207 ID
208 = { $$ = $1; } |
209 NUMBER
210 = {
211 char buf[80];
212
213 (void) snprintf(buf, sizeof(buf), "%d", $1);
214 $$ = ns(buf);
215 } ;
216
217Save_id:
218 ID
219 = { $$ = $1; }
220 ;
221
222Mkopt_list:
223 Mkopt_list COMMA Mkoption
224 |
225 Mkoption
226 ;
227
228Mkoption:
229 Save_id
230 = { newopt(&mkopt, $1, ns("")); } |
231 Save_id EQUALS Opt_value
232 = { newopt(&mkopt, $1, $3); } ;
233
234Dev:
235 ID
236 = { $$ = $1; }
237 ;
238
239Device_spec:
240 DEVICE Dev
241 = {
242 newopt(&opt, devopt($2), ns("1"));
243 /* and the device part */
244 newdev($2, UNKNOWN);
245 } |
246 DEVICE Dev NUMBER
247 = {
248 newopt(&opt, devopt($2), ns("1"));
249 /* and the device part */
250 newdev($2, $3);
251 if ($3 == 0)
252 errx(1, "%s:%d: devices with zero units are not "
253 "likely to be correct", yyfile, yyline);
254 } |
255 NODEVICE Dev
256 = {
251 rmopt(&opt, devopt($2));
257 char *s = devopt($2);
258
259 rmopt(&opt, s);
260 free(s);
252 /* and the device part */
253 rmdev($2);
254 } ;
255
256%%
257
258void
259yyerror(const char *s)
260{
261
262 errx(1, "%s:%d: %s", yyfile, yyline + 1, s);
263}
264
265/*
266 * add a device to the list of devices
267 */
268static void
269newdev(char *name, int count)
270{
271 struct device *np;
272
273 np = (struct device *) malloc(sizeof *np);
274 memset(np, 0, sizeof(*np));
275 np->d_name = name;
276 np->d_count = count;
277 STAILQ_INSERT_TAIL(&dtab, np, d_next);
278}
279
280/*
281 * remove a device from the list of devices
282 */
283static void
284rmdev(char *name)
285{
286 struct device *dp, *rmdp;
287
288 STAILQ_FOREACH(dp, &dtab, d_next) {
289 if (eq(dp->d_name, name)) {
290 rmdp = dp;
291 dp = STAILQ_NEXT(dp, d_next);
292 STAILQ_REMOVE(&dtab, rmdp, device, d_next);
293 free(rmdp->d_name);
294 free(rmdp);
295 if (dp == NULL)
296 break;
297 }
298 }
299}
300
301static void
302newopt(struct opt_head *list, char *name, char *value)
303{
304 struct opt *op;
305
306 op = (struct opt *)malloc(sizeof (struct opt));
307 memset(op, 0, sizeof(*op));
308 op->op_name = name;
309 op->op_ownfile = 0;
310 op->op_value = value;
311 SLIST_INSERT_HEAD(list, op, op_next);
312}
313
314static void
315rmopt(struct opt_head *list, char *name)
316{
317 struct opt *op, *rmop;
318
319 SLIST_FOREACH(op, list, op_next) {
320 if (eq(op->op_name, name)) {
321 rmop = op;
322 op = SLIST_NEXT(op, op_next);
323 SLIST_REMOVE(list, rmop, opt, op_next);
324 free(rmop->op_name);
325 if (rmop->op_value != NULL)
326 free(rmop->op_value);
327 free(rmop);
328 if (op == NULL)
329 break;
330 }
331 }
332}
261 /* and the device part */
262 rmdev($2);
263 } ;
264
265%%
266
267void
268yyerror(const char *s)
269{
270
271 errx(1, "%s:%d: %s", yyfile, yyline + 1, s);
272}
273
274/*
275 * add a device to the list of devices
276 */
277static void
278newdev(char *name, int count)
279{
280 struct device *np;
281
282 np = (struct device *) malloc(sizeof *np);
283 memset(np, 0, sizeof(*np));
284 np->d_name = name;
285 np->d_count = count;
286 STAILQ_INSERT_TAIL(&dtab, np, d_next);
287}
288
289/*
290 * remove a device from the list of devices
291 */
292static void
293rmdev(char *name)
294{
295 struct device *dp, *rmdp;
296
297 STAILQ_FOREACH(dp, &dtab, d_next) {
298 if (eq(dp->d_name, name)) {
299 rmdp = dp;
300 dp = STAILQ_NEXT(dp, d_next);
301 STAILQ_REMOVE(&dtab, rmdp, device, d_next);
302 free(rmdp->d_name);
303 free(rmdp);
304 if (dp == NULL)
305 break;
306 }
307 }
308}
309
310static void
311newopt(struct opt_head *list, char *name, char *value)
312{
313 struct opt *op;
314
315 op = (struct opt *)malloc(sizeof (struct opt));
316 memset(op, 0, sizeof(*op));
317 op->op_name = name;
318 op->op_ownfile = 0;
319 op->op_value = value;
320 SLIST_INSERT_HEAD(list, op, op_next);
321}
322
323static void
324rmopt(struct opt_head *list, char *name)
325{
326 struct opt *op, *rmop;
327
328 SLIST_FOREACH(op, list, op_next) {
329 if (eq(op->op_name, name)) {
330 rmop = op;
331 op = SLIST_NEXT(op, op_next);
332 SLIST_REMOVE(list, rmop, opt, op_next);
333 free(rmop->op_name);
334 if (rmop->op_value != NULL)
335 free(rmop->op_value);
336 free(rmop);
337 if (op == NULL)
338 break;
339 }
340 }
341}