2 * Copyright (c) 1995 Peter Wemm
3 * Copyright (c) 1980, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 4. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
35 static const char rcsid[] =
40 * Make all the .h files for the optional entries
47 #include <sys/param.h>
55 } users = { 8, 2, 512 };
57 static char *lower(char *);
58 static void read_options(void);
59 static void do_option(char *);
60 static char *tooption(char *);
70 /* Fake the cpu types as options. */
71 SLIST_FOREACH(cp, &cputype, cpu_next) {
72 op = (struct opt *)calloc(1, sizeof(*op));
74 err(EXIT_FAILURE, "calloc");
75 op->op_name = ns(cp->cpu_name);
76 SLIST_INSERT_HEAD(&opt, op, op_next);
80 /* printf("maxusers not specified; will auto-size\n"); */
81 } else if (maxusers < users.u_min) {
82 printf("minimum of %d maxusers assumed\n", users.u_min);
83 maxusers = users.u_min;
84 } else if (maxusers > users.u_max)
85 printf("warning: maxusers > %d (%d)\n", users.u_max, maxusers);
87 /* Fake MAXUSERS as an option. */
88 op = (struct opt *)calloc(1, sizeof(*op));
90 err(EXIT_FAILURE, "calloc");
91 op->op_name = ns("MAXUSERS");
92 snprintf(buf, sizeof(buf), "%d", maxusers);
93 op->op_value = ns(buf);
94 SLIST_INSERT_HEAD(&opt, op, op_next);
97 SLIST_FOREACH(op, &opt, op_next) {
98 SLIST_FOREACH(ol, &otab, o_next) {
99 if (eq(op->op_name, ol->o_name) &&
100 (ol->o_flags & OL_ALIAS)) {
101 printf("Mapping option %s to %s.\n",
102 op->op_name, ol->o_file);
103 op->op_name = ol->o_file;
108 SLIST_FOREACH(ol, &otab, o_next)
109 do_option(ol->o_name);
110 SLIST_FOREACH(op, &opt, op_next) {
111 if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) {
112 printf("%s: unknown option \"%s\"\n",
113 PREFIX, op->op_name);
120 * Generate an <options>.h file
124 do_option(char *name)
127 const char *basefile;
130 struct opt_head op_head;
137 file = tooption(name);
139 * Check to see if the option was specified..
142 SLIST_FOREACH(op, &opt, op_next) {
143 if (eq(name, op->op_name)) {
145 value = op->op_value;
148 if (oldvalue != NULL && !eq(value, oldvalue))
150 "%s: option \"%s\" redefined from %s to %s\n",
151 PREFIX, op->op_name, oldvalue,
158 inf = fopen(file, "r");
160 outf = fopen(file, "w");
164 /* was the option in the config file? */
166 fprintf(outf, "#define %s %s\n", name, value);
167 } /* else empty file */
173 SLIST_FOREACH(ol, &otab, o_next)
174 if (eq(name, ol->o_name)) {
175 basefile = ol->o_file;
179 SLIST_INIT(&op_head);
186 /* get the #define */
187 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
189 /* get the option name */
190 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
193 /* get the option value */
194 if ((cp = get_word(inf)) == 0 || cp == (char *)EOF)
197 invalue = ns(cp); /* malloced */
203 SLIST_FOREACH(ol, &otab, o_next)
204 if (eq(inw, ol->o_name))
206 if (!eq(inw, name) && !ol) {
207 printf("WARNING: unknown option `%s' removed from %s\n",
210 } else if (ol != NULL && !eq(basefile, ol->o_file)) {
211 printf("WARNING: option `%s' moved from %s to %s\n",
212 inw, basefile, ol->o_file);
215 op = (struct opt *) calloc(1, sizeof *op);
217 err(EXIT_FAILURE, "calloc");
219 op->op_value = invalue;
220 SLIST_INSERT_HEAD(&op_head, op, op_next);
225 if (cp == (char *)EOF)
229 if (!tidy && ((value == NULL && oldvalue == NULL) ||
230 (value && oldvalue && eq(value, oldvalue)))) {
231 while (!SLIST_EMPTY(&op_head)) {
232 op = SLIST_FIRST(&op_head);
233 SLIST_REMOVE_HEAD(&op_head, op_next);
241 if (value && !seen) {
242 /* New option appears */
243 op = (struct opt *) calloc(1, sizeof *op);
245 err(EXIT_FAILURE, "calloc");
246 op->op_name = ns(name);
247 op->op_value = value ? ns(value) : NULL;
248 SLIST_INSERT_HEAD(&op_head, op, op_next);
251 outf = fopen(file, "w");
254 while (!SLIST_EMPTY(&op_head)) {
255 op = SLIST_FIRST(&op_head);
256 /* was the option in the config file? */
258 fprintf(outf, "#define %s %s\n",
259 op->op_name, op->op_value);
261 SLIST_REMOVE_HEAD(&op_head, op_next);
270 * Find the filename to store the option spec into.
275 static char hbuf[MAXPATHLEN];
276 char nbuf[MAXPATHLEN];
279 /* "cannot happen"? the otab list should be complete.. */
280 (void)strlcpy(nbuf, "options.h", sizeof(nbuf));
282 SLIST_FOREACH(po, &otab, o_next) {
283 if (eq(po->o_name, name)) {
284 strlcpy(nbuf, po->o_file, sizeof(nbuf));
289 (void)strlcpy(hbuf, path(nbuf), sizeof(hbuf));
295 check_duplicate(const char *fname, const char *this)
299 SLIST_FOREACH(po, &otab, o_next) {
300 if (eq(po->o_name, this)) {
301 printf("%s: Duplicate option %s.\n",
309 insert_option(const char *fname, char *this, char *val)
313 check_duplicate(fname, this);
314 po = (struct opt_list *) calloc(1, sizeof *po);
316 err(EXIT_FAILURE, "calloc");
320 SLIST_INSERT_HEAD(&otab, po, o_next);
324 update_option(const char *this, char *val, int flags)
328 SLIST_FOREACH(po, &otab, o_next) {
329 if (eq(po->o_name, this)) {
336 printf("Compat option %s not listed in options file.\n", this);
341 read_option_file(const char *fname, int flags)
344 char *wd, *this, *val;
345 char genopt[MAXPATHLEN];
347 fp = fopen(fname, "r");
350 while ((wd = get_word(fp)) != (char *)EOF) {
354 while (((wd = get_word(fp)) != (char *)EOF) && wd)
360 if (val == (char *)EOF)
364 printf("%s: compat file requires two words "
365 "per line at %s\n", fname, this);
369 (void)snprintf(genopt, sizeof(genopt), "opt_%s.h",
376 insert_option(fname, this, val);
378 update_option(this, val, flags);
385 * read the options and options.<machine> files
390 char fname[MAXPATHLEN];
393 read_option_file("../../conf/options", 0);
394 (void)snprintf(fname, sizeof fname, "../../conf/options.%s",
396 if (!read_option_file(fname, 0)) {
397 (void)snprintf(fname, sizeof fname, "options.%s", machinename);
398 read_option_file(fname, 0);
400 read_option_file("../../conf/options-compat", OL_ALIAS);
410 *str = tolower(*str);