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 $
39 * Make all the .h files for the optional entries
46 #include <sys/param.h>
50 static char *lower(char *);
51 static void read_options(void);
52 static void do_option(char *);
53 static char *tooption(char *);
63 /* Fake the cpu types as options. */
64 for (cp = cputype; cp != NULL; cp = cp->cpu_next) {
65 op = malloc(sizeof(*op));
66 bzero(op, sizeof(*op));
67 op->op_name = strdup(cp->cpu_name);
73 /* printf("maxusers not specified; will auto-size\n"); */
75 } else if (maxusers < 2) {
76 puts("minimum of 2 maxusers assumed");
78 } else if (maxusers > 512) {
79 printf("warning: maxusers > 512 (%d)\n", maxusers);
82 /* Fake MAXUSERS as an option. */
83 op = malloc(sizeof(*op));
84 bzero(op, sizeof(*op));
85 op->op_name = strdup("MAXUSERS");
86 snprintf(buf, sizeof(buf), "%d", maxusers);
87 op->op_value = strdup(buf);
92 for (ol = otab; ol != NULL; ol = ol->o_next)
93 do_option(ol->o_name);
94 for (op = opt; op != NULL; op = op->op_next) {
95 if (!op->op_ownfile) {
96 printf("%s:%d: unknown option \"%s\"\n",
97 PREFIX, op->op_line, op->op_name);
104 * Generate an <options>.h file
108 do_option(char *name)
110 const char *basefile, *file;
113 struct opt *op, *op_head, *topp;
120 file = tooption(name);
123 * Check to see if the option was specified..
126 for (op = opt; op != NULL; op = op->op_next) {
127 if (strcmp(name, op->op_name) == 0) {
129 value = op->op_value;
132 if (oldvalue != NULL && strcmp(value, oldvalue) != 0)
134 "%s:%d: option \"%s\" redefined from %s to %s\n",
135 PREFIX, op->op_line, op->op_name, oldvalue,
141 inf = fopen(file, "r");
143 outf = fopen(file, "w");
147 /* was the option in the config file? */
149 fprintf(outf, "#define %s %s\n", name, value);
150 } /* else empty file */
156 for (ol = otab; ol != NULL; ol = ol->o_next)
157 if (strcmp(name, ol->o_name) == 0) {
158 basefile = ol->o_file;
169 /* get the #define */
170 if ((inw = get_word(inf)) == NULL || inw == (char *)EOF)
172 /* get the option name */
173 if ((inw = get_word(inf)) == NULL || inw == (char *)EOF)
176 /* get the option value */
177 if ((cp = get_word(inf)) == NULL || cp == (char *)EOF)
180 invalue = strdup(cp); /* malloced */
181 if (strcmp(inw, name) == 0) {
186 for (ol = otab; ol != NULL; ol = ol->o_next)
187 if (strcmp(inw, ol->o_name) == 0)
189 if (strcmp(inw, name) != 0 && ol == NULL) {
190 printf("WARNING: unknown option `%s' removed from %s\n",
193 } else if (ol != NULL && strcmp(basefile, ol->o_file) != 0) {
194 printf("WARNING: option `%s' moved from %s to %s\n",
195 inw, basefile, ol->o_file);
198 op = malloc(sizeof(*op));
199 bzero(op, sizeof(*op));
201 op->op_value = invalue;
202 op->op_next = op_head;
208 if (cp == (char *)EOF)
212 if (!tidy && ((value == NULL && oldvalue == NULL) ||
213 (value && oldvalue && strcmp(value, oldvalue) == 0))) {
214 for (op = op_head; op != NULL; op = topp) {
223 if (value != NULL && !seen) {
224 /* New option appears */
225 op = malloc(sizeof(*op));
226 bzero(op, sizeof(*op));
227 op->op_name = strdup(name);
228 op->op_value = value != NULL ? strdup(value) : NULL;
229 op->op_next = op_head;
233 outf = fopen(file, "w");
236 for (op = op_head; op != NULL; op = topp) {
237 /* was the option in the config file? */
238 if (op->op_value != NULL) {
239 fprintf(outf, "#define %s %s\n",
240 op->op_name, op->op_value);
251 * Find the filename to store the option spec into.
256 static char hbuf[MAXPATHLEN];
257 char nbuf[MAXPATHLEN];
260 /* "cannot happen"? the otab list should be complete.. */
261 strlcpy(nbuf, "options.h", sizeof(nbuf));
263 for (po = otab ; po != NULL; po = po->o_next) {
264 if (strcmp(po->o_name, name) == 0) {
265 strlcpy(nbuf, po->o_file, sizeof(nbuf));
270 strlcpy(hbuf, path(nbuf), sizeof(hbuf));
275 * read the options and options.<machine> files
281 char fname[MAXPATHLEN];
282 char *wd, *this, *val;
285 char genopt[MAXPATHLEN];
289 printf("no ident line specified\n");
292 snprintf(fname, sizeof(fname), "../conf/options");
294 fp = fopen(fname, "r");
300 if (wd == (char *)EOF) {
304 snprintf(fname, sizeof(fname),
305 "../platform/%s/conf/options",
307 fp = fopen(fname, "r");
310 snprintf(fname, sizeof(fname), "options.%s",
316 snprintf(fname, sizeof(fname), "options.%s", raisestr(ident));
317 fp = fopen(fname, "r");
327 while (((wd = get_word(fp)) != (char *)EOF) && wd != NULL)
333 if (val == (char *)EOF)
339 snprintf(genopt, sizeof(genopt), "opt_%s.h", lower(s));
345 for (po = otab; po != NULL; po = po->o_next) {
346 if (strcmp(po->o_name, this) == 0) {
347 printf("%s: Duplicate option %s.\n",
353 po = malloc(sizeof(*po));
354 bzero(po, sizeof(*po));
370 *str = tolower(*str);