3 # $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
6 # Copyright (c) 1995, 1996 Christopher G. Demetriou
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 3. All advertising materials mentioning features or use of this software
18 # must display the following acknowledgement:
19 # This product includes software developed by Christopher G. Demetriou.
20 # 4. The name of the author may not be used to endorse or promote products
21 # derived from this software without specific prior written permission
23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 print "usage: usbdevs2h.awk <srcfile> [-d|-h]";
44 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
46 printf(" */\n") > file
49 function vendor
(hfile
)
53 vendorindex
[$
2] = nvendors
; # record index for this name, for later.
54 vendors
[nvendors
, 1] = $
2; # name
55 vendors
[nvendors
, 2] = $
3; # id
57 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors
[nvendors
, 1],
58 vendors
[nvendors
, 2]) > hfile
65 printf("\t/* ") > hfile
78 printf("%s", $f
) > hfile
84 vendors
[nvendors
, i
] = $f
86 printf("%s", vendors
[nvendors
, i
]) > hfile
93 if (ocomment
&& hfile
)
99 function product
(hfile
)
103 products
[nproducts
, 1] = $
2; # vendor name
104 products
[nproducts
, 2] = $
3; # product id
105 products
[nproducts
, 3] = $
4; # id
107 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
108 products
[nproducts
, 1], products
[nproducts
, 2], \
109 products
[nproducts
, 3]) > hfile
114 ocomment = oparen =
0
117 printf("\t/* ") > hfile
130 printf("%s", $f
) > hfile
136 products
[nproducts
, i
] = $f
138 printf("%s", products
[nproducts
, i
]) > hfile
145 if (ocomment
&& hfile
)
146 printf(" */") > hfile
151 function dump_dfile
(dfile
)
154 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
155 for (i =
1; i
<= nproducts
; i
++) {
156 printf("\t{\n") > dfile
157 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
158 products
[i
, 1], products
[i
, 1], products
[i
, 2]) > dfile
159 printf("\t ") > dfile
161 printf(",\n") > dfile
163 vendi = vendorindex
[products
[i
, 1]];
164 printf("\t \"") > dfile
167 while (vendors
[vendi
, j
] != "") {
170 printf("%s", vendors
[vendi
, j
]) > dfile
174 printf("\",\n") > dfile
176 printf("\t \"") > dfile
179 while (products
[i
, j
] != "") {
182 printf("%s", products
[i
, j
]) > dfile
186 printf("\",\n") > dfile
187 printf("\t},\n") > dfile
189 for (i =
1; i
<= nvendors
; i
++) {
190 printf("\t{\n") > dfile
191 printf("\t USB_VENDOR_%s, 0,\n", vendors
[i
, 1]) > dfile
192 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
193 printf("\t \"") > dfile
196 while (vendors
[i
, j
] != "") {
199 printf("%s", vendors
[i
, j
]) > dfile
203 printf("\",\n") > dfile
204 printf("\t NULL,\n") > dfile
205 printf("\t},\n") > dfile
207 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
208 printf("};\n") > dfile
213 nproducts = nvendors =
0
214 # Process the command line
215 for (i =
1; i
< ARGC; i
++) {
217 if (arg !~
/^
-[dh
]+$
/ && arg !~
/devs$
/)
220 dfile=
"usbdevs_data.h"
229 while ((getline < srcfile
) > 0) {
238 if ($
1 ==
"vendor") {
242 if ($
1 ==
"product") {
250 if (blanklines
< 2 && dfile
)
254 # print out the match tables