3 # $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
4 # $FreeBSD: src/sys/tools/usbdevs2h.awk,v 1.7 2005/01/07 02:29:25 imp Exp $
5 # $DragonFly: src/sys/bus/usb/Attic/devlist2h.awk,v 1.5 2005/08/07 22:43:17 joerg Exp $
7 # Copyright (c) 1995, 1996 Christopher G. Demetriou
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 # 3. All advertising materials mentioning features or use of this software
19 # must display the following acknowledgement:
20 # This product includes software developed by Christopher G. Demetriou.
21 # 4. The name of the author may not be used to endorse or promote products
22 # derived from this software without specific prior written permission
24 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 print "usage: usbdevs2h.awk <srcfile> [-d|-h]";
45 printf("/*\t\$NetBSD\$\t*/\n\n") > file
46 else if (os ==
"FreeBSD")
47 printf("/* \$FreeBSD\$ */\n\n") > file
48 else if (os ==
"OpenBSD")
49 printf("/*\t\$OpenBSD\$\t*/\n\n") > file
50 else if (os ==
"DragonFly")
51 printf("/*\t\$DragonFly\$\t*/\n\n") > file
53 printf("/* ??? */\n\n") > file
55 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
58 printf(" * generated from:\n") > file
59 printf(" *\t%s\n", VERSION
) > file
60 printf(" */\n") > file
63 function vendor
(hfile
)
67 vendorindex
[$
2] = nvendors
; # record index for this name, for later.
68 vendors
[nvendors
, 1] = $
2; # name
69 vendors
[nvendors
, 2] = $
3; # id
71 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors
[nvendors
, 1],
72 vendors
[nvendors
, 2]) > hfile
79 printf("\t/* ") > hfile
92 printf("%s", $f
) > hfile
98 vendors
[nvendors
, i
] = $f
100 printf("%s", vendors
[nvendors
, i
]) > hfile
107 if (ocomment
&& hfile
)
108 printf(" */") > hfile
113 function product
(hfile
)
117 products
[nproducts
, 1] = $
2; # vendor name
118 products
[nproducts
, 2] = $
3; # product id
119 products
[nproducts
, 3] = $
4; # id
121 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
122 products
[nproducts
, 1], products
[nproducts
, 2], \
123 products
[nproducts
, 3]) > hfile
128 ocomment = oparen =
0
131 printf("\t/* ") > hfile
144 printf("%s", $f
) > hfile
150 products
[nproducts
, i
] = $f
152 printf("%s", products
[nproducts
, i
]) > hfile
159 if (ocomment
&& hfile
)
160 printf(" */") > hfile
165 function dump_dfile
(dfile
)
168 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
169 for (i =
1; i
<= nproducts
; i
++) {
170 printf("\t{\n") > dfile
171 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
172 products
[i
, 1], products
[i
, 1], products
[i
, 2]) > dfile
173 printf("\t ") > dfile
175 printf(",\n") > dfile
177 vendi = vendorindex
[products
[i
, 1]];
178 printf("\t \"") > dfile
181 while (vendors
[vendi
, j
] != "") {
184 printf("%s", vendors
[vendi
, j
]) > dfile
188 printf("\",\n") > dfile
190 printf("\t \"") > dfile
193 while (products
[i
, j
] != "") {
196 printf("%s", products
[i
, j
]) > dfile
200 printf("\",\n") > dfile
201 printf("\t},\n") > dfile
203 for (i =
1; i
<= nvendors
; i
++) {
204 printf("\t{\n") > dfile
205 printf("\t USB_VENDOR_%s, 0,\n", vendors
[i
, 1]) > dfile
206 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
207 printf("\t \"") > dfile
210 while (vendors
[i
, j
] != "") {
213 printf("%s", vendors
[i
, j
]) > dfile
217 printf("\",\n") > dfile
218 printf("\t NULL,\n") > dfile
219 printf("\t},\n") > dfile
221 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
222 printf("};\n") > dfile
227 nproducts = nvendors =
0
228 # Process the command line
229 for (i =
1; i
< ARGC; i
++) {
231 if (arg !~
/^
-[dh
]+$
/ && arg !~
/devs$
/)
234 dfile=
"usbdevs_data.h"
243 while ((getline < srcfile
) > 0) {
247 gsub("\\$", "", VERSION
)
254 if ($
1 ==
"vendor") {
258 if ($
1 ==
"product") {
266 if (blanklines
< 2 && dfile
)
270 # print out the match tables