devlist2h.awk revision 1.8.72.1 1 1.1 christos #! /usr/bin/awk -f
2 1.8.72.1 yamt # $NetBSD: devlist2h.awk,v 1.8.72.1 2008/05/18 12:34:09 yamt Exp $
3 1.2 christos #
4 1.2 christos # Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.2 christos # All rights reserved.
6 1.2 christos #
7 1.2 christos # This code is derived from software contributed to The NetBSD Foundation
8 1.2 christos # by Christos Zoulas.
9 1.2 christos #
10 1.2 christos # Redistribution and use in source and binary forms, with or without
11 1.2 christos # modification, are permitted provided that the following conditions
12 1.2 christos # are met:
13 1.2 christos # 1. Redistributions of source code must retain the above copyright
14 1.2 christos # notice, this list of conditions and the following disclaimer.
15 1.2 christos # 2. Redistributions in binary form must reproduce the above copyright
16 1.2 christos # notice, this list of conditions and the following disclaimer in the
17 1.2 christos # documentation and/or other materials provided with the distribution.
18 1.2 christos #
19 1.2 christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 christos # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 christos # POSSIBILITY OF SUCH DAMAGE.
30 1.1 christos #
31 1.1 christos # Copyright (c) 1995, 1996 Christopher G. Demetriou
32 1.1 christos # All rights reserved.
33 1.1 christos #
34 1.1 christos # Redistribution and use in source and binary forms, with or without
35 1.1 christos # modification, are permitted provided that the following conditions
36 1.1 christos # are met:
37 1.1 christos # 1. Redistributions of source code must retain the above copyright
38 1.1 christos # notice, this list of conditions and the following disclaimer.
39 1.1 christos # 2. Redistributions in binary form must reproduce the above copyright
40 1.1 christos # notice, this list of conditions and the following disclaimer in the
41 1.1 christos # documentation and/or other materials provided with the distribution.
42 1.1 christos # 3. All advertising materials mentioning features or use of this software
43 1.1 christos # must display the following acknowledgement:
44 1.1 christos # This product includes software developed by Christopher G. Demetriou.
45 1.1 christos # This product includes software developed by Christos Zoulas
46 1.1 christos # 4. The name of the author(s) may not be used to endorse or promote products
47 1.1 christos # derived from this software without specific prior written permission
48 1.1 christos #
49 1.1 christos # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
50 1.1 christos # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 1.1 christos # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52 1.1 christos # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
53 1.1 christos # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
54 1.1 christos # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 1.1 christos # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 1.1 christos # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 1.1 christos # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58 1.1 christos # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 1.1 christos #
60 1.6 jmc function collectline(f) {
61 1.1 christos oparen = 0
62 1.1 christos line = ""
63 1.1 christos while (f <= NF) {
64 1.1 christos if ($f == "#") {
65 1.1 christos line = line "("
66 1.1 christos oparen = 1
67 1.1 christos f++
68 1.1 christos continue
69 1.1 christos }
70 1.1 christos if (oparen) {
71 1.1 christos line = line $f
72 1.1 christos if (f < NF)
73 1.1 christos line = line " "
74 1.1 christos f++
75 1.1 christos continue
76 1.1 christos }
77 1.1 christos line = line $f
78 1.1 christos if (f < NF)
79 1.1 christos line = line " "
80 1.1 christos f++
81 1.1 christos }
82 1.1 christos if (oparen)
83 1.1 christos line = line ")"
84 1.1 christos return line
85 1.1 christos }
86 1.1 christos function checkdecl() {
87 1.1 christos done = 1
88 1.1 christos if (!decl) {
89 1.1 christos decl = 1;
90 1.3 mycroft printf("struct isapnp_matchinfo {\n") > hfile
91 1.3 mycroft printf("\tconst char *name;\n") > hfile
92 1.3 mycroft printf("\tint variant;\n") > hfile
93 1.3 mycroft printf("};\n\n") > hfile
94 1.1 christos printf("struct isapnp_devinfo {\n") > hfile
95 1.3 mycroft printf("\tconst struct isapnp_matchinfo *devlogic;\n") > hfile
96 1.3 mycroft printf("\tint nlogic;\n") > hfile
97 1.3 mycroft printf("\tconst struct isapnp_matchinfo *devcompat;\n") > hfile
98 1.3 mycroft printf("\tint ncompat;\n") > hfile
99 1.1 christos printf("};\n\n") > hfile
100 1.6 jmc printf("\n#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"$NetBSD" "$\");\n\n") > cfile
101 1.1 christos printf("#include <sys/param.h>\n") > cfile
102 1.1 christos printf("#include <dev/isapnp/isapnpdevs.h>\n\n") > cfile
103 1.1 christos }
104 1.1 christos }
105 1.1 christos BEGIN {
106 1.6 jmc decl = done = ncompat = nlogicals = ndriver = blanklines = ncompats = 0
107 1.1 christos cfile="isapnpdevs.c"
108 1.1 christos hfile="isapnpdevs.h"
109 1.1 christos }
110 1.1 christos NR == 1 {
111 1.1 christos VERSION = $0
112 1.1 christos gsub("\\$", "", VERSION)
113 1.7 perry gsub(/ $/, "", VERSION)
114 1.1 christos
115 1.6 jmc printf("/*\t$NetBSD" "$\t*/\n\n") > cfile
116 1.1 christos printf("/*\n") > cfile
117 1.4 augustss printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
118 1.1 christos > cfile
119 1.1 christos printf(" *\n") > cfile
120 1.1 christos printf(" * generated from:\n") > cfile
121 1.1 christos printf(" *\t%s\n", VERSION) > cfile
122 1.1 christos printf(" */\n") > cfile
123 1.1 christos
124 1.6 jmc printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
125 1.1 christos printf("/*\n") > hfile
126 1.4 augustss printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
127 1.1 christos > hfile
128 1.1 christos printf(" *\n") > hfile
129 1.1 christos printf(" * generated from:\n") > hfile
130 1.1 christos printf(" *\t%s\n", VERSION) > hfile
131 1.1 christos printf(" */\n") > hfile
132 1.1 christos printf("\n") > hfile
133 1.1 christos next
134 1.1 christos }
135 1.6 jmc NF > 0 && $1 == "driver" {
136 1.1 christos checkdecl()
137 1.1 christos ndriver++
138 1.1 christos
139 1.1 christos driverindex[$2] = ndriver;
140 1.1 christos driver[ndriver, 1] = $2;
141 1.6 jmc driver[ndriver, 2] = collectline(3);
142 1.1 christos printf("/* %s */\n", driver[ndriver, 2]) > hfile
143 1.1 christos printf("extern const struct isapnp_devinfo isapnp_%s_devinfo;\n",
144 1.1 christos driver[ndriver, 1]) > hfile
145 1.1 christos next
146 1.1 christos }
147 1.6 jmc NF > 0 && $1 == "devlogic" {
148 1.1 christos checkdecl()
149 1.1 christos nlogicals++
150 1.1 christos
151 1.1 christos logicals[nlogicals, 1] = $2;
152 1.1 christos logicals[nlogicals, 2] = $3;
153 1.3 mycroft logicals[nlogicals, 3] = $4;
154 1.6 jmc logicals[nlogicals, 4] = collectline(5);
155 1.1 christos next
156 1.1 christos }
157 1.6 jmc NF > 0 && $1 == "devcompat" {
158 1.1 christos checkdecl()
159 1.1 christos ncompats++
160 1.1 christos
161 1.1 christos compats[ncompats, 1] = $2;
162 1.1 christos compats[ncompats, 2] = $3;
163 1.3 mycroft compats[ncompats, 3] = $4;
164 1.6 jmc compats[ncompats, 4] = collectline(5);
165 1.1 christos next
166 1.1 christos }
167 1.1 christos {
168 1.1 christos if (!done) {
169 1.1 christos if ($0 == "")
170 1.1 christos blanklines++
171 1.1 christos print $0 > hfile
172 1.1 christos if (blanklines < 2)
173 1.1 christos print $0 > cfile
174 1.1 christos }
175 1.1 christos }
176 1.1 christos END {
177 1.1 christos # print out the match tables
178 1.1 christos
179 1.1 christos printf("\n") > cfile
180 1.1 christos
181 1.1 christos for (i = 1; i <= ndriver; i++) {
182 1.3 mycroft nlogical = ncompat = 0;
183 1.1 christos printf("/* %s */\n", driver[i, 2]) > cfile
184 1.1 christos for (j = 1; j <= nlogicals; j++) {
185 1.1 christos if (logicals[j, 1] == driver[i, 1]) {
186 1.3 mycroft if (nlogical == 0)
187 1.3 mycroft printf("static const struct isapnp_matchinfo isapnp_%s_devlogic[] = {\n",
188 1.3 mycroft driver[i, 1]) > cfile
189 1.3 mycroft nlogical++;
190 1.3 mycroft printf("\t{\"%s\", %d},\t/* %s */\n",
191 1.3 mycroft logicals[j, 2], logicals[j, 3],
192 1.3 mycroft logicals[j, 4]) > cfile
193 1.1 christos }
194 1.1 christos }
195 1.3 mycroft if (nlogical != 0)
196 1.3 mycroft printf("};\n") > cfile
197 1.1 christos for (j = 1; j <= ncompats; j++) {
198 1.1 christos if (compats[j, 1] == driver[i, 1]) {
199 1.3 mycroft if (ncompat == 0)
200 1.3 mycroft printf("static const struct isapnp_matchinfo isapnp_%s_devcompat[] = {\n",
201 1.3 mycroft driver[i, 1]) > cfile
202 1.3 mycroft ncompat++;
203 1.3 mycroft printf("\t{\"%s\", %d},\t/* %s */\n",
204 1.3 mycroft compats[j, 2], compats[j, 3],
205 1.3 mycroft compats[j, 4]) > cfile
206 1.1 christos }
207 1.1 christos }
208 1.3 mycroft if (ncompat != 0)
209 1.3 mycroft printf("};\n") > cfile
210 1.1 christos printf("const struct isapnp_devinfo isapnp_%s_devinfo = {\n",
211 1.1 christos driver[i, 1]) > cfile
212 1.3 mycroft if (nlogical != 0)
213 1.3 mycroft printf("\tisapnp_%s_devlogic, %d,\n",
214 1.3 mycroft driver[i, 1], nlogical) > cfile
215 1.3 mycroft else
216 1.3 mycroft printf("\tNULL, 0,\n") > cfile
217 1.3 mycroft if (ncompat != 0)
218 1.3 mycroft printf("\tisapnp_%s_devcompat, %d,\n",
219 1.3 mycroft driver[i, 1], ncompat) > cfile
220 1.3 mycroft else
221 1.3 mycroft printf("\tNULL, 0,\n") > cfile
222 1.3 mycroft printf("};\n\n") > cfile;
223 1.1 christos
224 1.1 christos }
225 1.6 jmc close(cfile)
226 1.6 jmc close(hfile)
227 1.1 christos }
228