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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
39 static const char rcsid[] =
44 * Make all the .h files for the optional entries
51 #include <sys/param.h>
59 } users= { 8, 2, 512 };
61 static char *lower(char *);
62 static void read_options(void);
63 static void do_option(char *);
64 static char *tooption(char *);
74 /* Fake the cpu types as options. */
75 for (cp = cputype; cp != NULL; cp = cp->cpu_next) {
76 op = (struct opt *)malloc(sizeof(*op));
77 memset(op, 0, sizeof(*op));
78 op->op_name = ns(cp->cpu_name);
84 /* printf("maxusers not specified; will auto-size\n"); */
85 } else if (maxusers < users.u_min) {
86 printf("minimum of %d maxusers assumed\n", users.u_min);
87 maxusers = users.u_min;
88 } else if (maxusers > users.u_max)
89 printf("warning: maxusers > %d (%d)\n", users.u_max, maxusers);
91 /* Fake MAXUSERS as an option. */
92 op = (struct opt *)malloc(sizeof(*op));
93 memset(op, 0, sizeof(*op));
94 op->op_name = ns("MAXUSERS");
95 snprintf(buf, sizeof(buf), "%d", maxusers);
96 op->op_value = ns(buf);
101 for (ol = otab; ol != 0; ol = ol->o_next)
102 do_option(ol->o_name);
103 for (op = opt; op; op = op->op_next) {
104 if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) {
105 printf("%s: unknown option \"%s\"\n",
106 PREFIX, op->op_name);
113 * Generate an <options>.h file
117 do_option(char *name)
120 const char *basefile;
122 struct opt *op, *op_head, *topp;
129 file = tooption(name);
132 * Check to see if the option was specified..
135 for (op = opt; op; op = op->op_next) {
136 if (eq(name, op->op_name)) {
138 value = op->op_value;
141 if (oldvalue != NULL && !eq(value, oldvalue))
143 "%s: option \"%s\" redefined from %s to %s\n",
144 PREFIX, op->op_name, oldvalue,
151 inf = fopen(file, "r");
153 outf = fopen(file, "w");
157 /* was the option in the config file? */
159 fprintf(outf, "#define %s %s\n", name, value);
160 } /* else empty file */
166 for (ol = otab; ol != 0; ol = ol->o_next)
167 if (eq(name, ol->o_name)) {
168 basefile = ol->o_file;
179 /* get the #define */
180 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
182 /* get the option name */
183 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
186 /* get the option value */
187 if ((cp = get_word(inf)) == 0 || cp == (char *)EOF)
190 invalue = ns(cp); /* malloced */
196 for (ol = otab; ol != 0; ol = ol->o_next)
197 if (eq(inw, ol->o_name))
199 if (!eq(inw, name) && !ol) {
200 printf("WARNING: unknown option `%s' removed from %s\n",
203 } else if (ol != NULL && !eq(basefile, ol->o_file)) {
204 printf("WARNING: option `%s' moved from %s to %s\n",
205 inw, basefile, ol->o_file);
208 op = (struct opt *) malloc(sizeof *op);
209 bzero(op, sizeof(*op));
211 op->op_value = invalue;
212 op->op_next = op_head;
218 if (cp == (char *)EOF)
222 if (!tidy && ((value == NULL && oldvalue == NULL) ||
223 (value && oldvalue && eq(value, oldvalue)))) {
224 for (op = op_head; op != NULL; op = topp) {
233 if (value && !seen) {
234 /* New option appears */
235 op = (struct opt *) malloc(sizeof *op);
236 bzero(op, sizeof(*op));
237 op->op_name = ns(name);
238 op->op_value = value ? ns(value) : NULL;
239 op->op_next = op_head;
243 outf = fopen(file, "w");
246 for (op = op_head; op != NULL; op = topp) {
247 /* was the option in the config file? */
249 fprintf(outf, "#define %s %s\n",
250 op->op_name, op->op_value);
261 * Find the filename to store the option spec into.
266 static char hbuf[MAXPATHLEN];
267 char nbuf[MAXPATHLEN];
270 /* "cannot happen"? the otab list should be complete.. */
271 (void) strlcpy(nbuf, "options.h", sizeof(nbuf));
273 for (po = otab ; po != 0; po = po->o_next) {
274 if (eq(po->o_name, name)) {
275 strlcpy(nbuf, po->o_file, sizeof(nbuf));
280 (void) strlcpy(hbuf, path(nbuf), sizeof(hbuf));
285 * read the options and options.<machine> files
291 char fname[MAXPATHLEN];
292 char *wd, *this, *val;
295 char genopt[MAXPATHLEN];
299 printf("no ident line specified\n");
302 (void) snprintf(fname, sizeof(fname), "../../conf/options");
304 fp = fopen(fname, "r");
310 if (wd == (char *)EOF) {
314 (void) snprintf(fname, sizeof fname, "../../conf/options.%s", machinename);
315 fp = fopen(fname, "r");
318 (void) snprintf(fname, sizeof fname, "options.%s", machinename);
327 while (((wd = get_word(fp)) != (char *)EOF) && wd)
333 if (val == (char *)EOF)
337 (void) snprintf(genopt, sizeof(genopt), "opt_%s.h", lower(s));
343 for (po = otab ; po != 0; po = po->o_next) {
344 if (eq(po->o_name, this)) {
345 printf("%s: Duplicate option %s.\n",
351 po = (struct opt_list *) malloc(sizeof *po);
352 bzero(po, sizeof(*po));
368 *str = tolower(*str);