devlist2h.awk revision 1.9 1 1.1 christos #! /usr/bin/awk -f
2 1.9 perry # $NetBSD: devlist2h.awk,v 1.9 2005/02/27 00:27:43 perry Exp $
3 1.3 christos #
4 1.8 mycroft # Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
5 1.3 christos # All rights reserved.
6 1.3 christos #
7 1.3 christos # This code is derived from software contributed to The NetBSD Foundation
8 1.3 christos # by Christos Zoulas.
9 1.3 christos #
10 1.3 christos # Redistribution and use in source and binary forms, with or without
11 1.3 christos # modification, are permitted provided that the following conditions
12 1.3 christos # are met:
13 1.3 christos # 1. Redistributions of source code must retain the above copyright
14 1.3 christos # notice, this list of conditions and the following disclaimer.
15 1.3 christos # 2. Redistributions in binary form must reproduce the above copyright
16 1.3 christos # notice, this list of conditions and the following disclaimer in the
17 1.3 christos # documentation and/or other materials provided with the distribution.
18 1.3 christos # 3. All advertising materials mentioning features or use of this software
19 1.3 christos # must display the following acknowledgement:
20 1.3 christos # This product includes software developed by the NetBSD
21 1.3 christos # Foundation, Inc. and its contributors.
22 1.3 christos # 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3 christos # contributors may be used to endorse or promote products derived
24 1.3 christos # from this software without specific prior written permission.
25 1.3 christos #
26 1.3 christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3 christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3 christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3 christos # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3 christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3 christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3 christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3 christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3 christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3 christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3 christos # POSSIBILITY OF SUCH DAMAGE.
37 1.1 christos #
38 1.1 christos # Copyright (c) 1995, 1996 Christopher G. Demetriou
39 1.1 christos # All rights reserved.
40 1.1 christos #
41 1.1 christos # Redistribution and use in source and binary forms, with or without
42 1.1 christos # modification, are permitted provided that the following conditions
43 1.1 christos # are met:
44 1.1 christos # 1. Redistributions of source code must retain the above copyright
45 1.1 christos # notice, this list of conditions and the following disclaimer.
46 1.1 christos # 2. Redistributions in binary form must reproduce the above copyright
47 1.1 christos # notice, this list of conditions and the following disclaimer in the
48 1.1 christos # documentation and/or other materials provided with the distribution.
49 1.1 christos # 3. All advertising materials mentioning features or use of this software
50 1.1 christos # must display the following acknowledgement:
51 1.1 christos # This product includes software developed by Christopher G. Demetriou.
52 1.2 christos # This product includes software developed by Christos Zoulas
53 1.2 christos # 4. The name of the author(s) may not be used to endorse or promote products
54 1.1 christos # derived from this software without specific prior written permission
55 1.1 christos #
56 1.1 christos # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
57 1.1 christos # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 1.1 christos # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 1.1 christos # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
60 1.1 christos # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 1.1 christos # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 1.1 christos # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 1.1 christos # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 1.1 christos # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
65 1.1 christos # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 1.1 christos #
67 1.7 jmc function collectline(_f, _line) {
68 1.7 jmc _oparen = 0
69 1.7 jmc _line = ""
70 1.7 jmc while (_f <= NF) {
71 1.7 jmc if ($_f == "#") {
72 1.7 jmc _line = _line "("
73 1.7 jmc _oparen = 1
74 1.7 jmc _f++
75 1.2 christos continue
76 1.2 christos }
77 1.7 jmc if (_oparen) {
78 1.7 jmc _line = _line $_f
79 1.7 jmc if (_f < NF)
80 1.7 jmc _line = _line " "
81 1.7 jmc _f++
82 1.2 christos continue
83 1.2 christos }
84 1.7 jmc _line = _line $_f
85 1.7 jmc if (_f < NF)
86 1.7 jmc _line = _line " "
87 1.7 jmc _f++
88 1.2 christos }
89 1.7 jmc if (_oparen)
90 1.7 jmc _line = _line ")"
91 1.7 jmc return _line
92 1.2 christos }
93 1.1 christos BEGIN {
94 1.7 jmc nproducts = nvendors = blanklines = 0
95 1.1 christos dfile="pcmciadevs_data.h"
96 1.1 christos hfile="pcmciadevs.h"
97 1.5 christos line=""
98 1.1 christos }
99 1.1 christos NR == 1 {
100 1.1 christos VERSION = $0
101 1.1 christos gsub("\\$", "", VERSION)
102 1.1 christos
103 1.7 jmc printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
104 1.1 christos printf("/*\n") > dfile
105 1.1 christos printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
106 1.1 christos > dfile
107 1.1 christos printf(" *\n") > dfile
108 1.1 christos printf(" * generated from:\n") > dfile
109 1.1 christos printf(" *\t%s\n", VERSION) > dfile
110 1.1 christos printf(" */\n") > dfile
111 1.1 christos
112 1.7 jmc printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
113 1.1 christos printf("/*\n") > hfile
114 1.1 christos printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
115 1.1 christos > hfile
116 1.1 christos printf(" *\n") > hfile
117 1.1 christos printf(" * generated from:\n") > hfile
118 1.1 christos printf(" *\t%s\n", VERSION) > hfile
119 1.1 christos printf(" */\n") > hfile
120 1.1 christos
121 1.1 christos next
122 1.1 christos }
123 1.7 jmc NF > 0 && $1 == "vendor" {
124 1.1 christos nvendors++
125 1.1 christos
126 1.1 christos vendorindex[$2] = nvendors; # record index for this name, for later.
127 1.1 christos vendors[nvendors, 1] = $2; # name
128 1.1 christos vendors[nvendors, 2] = $3; # id
129 1.1 christos printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1],
130 1.1 christos vendors[nvendors, 2]) > hfile
131 1.2 christos vendors[nvendors, 3] = collectline(4, line)
132 1.2 christos printf("/* %s */\n", vendors[nvendors, 3]) > hfile
133 1.1 christos next
134 1.1 christos }
135 1.7 jmc NF > 0 && $1 == "product" {
136 1.1 christos nproducts++
137 1.1 christos
138 1.1 christos products[nproducts, 1] = $2; # vendor name
139 1.1 christos products[nproducts, 2] = $3; # product id
140 1.1 christos products[nproducts, 3] = $4; # id
141 1.1 christos
142 1.1 christos f = 5;
143 1.1 christos
144 1.1 christos if ($4 == "{") {
145 1.1 christos products[nproducts, 3] = -1
146 1.1 christos z = "{ "
147 1.1 christos for (i = 0; i < 4; i++) {
148 1.1 christos if (f <= NF) {
149 1.1 christos gsub("&sp", " ", $f)
150 1.1 christos gsub("&tab", "\t", $f)
151 1.1 christos gsub("&nl", "\n", $f)
152 1.1 christos z = z $f " "
153 1.1 christos f++
154 1.1 christos }
155 1.1 christos else {
156 1.1 christos if (i == 3)
157 1.1 christos z = z "NULL "
158 1.1 christos else
159 1.1 christos z = z "NULL, "
160 1.1 christos }
161 1.1 christos }
162 1.1 christos products[nproducts, 4] = z $f
163 1.1 christos f++
164 1.1 christos }
165 1.1 christos else {
166 1.1 christos products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
167 1.1 christos }
168 1.1 christos printf("#define\tPCMCIA_CIS_%s_%s\t%s\n",
169 1.1 christos products[nproducts, 1], products[nproducts, 2],
170 1.1 christos products[nproducts, 4]) > hfile
171 1.1 christos printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
172 1.1 christos products[nproducts, 2], products[nproducts, 3]) > hfile
173 1.1 christos
174 1.2 christos products[nproducts, 5] = collectline(f, line)
175 1.1 christos
176 1.1 christos next
177 1.1 christos }
178 1.1 christos {
179 1.1 christos if ($0 == "")
180 1.1 christos blanklines++
181 1.1 christos print $0 > hfile
182 1.1 christos if (blanklines < 2)
183 1.1 christos print $0 > dfile
184 1.1 christos }
185 1.1 christos END {
186 1.1 christos # print out the match tables
187 1.1 christos
188 1.1 christos printf("\n") > dfile
189 1.1 christos
190 1.4 haya printf("struct pcmcia_knowndev {\n") > dfile
191 1.4 haya printf("\tint vendorid;\n") > dfile
192 1.4 haya printf("\tint productid;\n") > dfile
193 1.4 haya printf("\tstruct pcmcia_knowndev_cis {\n") > dfile
194 1.4 haya printf("\t\tchar *vendor;\n") > dfile
195 1.4 haya printf("\t\tchar *product;\n") > dfile
196 1.4 haya printf("\t\tchar *version;\n") > dfile
197 1.4 haya printf("\t\tchar *revision;\n") > dfile
198 1.4 haya printf("\t}cis;\n") > dfile
199 1.4 haya printf("\tint flags;\n") > dfile
200 1.4 haya printf("\tchar *vendorname;\n") > dfile
201 1.4 haya printf("\tchar *devicename;\n") > dfile
202 1.4 haya printf("\tint reserve;\n") > dfile
203 1.4 haya printf("};\n\n") > dfile
204 1.4 haya printf("#define PCMCIA_CIS_INVALID\t\t{ NULL, NULL, NULL, NULL }\n") > dfile
205 1.4 haya printf("#define PCMCIA_KNOWNDEV_NOPROD\t\t0\n\n") > dfile
206 1.1 christos printf("struct pcmcia_knowndev pcmcia_knowndevs[] = {\n") > dfile
207 1.1 christos for (i = 1; i <= nproducts; i++) {
208 1.1 christos printf("\t{\n") > dfile
209 1.1 christos if (products[i, 3] == -1) {
210 1.1 christos printf("\t PCMCIA_VENDOR_UNKNOWN, PCMCIA_PRODUCT_%s_%s,\n",
211 1.1 christos products[i, 1], products[i, 2]) > dfile
212 1.1 christos } else {
213 1.1 christos printf("\t PCMCIA_VENDOR_%s, PCMCIA_PRODUCT_%s_%s,\n",
214 1.1 christos products[i, 1], products[i, 1], products[i, 2]) > dfile
215 1.1 christos }
216 1.9 perry printf("\t PCMCIA_CIS_%s_%s,\n",
217 1.1 christos products[i, 1], products[i, 2]) > dfile
218 1.1 christos printf("\t ") > dfile
219 1.1 christos printf("0") > dfile
220 1.1 christos printf(",\n") > dfile
221 1.1 christos
222 1.7 jmc if (products[i, 1] in vendorindex) {
223 1.7 jmc vendi = vendorindex[products[i, 1]];
224 1.7 jmc vendname = vendors[vendi, 3]
225 1.7 jmc }
226 1.7 jmc else
227 1.7 jmc vendname = ""
228 1.7 jmc printf("\t \"%s\",\n", vendname) > dfile
229 1.4 haya printf("\t \"%s\",\t}\n", products[i, 5]) > dfile
230 1.4 haya printf("\t,\n") > dfile
231 1.1 christos }
232 1.1 christos for (i = 1; i <= nvendors; i++) {
233 1.1 christos printf("\t{\n") > dfile
234 1.4 haya printf("\t PCMCIA_VENDOR_%s,\n", vendors[i, 1]) > dfile
235 1.1 christos printf("\t PCMCIA_KNOWNDEV_NOPROD,\n") > dfile
236 1.1 christos printf("\t PCMCIA_CIS_INVALID,\n") > dfile
237 1.4 haya printf("\t 0,\n") > dfile
238 1.2 christos printf("\t \"%s\",\n", vendors[i, 3]) > dfile
239 1.1 christos printf("\t NULL,\n") > dfile
240 1.1 christos printf("\t},\n") > dfile
241 1.1 christos }
242 1.1 christos printf("\t{ 0, 0, { NULL, NULL, NULL, NULL }, 0, NULL, NULL, }\n") > dfile
243 1.1 christos printf("};\n") > dfile
244 1.7 jmc close(dfile)
245 1.7 jmc close(hfile)
246 1.1 christos }
247