2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
38 static const char rcsid[] =
43 * Make all the .h files for the optional entries
50 #include <sys/param.h>
54 static int do_header(char *, int);
55 static void nocount(char *);
56 static char *toheader(char *);
57 static char *tomacro(char *);
68 for (fl = ftab; fl != 0; fl = fl->f_next) {
69 if (fl->f_needs != 0) {
71 for (dp = dtab; dp != 0; dp = dp->d_next) {
72 if (eq(dp->d_name, fl->f_needs)) {
74 dp->d_done |= DEVDONE;
77 if (fl->f_flags & NEED_COUNT)
78 errors += do_header(fl->f_needs, match);
81 for (dp = dtab; dp != 0; dp = dp->d_next) {
82 if (!(dp->d_done & DEVDONE)) {
83 warnx("Error: device \"%s\" is unknown",
87 if (dp->d_count == UNKNOWN)
90 for (fl = ftab; fl != 0; fl = fl->f_next) {
93 if ((fl->f_flags & NEED_COUNT) == 0)
95 if (eq(dp->d_name, fl->f_needs)) {
101 warnx("Error: device \"%s\" does not take a count",
107 errx(1, "%d errors", errors);
111 do_header(char *dev, int match)
113 char *file, *name, *inw;
114 struct file_list *fl, *fl_head, *tflp;
122 * After this loop, "count" will be the actual number of units,
123 * and "hicount" will be the highest unit declared. do_header()
124 * must use this higher of these values.
127 for (hicount = count = 0, dp = dtab; dp != 0; dp = dp->d_next) {
128 if (eq(dp->d_name, dev)) {
129 if (dp->d_count == UNKNOWN) {
130 warnx("Device \"%s\" requires a count", dev);
137 file = toheader(dev);
140 printf("FYI: static unit limits for %s are set: %s=%d\n", dev, name, count);
142 inf = fopen(file, "r");
145 outf = fopen(file, "w");
148 fprintf(outf, "#define %s %d\n", name, count);
155 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
157 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
161 if (cp == 0 || cp == (char *)EOF)
169 if (cp == (char *)EOF)
171 fl = (struct file_list *) malloc(sizeof *fl);
172 bzero(fl, sizeof(*fl));
173 fl->f_fn = inw; /* malloced */
175 fl->f_next = fl_head;
179 if (count == oldcount) {
180 for (fl = fl_head; fl != NULL; fl = tflp) {
187 if (oldcount == -1) {
188 fl = (struct file_list *) malloc(sizeof *fl);
189 bzero(fl, sizeof(*fl));
192 fl->f_next = fl_head;
195 outf = fopen(file, "w");
198 for (fl = fl_head; fl != NULL; fl = tflp) {
200 "#define %s %u\n", fl->f_fn, count ? fl->f_type : 0);
210 * convert a dev name to a .h file name
215 static char hbuf[MAXPATHLEN];
217 snprintf(hbuf, sizeof(hbuf), "%s.h", path(dev));
222 * convert a dev name to a macro name
227 static char mbuf[20];
233 *cp++ = islower(*dev) ? toupper(*dev++) : *dev++;