4 struct file_list *file;
41 * SPDX-License-Identifier: BSD-3-Clause
43 * Copyright (c) 1988, 1993
44 * The Regents of the University of California. All rights reserved.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * @(#)config.y 8.1 (Berkeley) 6/6/93
81 struct device_head dtab;
86 struct file_list_head ftab;
87 struct files_name_head fntab;
91 #define ns(s) strdup(s)
92 int include(const char *, int);
93 void yyerror(const char *s);
96 static void newdev(char *name);
97 static void newfile(char *name);
98 static void newenvvar(char *name, bool is_file);
99 static void rmdev_schedule(struct device_head *dh, char *name);
100 static void newopt(struct opt_head *list, char *name, char *value, int append, int dupe);
101 static void rmopt_schedule(struct opt_head *list, char *name);
106 char *ret = malloc(strlen(dev) + 5);
108 sprintf(ret, "DEV_%s", dev);
126 Device_spec SEMICOLON
128 Config_spec SEMICOLON
130 INCLUDE PATH SEMICOLON {
135 INCLUDE ID SEMICOLON {
140 FILES ID SEMICOLON { newfile($2); };
149 if (machinename != NULL && !eq($2, machinename))
150 errx(1, "%s:%d: only one machine directive is allowed",
155 ARCH Save_id Save_id {
157 * Allow the machinearch to change with a second machine directive,
158 * but still enforce no changes to the machinename.
160 if (machinename != NULL && !eq($2, machinename))
161 errx(1, "%s:%d: only one machine directive is allowed",
168 (struct cputype *)calloc(1, sizeof (struct cputype));
170 err(EXIT_FAILURE, "calloc");
172 SLIST_INSERT_HEAD(&cputype, cp, cpu_next);
175 struct cputype *cp, *cp2;
176 SLIST_FOREACH_SAFE(cp, &cputype, cpu_next, cp2) {
177 if (eq(cp->cpu_name, $2)) {
178 SLIST_REMOVE(&cputype, cp, cputype, cpu_next);
185 NOOPTION NoOpt_list |
186 MAKEOPTIONS Mkopt_list
188 NOMAKEOPTION Save_id { rmopt_schedule(&mkopt, $2); } |
189 IDENT ID { ident = $2; } |
190 MAXUSERS NUMBER { maxusers = $2; } |
191 ENV ID { newenvvar($2, true); } |
192 ENVVAR ENVLINE { newenvvar($2, false); } |
196 hint = (struct hint *)calloc(1, sizeof (struct hint));
198 err(EXIT_FAILURE, "calloc");
199 hint->hint_name = $2;
200 STAILQ_INSERT_HEAD(&hints, hint, hint_next);
204 Save_id { newopt(&mkopt, ns("KERNEL"), $1, 0, 0); };
206 System_parameter_list:
207 System_parameter_list ID
212 Opt_list COMMA Option
218 NoOpt_list COMMA NoOption
224 newopt(&opt, $1, NULL, 0, 1);
225 if (strchr($1, '=') != NULL)
226 errx(1, "%s:%d: The `=' in options should not be "
227 "quoted", yyfile, yyline);
229 Save_id EQUALS Opt_value {
230 newopt(&opt, $1, $3, 0, 1);
235 rmopt_schedule(&opt, $1);
243 (void) snprintf(buf, sizeof(buf), "%d", $1);
252 Mkopt_list COMMA Mkoption
258 Save_id { newopt(&mkopt, $1, ns(""), 0, 0); } |
259 Save_id EQUALS { newopt(&mkopt, $1, ns(""), 0, 0); } |
260 Save_id EQUALS Opt_value { newopt(&mkopt, $1, $3, 0, 0); } |
261 Save_id PLUSEQUALS Opt_value { newopt(&mkopt, $1, $3, 1, 0); } ;
274 Dev_list COMMA Device
280 NoDev_list COMMA NoDevice
287 newopt(&opt, devopt($1), ns("1"), 0, 0);
288 /* and the device part */
294 char *s = devopt($1);
296 rmopt_schedule(&opt, s);
298 /* and the device part */
299 rmdev_schedule(&dtab, $1);
305 yyerror(const char *s)
308 errx(1, "%s:%d: %s", yyfile, yyline + 1, s);
314 if (found_defaults) {
315 if (freopen(PREFIX, "r", stdin) == NULL)
316 err(2, "%s", PREFIX);
326 * Add a new file to the list of files.
331 struct files_name *nl;
333 nl = (struct files_name *) calloc(1, sizeof *nl);
335 err(EXIT_FAILURE, "calloc");
337 STAILQ_INSERT_TAIL(&fntab, nl, f_next);
341 newenvvar(char *name, bool is_file)
343 struct envvar *envvar;
345 envvar = (struct envvar *)calloc(1, sizeof (struct envvar));
347 err(EXIT_FAILURE, "calloc");
348 envvar->env_str = name;
349 envvar->env_is_file = is_file;
350 STAILQ_INSERT_HEAD(&envvars, envvar, envvar_next);
354 * Find a device in the list of devices.
356 static struct device *
357 finddev(struct device_head *dlist, char *name)
361 STAILQ_FOREACH(dp, dlist, d_next)
362 if (eq(dp->d_name, name))
369 * Add a device to the list of devices.
374 struct device *np, *dp;
376 if ((dp = finddev(&dtab, name)) != NULL) {
377 if (strcmp(dp->yyfile, yyfile) == 0)
379 "WARNING: duplicate device `%s' encountered in %s\n",
384 np = (struct device *) calloc(1, sizeof *np);
386 err(EXIT_FAILURE, "calloc");
388 np->yyfile = strdup(yyfile);
389 STAILQ_INSERT_TAIL(&dtab, np, d_next);
393 * Schedule a device to removal.
396 rmdev_schedule(struct device_head *dh, char *name)
400 dp = finddev(dh, name);
402 STAILQ_REMOVE(dh, dp, device, d_next);
410 * Find an option in the list of options.
413 findopt(struct opt_head *list, char *name)
417 SLIST_FOREACH(op, list, op_next)
418 if (eq(op->op_name, name))
425 * Add an option to the list of options.
428 newopt(struct opt_head *list, char *name, char *value, int append, int dupe)
430 struct opt *op, *op2;
433 * Ignore inclusions listed explicitly for configuration files.
435 if (eq(name, OPT_AUTOGEN)) {
440 op2 = findopt(list, name);
441 if (op2 != NULL && !append && !dupe) {
442 if (strcmp(op2->yyfile, yyfile) == 0)
444 "WARNING: duplicate option `%s' encountered.\n", name);
448 op = (struct opt *)calloc(1, sizeof (struct opt));
450 err(EXIT_FAILURE, "calloc");
453 op->op_value = value;
454 op->yyfile = strdup(yyfile);
457 while (SLIST_NEXT(op2, op_append) != NULL)
458 op2 = SLIST_NEXT(op2, op_append);
459 SLIST_NEXT(op2, op_append) = op;
461 while (SLIST_NEXT(op2, op_next) != NULL)
462 op2 = SLIST_NEXT(op2, op_next);
463 SLIST_NEXT(op2, op_next) = op;
466 SLIST_INSERT_HEAD(list, op, op_next);
470 * Remove an option from the list of options.
473 rmopt_schedule(struct opt_head *list, char *name)
477 while ((op = findopt(list, name)) != NULL) {
478 SLIST_REMOVE(list, op, opt, op_next);