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
82 struct device_head dtab;
87 struct file_list_head ftab;
88 struct files_name_head fntab;
92 #define ns(s) strdup(s)
93 int include(const char *, int);
94 void yyerror(const char *s);
97 static void newdev(char *name);
98 static void newfile(char *name);
99 static void newenvvar(char *name, bool is_file);
100 static void rmdev_schedule(struct device_head *dh, char *name);
101 static void newopt(struct opt_head *list, char *name, char *value, int append, int dupe);
102 static void rmopt_schedule(struct opt_head *list, char *name);
107 char *ret = malloc(strlen(dev) + 5);
109 sprintf(ret, "DEV_%s", dev);
127 Device_spec SEMICOLON
129 Config_spec SEMICOLON
131 INCLUDE PATH SEMICOLON {
136 INCLUDE ID SEMICOLON {
141 FILES ID SEMICOLON { newfile($2); };
150 if (machinename != NULL && !eq($2, machinename))
151 errx(1, "%s:%d: only one machine directive is allowed",
156 ARCH Save_id Save_id {
158 * Allow the machinearch to change with a second machine directive,
159 * but still enforce no changes to the machinename.
161 if (machinename != NULL && !eq($2, machinename))
162 errx(1, "%s:%d: only one machine directive is allowed",
169 (struct cputype *)calloc(1, sizeof (struct cputype));
171 err(EXIT_FAILURE, "calloc");
173 SLIST_INSERT_HEAD(&cputype, cp, cpu_next);
176 struct cputype *cp, *cp2;
177 SLIST_FOREACH_SAFE(cp, &cputype, cpu_next, cp2) {
178 if (eq(cp->cpu_name, $2)) {
179 SLIST_REMOVE(&cputype, cp, cputype, cpu_next);
186 NOOPTION NoOpt_list |
187 MAKEOPTIONS Mkopt_list
189 NOMAKEOPTION Save_id { rmopt_schedule(&mkopt, $2); } |
190 IDENT ID { ident = $2; } |
193 MAXUSERS NUMBER { maxusers = $2; } |
194 ENV ID { newenvvar($2, true); } |
195 ENVVAR ENVLINE { newenvvar($2, false); } |
199 hint = (struct hint *)calloc(1, sizeof (struct hint));
201 err(EXIT_FAILURE, "calloc");
202 hint->hint_name = $2;
203 STAILQ_INSERT_HEAD(&hints, hint, hint_next);
207 Save_id { newopt(&mkopt, ns("KERNEL"), $1, 0, 0); };
209 System_parameter_list:
210 System_parameter_list ID
215 Opt_list COMMA Option
221 NoOpt_list COMMA NoOption
227 newopt(&opt, $1, NULL, 0, 1);
228 if (strchr($1, '=') != NULL)
229 errx(1, "%s:%d: The `=' in options should not be "
230 "quoted", yyfile, yyline);
232 Save_id EQUALS Opt_value {
233 newopt(&opt, $1, $3, 0, 1);
238 rmopt_schedule(&opt, $1);
246 (void) snprintf(buf, sizeof(buf), "%d", $1);
255 Mkopt_list COMMA Mkoption
261 Save_id { newopt(&mkopt, $1, ns(""), 0, 0); } |
262 Save_id EQUALS { newopt(&mkopt, $1, ns(""), 0, 0); } |
263 Save_id EQUALS Opt_value { newopt(&mkopt, $1, $3, 0, 0); } |
264 Save_id PLUSEQUALS Opt_value { newopt(&mkopt, $1, $3, 1, 0); } ;
277 Dev_list COMMA Device
283 NoDev_list COMMA NoDevice
290 newopt(&opt, devopt($1), ns("1"), 0, 0);
291 /* and the device part */
297 char *s = devopt($1);
299 rmopt_schedule(&opt, s);
301 /* and the device part */
302 rmdev_schedule(&dtab, $1);
308 yyerror(const char *s)
311 errx(1, "%s:%d: %s", yyfile, yyline + 1, s);
317 if (found_defaults) {
318 if (freopen(PREFIX, "r", stdin) == NULL)
319 err(2, "%s", PREFIX);
329 * Add a new file to the list of files.
334 struct files_name *nl;
336 nl = (struct files_name *) calloc(1, sizeof *nl);
338 err(EXIT_FAILURE, "calloc");
340 STAILQ_INSERT_TAIL(&fntab, nl, f_next);
344 newenvvar(char *name, bool is_file)
346 struct envvar *envvar;
348 envvar = (struct envvar *)calloc(1, sizeof (struct envvar));
350 err(EXIT_FAILURE, "calloc");
351 envvar->env_str = name;
352 envvar->env_is_file = is_file;
353 STAILQ_INSERT_HEAD(&envvars, envvar, envvar_next);
357 * Find a device in the list of devices.
359 static struct device *
360 finddev(struct device_head *dlist, char *name)
364 STAILQ_FOREACH(dp, dlist, d_next)
365 if (eq(dp->d_name, name))
372 * Add a device to the list of devices.
377 struct device *np, *dp;
379 if ((dp = finddev(&dtab, name)) != NULL) {
380 if (strcmp(dp->yyfile, yyfile) == 0)
382 "WARNING: duplicate device `%s' encountered in %s\n",
387 np = (struct device *) calloc(1, sizeof *np);
389 err(EXIT_FAILURE, "calloc");
391 np->yyfile = strdup(yyfile);
392 STAILQ_INSERT_TAIL(&dtab, np, d_next);
396 * Schedule a device to removal.
399 rmdev_schedule(struct device_head *dh, char *name)
403 dp = finddev(dh, name);
405 STAILQ_REMOVE(dh, dp, device, d_next);
413 * Find an option in the list of options.
416 findopt(struct opt_head *list, char *name)
420 SLIST_FOREACH(op, list, op_next)
421 if (eq(op->op_name, name))
428 * Add an option to the list of options.
431 newopt(struct opt_head *list, char *name, char *value, int append, int dupe)
433 struct opt *op, *op2;
436 * Ignore inclusions listed explicitly for configuration files.
438 if (eq(name, OPT_AUTOGEN)) {
443 op2 = findopt(list, name);
444 if (op2 != NULL && !append && !dupe) {
445 if (strcmp(op2->yyfile, yyfile) == 0)
447 "WARNING: duplicate option `%s' encountered.\n", name);
451 op = (struct opt *)calloc(1, sizeof (struct opt));
453 err(EXIT_FAILURE, "calloc");
456 op->op_value = value;
457 op->yyfile = strdup(yyfile);
460 while (SLIST_NEXT(op2, op_append) != NULL)
461 op2 = SLIST_NEXT(op2, op_append);
462 SLIST_NEXT(op2, op_append) = op;
464 while (SLIST_NEXT(op2, op_next) != NULL)
465 op2 = SLIST_NEXT(op2, op_next);
466 SLIST_NEXT(op2, op_next) = op;
469 SLIST_INSERT_HEAD(list, op, op_next);
473 * Remove an option from the list of options.
476 rmopt_schedule(struct opt_head *list, char *name)
480 while ((op = findopt(list, name)) != NULL) {
481 SLIST_REMOVE(list, op, opt, op_next);