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
34 * @(#)mkheaders.c 8.1 (Berkeley) 6/6/93
35 * $FreeBSD: src/usr.sbin/config/mkoptions.c,v 1.17.2.3 2001/12/13 19:18:01 dillon Exp $
36 * $DragonFly: src/usr.sbin/config/mkoptions.c,v 1.4 2003/11/16 11:51:14 eirikn Exp $
40 * Make all the .h files for the optional entries
47 #include <sys/param.h>
56 { 8, 2, 512 }, /* MACHINE_I386 */
57 { 8, 2, 512 }, /* MACHINE_PC98 */
58 { 8, 2, 512 }, /* MACHINE_ALPHA */
60 #define NUSERS (sizeof (users) / sizeof (users[0]))
62 static char *lower(char *);
63 static void read_options(void);
64 static void do_option(char *);
65 static char *tooption(char *);
76 /* Fake the cpu types as options. */
77 for (cp = cputype; cp != NULL; cp = cp->cpu_next) {
78 op = (struct opt *)malloc(sizeof(*op));
79 memset(op, 0, sizeof(*op));
80 op->op_name = ns(cp->cpu_name);
85 /* Initialize `maxusers'. */
86 if ((unsigned)machine > NUSERS) {
87 printf("maxusers config info isn't present, using i386\n");
88 up = &users[MACHINE_I386 - 1];
90 up = &users[machine - 1];
92 /* printf("maxusers not specified; will auto-size\n"); */
94 } else if (maxusers < up->u_min) {
95 printf("minimum of %d maxusers assumed\n", up->u_min);
97 } else if (maxusers > up->u_max)
98 printf("warning: maxusers > %d (%d)\n", up->u_max, maxusers);
100 /* Fake MAXUSERS as an option. */
101 op = (struct opt *)malloc(sizeof(*op));
102 memset(op, 0, sizeof(*op));
103 op->op_name = "MAXUSERS";
104 snprintf(buf, sizeof(buf), "%d", maxusers);
105 op->op_value = ns(buf);
110 for (ol = otab; ol != 0; ol = ol->o_next)
111 do_option(ol->o_name);
112 for (op = opt; op; op = op->op_next) {
113 if (!op->op_ownfile) {
114 printf("%s:%d: unknown option \"%s\"\n",
115 PREFIX, op->op_line, op->op_name);
122 * Generate an <options>.h file
126 do_option(char *name)
128 char *basefile, *file, *inw;
130 struct opt *op, *op_head, *topp;
137 file = tooption(name);
140 * Check to see if the option was specified..
143 for (op = opt; op; op = op->op_next) {
144 if (eq(name, op->op_name)) {
146 value = op->op_value;
149 if (oldvalue != NULL && !eq(value, oldvalue))
151 "%s:%d: option \"%s\" redefined from %s to %s\n",
152 PREFIX, op->op_line, 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 for (ol = otab; ol != 0; ol = ol->o_next)
174 if (eq(name, ol->o_name)) {
175 basefile = ol->o_file;
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 for (ol = otab; ol != 0; ol = ol->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 *) malloc(sizeof *op);
216 bzero(op, sizeof(*op));
218 op->op_value = invalue;
219 op->op_next = op_head;
225 if (cp == (char *)EOF)
229 if (!tidy && ((value == NULL && oldvalue == NULL) ||
230 (value && oldvalue && eq(value, oldvalue)))) {
231 for (op = op_head; op != NULL; op = topp) {
240 if (value && !seen) {
241 /* New option appears */
242 op = (struct opt *) malloc(sizeof *op);
243 bzero(op, sizeof(*op));
244 op->op_name = ns(name);
245 op->op_value = value ? ns(value) : NULL;
246 op->op_next = op_head;
250 outf = fopen(file, "w");
253 for (op = op_head; op != NULL; op = topp) {
254 /* was the option in the config file? */
256 fprintf(outf, "#define %s %s\n",
257 op->op_name, op->op_value);
268 * Find the filename to store the option spec into.
273 static char hbuf[MAXPATHLEN];
274 char nbuf[MAXPATHLEN];
277 /* "cannot happen"? the otab list should be complete.. */
278 (void) strlcpy(nbuf, "options.h", sizeof(nbuf));
280 for (po = otab ; po != 0; po = po->o_next) {
281 if (eq(po->o_name, name)) {
282 strlcpy(nbuf, po->o_file, sizeof(nbuf));
287 (void) strlcpy(hbuf, path(nbuf), sizeof(hbuf));
292 * read the options and options.<machine> files
298 char fname[MAXPATHLEN];
299 char *wd, *this, *val;
302 char genopt[MAXPATHLEN];
306 printf("no ident line specified\n");
309 (void) snprintf(fname, sizeof(fname), "../../conf/options");
311 fp = fopen(fname, "r");
317 if (wd == (char *)EOF) {
321 (void) snprintf(fname, sizeof fname, "../../conf/options.%s", machinename);
322 fp = fopen(fname, "r");
325 (void) snprintf(fname, sizeof fname, "options.%s", machinename);
330 (void) snprintf(fname, sizeof fname, "options.%s", raisestr(ident));
331 fp = fopen(fname, "r");
341 while (((wd = get_word(fp)) != (char *)EOF) && wd)
347 if (val == (char *)EOF)
351 (void) snprintf(genopt, sizeof(genopt), "opt_%s.h", lower(s));
357 for (po = otab ; po != 0; po = po->o_next) {
358 if (eq(po->o_name, this)) {
359 printf("%s: Duplicate option %s.\n",
365 po = (struct opt_list *) malloc(sizeof *po);
366 bzero(po, sizeof(*po));
376 lower(register char *str)
378 register char *cp = str;
382 *str = tolower(*str);