delete sys/vm.h include file
[unix-history] / usr / src / usr.sbin / config / mkheaders.c
CommitLineData
cd68466f
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
86f9c1e9
KB
3 * All rights reserved.
4 *
32ce521f 5 * %sccs.include.redist.c%
cd68466f
DF
6 */
7
524aa063 8#ifndef lint
32ce521f 9static char sccsid[] = "@(#)mkheaders.c 5.6 (Berkeley) %G%";
86f9c1e9 10#endif /* not lint */
e0a482d6 11
900ae8f5 12/*
1614283b 13 * Make all the .h files for the optional entries
900ae8f5
MT
14 */
15
16#include <stdio.h>
17#include <ctype.h>
18#include "config.h"
576264df 19#include "y.tab.h"
900ae8f5 20
900ae8f5
MT
21headers()
22{
e0a482d6 23 register struct file_list *fl;
1614283b 24
e0a482d6
BJ
25 for (fl = ftab; fl != 0; fl = fl->f_next)
26 if (fl->f_needs != 0)
821eeaae 27 do_count(fl->f_needs, fl->f_needs, 1);
1614283b
MT
28}
29
30/*
e0a482d6
BJ
31 * count all the devices of a certain type and recurse to count
32 * whatever the device is connected to
1614283b 33 */
1614283b 34do_count(dev, hname, search)
e0a482d6 35 register char *dev, *hname;
f025f13d 36 int search;
1614283b 37{
e0a482d6
BJ
38 register struct device *dp, *mp;
39 register int count;
900ae8f5 40
e0a482d6
BJ
41 for (count = 0,dp = dtab; dp != 0; dp = dp->d_next)
42 if (dp->d_unit != -1 && eq(dp->d_name, dev)) {
43 if (dp->d_type == PSEUDO_DEVICE) {
73845e07
SL
44 count =
45 dp->d_slave != UNKNOWN ? dp->d_slave : 1;
e0a482d6
BJ
46 break;
47 }
48 count++;
49 /*
50 * Allow holes in unit numbering,
51 * assumption is unit numbering starts
52 * at zero.
53 */
54 if (dp->d_unit + 1 > count)
55 count = dp->d_unit + 1;
56 if (search) {
57 mp = dp->d_conn;
8a659ddd
MK
58 if (mp != 0 && mp != TO_NEXUS &&
59 mp->d_conn != 0 && mp->d_conn != TO_NEXUS) {
821eeaae
BJ
60 do_count(mp->d_name, hname, 0);
61 search = 0;
e0a482d6
BJ
62 }
63 }
1614283b 64 }
e0a482d6 65 do_header(dev, hname, count);
1614283b
MT
66}
67
68do_header(dev, hname, count)
e0a482d6
BJ
69 char *dev, *hname;
70 int count;
1614283b 71{
e0a482d6
BJ
72 char *file, *name, *inw, *toheader(), *tomacro();
73 struct file_list *fl, *fl_head;
74 FILE *inf, *outf;
75 int inc, oldcount;
1614283b 76
e0a482d6
BJ
77 file = toheader(hname);
78 name = tomacro(dev);
79 inf = fopen(file, "r");
80 oldcount = -1;
81 if (inf == 0) {
82 outf = fopen(file, "w");
83 if (outf == 0) {
84 perror(file);
85 exit(1);
86 }
87 fprintf(outf, "#define %s %d\n", name, count);
22d68ad0 88 (void) fclose(outf);
e0a482d6
BJ
89 return;
90 }
91 fl_head = 0;
92 for (;;) {
93 char *cp;
22d68ad0 94 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
e0a482d6 95 break;
22d68ad0 96 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
e0a482d6
BJ
97 break;
98 inw = ns(inw);
99 cp = get_word(inf);
22d68ad0 100 if (cp == 0 || cp == (char *)EOF)
e0a482d6
BJ
101 break;
102 inc = atoi(cp);
103 if (eq(inw, name)) {
104 oldcount = inc;
105 inc = count;
106 }
107 cp = get_word(inf);
73845e07 108 if (cp == (char *)EOF)
e0a482d6
BJ
109 break;
110 fl = (struct file_list *) malloc(sizeof *fl);
111 fl->f_fn = inw;
112 fl->f_type = inc;
113 fl->f_next = fl_head;
114 fl_head = fl;
115 }
22d68ad0 116 (void) fclose(inf);
e0a482d6
BJ
117 if (count == oldcount) {
118 for (fl = fl_head; fl != 0; fl = fl->f_next)
22d68ad0 119 free((char *)fl);
e0a482d6
BJ
120 return;
121 }
122 if (oldcount == -1) {
123 fl = (struct file_list *) malloc(sizeof *fl);
124 fl->f_fn = name;
125 fl->f_type = count;
126 fl->f_next = fl_head;
127 fl_head = fl;
128 }
1614283b 129 outf = fopen(file, "w");
e0a482d6
BJ
130 if (outf == 0) {
131 perror(file);
132 exit(1);
cc03da8f 133 }
e0a482d6 134 for (fl = fl_head; fl != 0; fl = fl->f_next) {
63e21440 135 fprintf(outf, "#define %s %u\n",
e0a482d6 136 fl->f_fn, count ? fl->f_type : 0);
22d68ad0 137 free((char *)fl);
900ae8f5 138 }
22d68ad0 139 (void) fclose(outf);
900ae8f5
MT
140}
141
142/*
e0a482d6 143 * convert a dev name to a .h file name
900ae8f5 144 */
e0a482d6
BJ
145char *
146toheader(dev)
147 char *dev;
900ae8f5 148{
e0a482d6 149 static char hbuf[80];
900ae8f5 150
22d68ad0
BJ
151 (void) strcpy(hbuf, path(dev));
152 (void) strcat(hbuf, ".h");
f025f13d 153 return (hbuf);
900ae8f5
MT
154}
155
156/*
e0a482d6 157 * convert a dev name to a macro name
900ae8f5 158 */
1614283b 159char *tomacro(dev)
e0a482d6 160 register char *dev;
900ae8f5 161{
e0a482d6
BJ
162 static char mbuf[20];
163 register char *cp;
900ae8f5 164
e0a482d6
BJ
165 cp = mbuf;
166 *cp++ = 'N';
167 while (*dev)
168 *cp++ = toupper(*dev++);
169 *cp++ = 0;
f025f13d 170 return (mbuf);
900ae8f5 171}