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("/*\t\$NetBSD\$\t*/\n\n") > file
45 else if (os == "FreeBSD")
46 printf("/* \$FreeBSD\$ */\n\n") > file
47 else if (os == "OpenBSD")
48 printf("/*\t\$OpenBSD\$\t*/\n\n") > file
50 printf("/* ??? */\n\n") > file
52 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
55 printf(" * generated from:\n") > file
56 printf(" *\t%s\n", VERSION) > file
57 printf(" */\n") > file
60 function vendor(hfile)
64 vendorindex[$2] = nvendors; # record index for this name, for later.
65 vendors[nvendors, 1] = $2; # name
66 vendors[nvendors, 2] = $3; # id
68 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
69 vendors[nvendors, 2]) > hfile
76 printf("\t/* ") > hfile
89 printf("%s", $f) > hfile
95 vendors[nvendors, i] = $f
97 printf("%s", vendors[nvendors, i]) > hfile
104 if (ocomment && hfile)
105 printf(" */") > hfile
110 function product(hfile)
114 products[nproducts, 1] = $2; # vendor name
115 products[nproducts, 2] = $3; # product id
116 products[nproducts, 3] = $4; # id
118 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
119 products[nproducts, 1], products[nproducts, 2], \
120 products[nproducts, 3]) > hfile
125 ocomment = oparen = 0
128 printf("\t/* ") > hfile
141 printf("%s", $f) > hfile
147 products[nproducts, i] = $f
149 printf("%s", products[nproducts, i]) > hfile
156 if (ocomment && hfile)
157 printf(" */") > hfile
162 function dump_dfile(dfile)
165 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
166 for (i = 1; i <= nproducts; i++) {
167 printf("\t{\n") > dfile
168 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
169 products[i, 1], products[i, 1], products[i, 2]) > dfile
170 printf("\t ") > dfile
172 printf(",\n") > dfile
174 vendi = vendorindex[products[i, 1]];
175 printf("\t \"") > dfile
178 while (vendors[vendi, j] != "") {
181 printf("%s", vendors[vendi, j]) > dfile
185 printf("\",\n") > dfile
187 printf("\t \"") > dfile
190 while (products[i, j] != "") {
193 printf("%s", products[i, j]) > dfile
197 printf("\",\n") > dfile
198 printf("\t},\n") > dfile
200 for (i = 1; i <= nvendors; i++) {
201 printf("\t{\n") > dfile
202 printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
203 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
204 printf("\t \"") > dfile
207 while (vendors[i, j] != "") {
210 printf("%s", vendors[i, j]) > dfile
214 printf("\",\n") > dfile
215 printf("\t NULL,\n") > dfile
216 printf("\t},\n") > dfile
218 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
219 printf("};\n") > dfile
224 nproducts = nvendors = 0
225 # Process the command line
226 for (i = 1; i < ARGC; i++) {
228 if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
231 dfile="usbdevs_data.h"
240 while ((getline < srcfile) > 0) {
244 gsub("\\$", "", VERSION)
251 if ($1 == "vendor") {
255 if ($1 == "product") {
263 if (blanklines < 2 && dfile)
267 # print out the match tables