2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
9 * All advertising materials mentioning features or use of this software
10 * must display the following acknowledgement:
11 * This product includes software developed by the University of
12 * California, Lawrence Berkeley Laboratories.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the University of
25 * California, Berkeley and its contributors.
26 * 4. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * @(#)mkheaders.c 8.1 (Berkeley) 6/6/93
45 #include <sys/param.h>
53 static int emitcnt __P((struct nvlist *));
54 static int err __P((const char *, char *, FILE *));
55 static char *cntname __P((const char *));
58 * Make headers containing counts, as needed.
63 register struct files *fi;
65 for (fi = allfiles; fi != NULL; fi = fi->fi_next) {
66 if (fi->fi_flags & FI_HIDDEN)
68 if (fi->fi_flags & (FI_NEEDSCOUNT | FI_NEEDSFLAG) &&
77 register struct nvlist *head;
79 register struct nvlist *nv;
86 (void)sprintf(buf, "%s.h", head->nv_name);
88 if ((fp = fopen(fname, "r")) == NULL)
91 while (fgets(buf, sizeof(buf), fp) != NULL) {
94 if (sscanf(buf, "#define %s %d", nam, &cnt) != 2 ||
95 strcmp(nam, cntname(nv->nv_name)) != 0 ||
101 return (err("read", fname, fp));
106 if ((fp = fopen(fname, "w")) == NULL) {
107 (void)fprintf(stderr, "config: cannot write %s: %s\n",
108 fname, strerror(errno));
111 for (nv = head; nv != NULL; nv = nv->nv_next)
112 if (fprintf(fp, "#define\t%s\t%d\n",
113 cntname(nv->nv_name), nv->nv_int) < 0)
114 return (err("writ", fname, fp));
116 return (err("writ", fname, NULL));
127 (void)fprintf(stderr, "config: error %sing %s: %s\n",
128 what, fname, strerror(errno));
137 register const char *src;
139 register char *dst, c;
140 static char buf[100];
144 while ((c = *src++) != 0)
145 *dst++ = islower(c) ? toupper(c) : c;