4 struct file_list *file;
42 * SPDX-License-Identifier: BSD-3-Clause
44 * Copyright (c) 1988, 1993
45 * The Regents of the University of California. All rights reserved.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * @(#)config.y 8.1 (Berkeley) 6/6/93
83 struct device_head dtab;
88 struct file_list_head ftab;
89 struct files_name_head fntab;
93 #define ns(s) strdup(s)
94 int include(const char *, int);
95 void yyerror(const char *s);
98 static void newdev(char *name);
99 static void newfile(char *name);
100 static void newenvvar(char *name, bool is_file);
101 static void rmdev_schedule(struct device_head *dh, char *name);
102 static void newopt(struct opt_head *list, char *name, char *value, int append, int dupe);
103 static void rmopt_schedule(struct opt_head *list, char *name);
108 char *ret = malloc(strlen(dev) + 5);
110 sprintf(ret, "DEV_%s", dev);
128 Device_spec SEMICOLON
130 Config_spec SEMICOLON
132 INCLUDE PATH SEMICOLON {
137 INCLUDE ID SEMICOLON {
142 FILES ID SEMICOLON { newfile($2); };
151 if (machinename != NULL && !eq($2, machinename))
152 errx(1, "%s:%d: only one machine directive is allowed",
157 ARCH Save_id Save_id {
159 * Allow the machinearch to change with a second machine directive,
160 * but still enforce no changes to the machinename.
162 if (machinename != NULL && !eq($2, machinename))
163 errx(1, "%s:%d: only one machine directive is allowed",
170 (struct cputype *)calloc(1, sizeof (struct cputype));
172 err(EXIT_FAILURE, "calloc");
174 SLIST_INSERT_HEAD(&cputype, cp, cpu_next);
177 struct cputype *cp, *cp2;
178 SLIST_FOREACH_SAFE(cp, &cputype, cpu_next, cp2) {
179 if (eq(cp->cpu_name, $2)) {
180 SLIST_REMOVE(&cputype, cp, cputype, cpu_next);
187 NOOPTION NoOpt_list |
188 MAKEOPTIONS Mkopt_list
190 NOMAKEOPTION Save_id { rmopt_schedule(&mkopt, $2); } |
191 IDENT ID { ident = $2; } |
194 MAXUSERS NUMBER { maxusers = $2; } |
195 PROFILE NUMBER { profiling = $2; } |
196 ENV ID { newenvvar($2, true); } |
197 ENVVAR ENVLINE { newenvvar($2, false); } |
201 hint = (struct hint *)calloc(1, sizeof (struct hint));
203 err(EXIT_FAILURE, "calloc");
204 hint->hint_name = $2;
205 STAILQ_INSERT_HEAD(&hints, hint, hint_next);
209 CONFIG System_id System_parameter_list {
210 errx(1, "%s:%d: root/dump/swap specifications obsolete",
218 Save_id { newopt(&mkopt, ns("KERNEL"), $1, 0, 0); };
220 System_parameter_list:
221 System_parameter_list ID
226 Opt_list COMMA Option
232 NoOpt_list COMMA NoOption
238 newopt(&opt, $1, NULL, 0, 1);
239 if (strchr($1, '=') != NULL)
240 errx(1, "%s:%d: The `=' in options should not be "
241 "quoted", yyfile, yyline);
243 Save_id EQUALS Opt_value {
244 newopt(&opt, $1, $3, 0, 1);
249 rmopt_schedule(&opt, $1);
257 (void) snprintf(buf, sizeof(buf), "%d", $1);
266 Mkopt_list COMMA Mkoption
272 Save_id { newopt(&mkopt, $1, ns(""), 0, 0); } |
273 Save_id EQUALS { newopt(&mkopt, $1, ns(""), 0, 0); } |
274 Save_id EQUALS Opt_value { newopt(&mkopt, $1, $3, 0, 0); } |
275 Save_id PLUSEQUALS Opt_value { newopt(&mkopt, $1, $3, 1, 0); } ;
288 Dev_list COMMA Device
294 NoDev_list COMMA NoDevice
301 newopt(&opt, devopt($1), ns("1"), 0, 0);
302 /* and the device part */
308 char *s = devopt($1);
310 rmopt_schedule(&opt, s);
312 /* and the device part */
313 rmdev_schedule(&dtab, $1);
319 yyerror(const char *s)
322 errx(1, "%s:%d: %s", yyfile, yyline + 1, s);
328 if (found_defaults) {
329 if (freopen(PREFIX, "r", stdin) == NULL)
330 err(2, "%s", PREFIX);
340 * Add a new file to the list of files.
345 struct files_name *nl;
347 nl = (struct files_name *) calloc(1, sizeof *nl);
349 err(EXIT_FAILURE, "calloc");
351 STAILQ_INSERT_TAIL(&fntab, nl, f_next);
355 newenvvar(char *name, bool is_file)
357 struct envvar *envvar;
359 envvar = (struct envvar *)calloc(1, sizeof (struct envvar));
361 err(EXIT_FAILURE, "calloc");
362 envvar->env_str = name;
363 envvar->env_is_file = is_file;
364 STAILQ_INSERT_HEAD(&envvars, envvar, envvar_next);
368 * Find a device in the list of devices.
370 static struct device *
371 finddev(struct device_head *dlist, char *name)
375 STAILQ_FOREACH(dp, dlist, d_next)
376 if (eq(dp->d_name, name))
383 * Add a device to the list of devices.
388 struct device *np, *dp;
390 if ((dp = finddev(&dtab, name)) != NULL) {
391 if (strcmp(dp->yyfile, yyfile) == 0)
393 "WARNING: duplicate device `%s' encountered in %s\n",
398 np = (struct device *) calloc(1, sizeof *np);
400 err(EXIT_FAILURE, "calloc");
402 np->yyfile = strdup(yyfile);
403 STAILQ_INSERT_TAIL(&dtab, np, d_next);
407 * Schedule a device to removal.
410 rmdev_schedule(struct device_head *dh, char *name)
414 dp = finddev(dh, name);
416 STAILQ_REMOVE(dh, dp, device, d_next);
424 * Find an option in the list of options.
427 findopt(struct opt_head *list, char *name)
431 SLIST_FOREACH(op, list, op_next)
432 if (eq(op->op_name, name))
439 * Add an option to the list of options.
442 newopt(struct opt_head *list, char *name, char *value, int append, int dupe)
444 struct opt *op, *op2;
447 * Ignore inclusions listed explicitly for configuration files.
449 if (eq(name, OPT_AUTOGEN)) {
454 op2 = findopt(list, name);
455 if (op2 != NULL && !append && !dupe) {
456 if (strcmp(op2->yyfile, yyfile) == 0)
458 "WARNING: duplicate option `%s' encountered.\n", name);
462 op = (struct opt *)calloc(1, sizeof (struct opt));
464 err(EXIT_FAILURE, "calloc");
467 op->op_value = value;
468 op->yyfile = strdup(yyfile);
471 while (SLIST_NEXT(op2, op_append) != NULL)
472 op2 = SLIST_NEXT(op2, op_append);
473 SLIST_NEXT(op2, op_append) = op;
475 while (SLIST_NEXT(op2, op_next) != NULL)
476 op2 = SLIST_NEXT(op2, op_next);
477 SLIST_NEXT(op2, op_next) = op;
480 SLIST_INSERT_HEAD(list, op, op_next);
484 * Remove an option from the list of options.
487 rmopt_schedule(struct opt_head *list, char *name)
491 while ((op = findopt(list, name)) != NULL) {
492 SLIST_REMOVE(list, op, opt, op_next);