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));
73 op->op_name = ns(cp->cpu_name);
74 SLIST_INSERT_HEAD(&opt, op, op_next);
78 /* printf("maxusers not specified; will auto-size\n"); */
79 } else if (maxusers < users.u_min) {
80 printf("minimum of %d maxusers assumed\n", users.u_min);
81 maxusers = users.u_min;
82 } else if (maxusers > users.u_max)
83 printf("warning: maxusers > %d (%d)\n", users.u_max, maxusers);
85 /* Fake MAXUSERS as an option. */
86 op = (struct opt *)calloc(1, sizeof(*op));
87 op->op_name = ns("MAXUSERS");
88 snprintf(buf, sizeof(buf), "%d", maxusers);
89 op->op_value = ns(buf);
90 SLIST_INSERT_HEAD(&opt, op, op_next);
93 SLIST_FOREACH(ol, &otab, o_next)
94 do_option(ol->o_name);
95 SLIST_FOREACH(op, &opt, op_next) {
96 if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) {
97 printf("%s: unknown option \"%s\"\n",
105 * Generate an <options>.h file
109 do_option(char *name)
112 const char *basefile;
115 struct opt_head op_head;
122 file = tooption(name);
125 * Check to see if the option was specified..
128 SLIST_FOREACH(op, &opt, op_next) {
129 if (eq(name, op->op_name)) {
131 value = op->op_value;
134 if (oldvalue != NULL && !eq(value, oldvalue))
136 "%s: option \"%s\" redefined from %s to %s\n",
137 PREFIX, op->op_name, oldvalue,
144 inf = fopen(file, "r");
146 outf = fopen(file, "w");
150 /* was the option in the config file? */
152 fprintf(outf, "#define %s %s\n", name, value);
153 } /* else empty file */
159 SLIST_FOREACH(ol, &otab, o_next)
160 if (eq(name, ol->o_name)) {
161 basefile = ol->o_file;
165 SLIST_INIT(&op_head);
172 /* get the #define */
173 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
175 /* get the option name */
176 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
179 /* get the option value */
180 if ((cp = get_word(inf)) == 0 || cp == (char *)EOF)
183 invalue = ns(cp); /* malloced */
189 SLIST_FOREACH(ol, &otab, o_next)
190 if (eq(inw, ol->o_name))
192 if (!eq(inw, name) && !ol) {
193 printf("WARNING: unknown option `%s' removed from %s\n",
196 } else if (ol != NULL && !eq(basefile, ol->o_file)) {
197 printf("WARNING: option `%s' moved from %s to %s\n",
198 inw, basefile, ol->o_file);
201 op = (struct opt *) calloc(1, sizeof *op);
203 op->op_value = invalue;
204 SLIST_INSERT_HEAD(&op_head, op, op_next);
209 if (cp == (char *)EOF)
213 if (!tidy && ((value == NULL && oldvalue == NULL) ||
214 (value && oldvalue && eq(value, oldvalue)))) {
215 while (!SLIST_EMPTY(&op_head)) {
216 op = SLIST_FIRST(&op_head);
217 SLIST_REMOVE_HEAD(&op_head, op_next);
225 if (value && !seen) {
226 /* New option appears */
227 op = (struct opt *) calloc(1, sizeof *op);
228 op->op_name = ns(name);
229 op->op_value = value ? ns(value) : NULL;
230 SLIST_INSERT_HEAD(&op_head, op, op_next);
233 outf = fopen(file, "w");
236 while (!SLIST_EMPTY(&op_head)) {
237 op = SLIST_FIRST(&op_head);
238 /* was the option in the config file? */
240 fprintf(outf, "#define %s %s\n",
241 op->op_name, op->op_value);
243 SLIST_REMOVE_HEAD(&op_head, op_next);
252 * Find the filename to store the option spec into.
257 static char hbuf[MAXPATHLEN];
258 char nbuf[MAXPATHLEN];
261 /* "cannot happen"? the otab list should be complete.. */
262 (void) strlcpy(nbuf, "options.h", sizeof(nbuf));
264 SLIST_FOREACH(po, &otab, o_next) {
265 if (eq(po->o_name, name)) {
266 strlcpy(nbuf, po->o_file, sizeof(nbuf));
271 (void) strlcpy(hbuf, path(nbuf), sizeof(hbuf));
276 * read the options and options.<machine> files
282 char fname[MAXPATHLEN];
283 char *wd, *this, *val;
286 char genopt[MAXPATHLEN];
289 (void) snprintf(fname, sizeof(fname), "../../conf/options");
291 fp = fopen(fname, "r");
297 if (wd == (char *)EOF) {
301 (void) snprintf(fname, sizeof fname, "../../conf/options.%s", machinename);
302 fp = fopen(fname, "r");
305 (void) snprintf(fname, sizeof fname, "options.%s", machinename);
314 while (((wd = get_word(fp)) != (char *)EOF) && wd)
320 if (val == (char *)EOF)
324 (void) snprintf(genopt, sizeof(genopt), "opt_%s.h", lower(s));
330 SLIST_FOREACH(po, &otab, o_next) {
331 if (eq(po->o_name, this)) {
332 printf("%s: Duplicate option %s.\n",
338 po = (struct opt_list *) calloc(1, sizeof *po);
341 SLIST_INSERT_HEAD(&otab, po, o_next);
353 *str = tolower(*str);