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
30 * @(#)mkheaders.c 8.1 (Berkeley) 6/6/93
31 * $FreeBSD: src/usr.sbin/config/mkoptions.c,v 1.17.2.3 2001/12/13 19:18:01 dillon Exp $
35 * Make all the .h files for the optional entries
42 #include <sys/param.h>
46 static char *lower(char *);
47 static void read_options(void);
48 static void do_option(char *);
49 static char *tooption(char *);
59 /* Fake the cpu types as options. */
60 for (cp = cputype; cp != NULL; cp = cp->cpu_next) {
61 op = malloc(sizeof(*op));
62 bzero(op, sizeof(*op));
63 op->op_name = strdup(cp->cpu_name);
69 /* printf("maxusers not specified; will auto-size\n"); */
71 } else if (maxusers < 2) {
72 puts("minimum of 2 maxusers assumed");
74 } else if (maxusers > 512) {
75 printf("warning: maxusers > 512 (%d)\n", maxusers);
78 /* Fake MAXUSERS as an option. */
79 op = malloc(sizeof(*op));
80 bzero(op, sizeof(*op));
81 op->op_name = strdup("MAXUSERS");
82 snprintf(buf, sizeof(buf), "%d", maxusers);
83 op->op_value = strdup(buf);
88 for (ol = otab; ol != NULL; ol = ol->o_next)
89 do_option(ol->o_name);
90 for (op = opt; op != NULL; op = op->op_next) {
91 if (!op->op_ownfile) {
92 printf("%s:%d: unknown option \"%s\"\n",
93 PREFIX, op->op_line, op->op_name);
100 * Generate an <options>.h file
104 do_option(char *name)
106 const char *basefile, *file;
109 struct opt *op, *op_head, *topp;
116 file = tooption(name);
119 * Check to see if the option was specified..
122 for (op = opt; op != NULL; op = op->op_next) {
123 if (strcmp(name, op->op_name) == 0) {
125 value = op->op_value;
128 if (oldvalue != NULL && strcmp(value, oldvalue) != 0)
130 "%s:%d: option \"%s\" redefined from %s to %s\n",
131 PREFIX, op->op_line, op->op_name, oldvalue,
137 inf = fopen(file, "r");
139 outf = fopen(file, "w");
143 /* was the option in the config file? */
145 fprintf(outf, "#define %s %s\n", name, value);
146 } /* else empty file */
152 for (ol = otab; ol != NULL; ol = ol->o_next)
153 if (strcmp(name, ol->o_name) == 0) {
154 basefile = ol->o_file;
165 /* get the #define */
166 if ((inw = get_word(inf)) == NULL || inw == (char *)EOF)
168 /* get the option name */
169 if ((inw = get_word(inf)) == NULL || inw == (char *)EOF)
172 /* get the option value */
173 if ((cp = get_word(inf)) == NULL || cp == (char *)EOF)
176 invalue = strdup(cp); /* malloced */
177 if (strcmp(inw, name) == 0) {
182 for (ol = otab; ol != NULL; ol = ol->o_next)
183 if (strcmp(inw, ol->o_name) == 0)
185 if (strcmp(inw, name) != 0 && ol == NULL) {
186 printf("WARNING: unknown option `%s' removed from %s\n",
189 } else if (ol != NULL && strcmp(basefile, ol->o_file) != 0) {
190 printf("WARNING: option `%s' moved from %s to %s\n",
191 inw, basefile, ol->o_file);
194 op = malloc(sizeof(*op));
195 bzero(op, sizeof(*op));
197 op->op_value = invalue;
198 op->op_next = op_head;
204 if (cp == (char *)EOF)
208 if (!tidy && ((value == NULL && oldvalue == NULL) ||
209 (value && oldvalue && strcmp(value, oldvalue) == 0))) {
210 for (op = op_head; op != NULL; op = topp) {
219 if (value != NULL && !seen) {
220 /* New option appears */
221 op = malloc(sizeof(*op));
222 bzero(op, sizeof(*op));
223 op->op_name = strdup(name);
224 op->op_value = value != NULL ? strdup(value) : NULL;
225 op->op_next = op_head;
229 outf = fopen(file, "w");
232 for (op = op_head; op != NULL; op = topp) {
233 /* was the option in the config file? */
234 if (op->op_value != NULL) {
235 fprintf(outf, "#define %s %s\n",
236 op->op_name, op->op_value);
247 * Find the filename to store the option spec into.
252 static char hbuf[MAXPATHLEN];
253 char nbuf[MAXPATHLEN];
256 /* "cannot happen"? the otab list should be complete.. */
257 strlcpy(nbuf, "options.h", sizeof(nbuf));
259 for (po = otab ; po != NULL; po = po->o_next) {
260 if (strcmp(po->o_name, name) == 0) {
261 strlcpy(nbuf, po->o_file, sizeof(nbuf));
266 strlcpy(hbuf, path(nbuf), sizeof(hbuf));
271 * read the options and options.<machine> files
277 char fname[MAXPATHLEN];
278 char *wd, *this, *val;
281 char genopt[MAXPATHLEN];
285 printf("no ident line specified\n");
288 snprintf(fname, sizeof(fname), "../conf/options");
290 fp = fopen(fname, "r");
296 if (wd == (char *)EOF) {
300 snprintf(fname, sizeof(fname),
301 "../platform/%s/conf/options",
303 fp = fopen(fname, "r");
306 snprintf(fname, sizeof(fname), "options.%s",
312 snprintf(fname, sizeof(fname), "options.%s", raisestr(ident));
313 fp = fopen(fname, "r");
323 while (((wd = get_word(fp)) != (char *)EOF) && wd != NULL)
329 if (val == (char *)EOF)
335 snprintf(genopt, sizeof(genopt), "opt_%s.h", lower(s));
341 for (po = otab; po != NULL; po = po->o_next) {
342 if (strcmp(po->o_name, this) == 0) {
343 printf("%s: Duplicate option %s.\n",
349 po = malloc(sizeof(*po));
350 bzero(po, sizeof(*po));
366 *str = tolower(*str);