3 # $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
5 # SPDX-License-Identifier: BSD-4-Clause
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(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
47 printf(" */\n") > file
50 function vendor(hfile)
54 vendorindex[$2] = nvendors; # record index for this name, for later.
55 vendors[nvendors, 1] = $2; # name
56 vendors[nvendors, 2] = $3; # id
58 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
59 vendors[nvendors, 2]) > hfile
66 printf("\t/* ") > hfile
79 printf("%s", $f) > hfile
85 vendors[nvendors, i] = $f
87 printf("%s", vendors[nvendors, i]) > hfile
94 if (ocomment && hfile)
100 function product(hfile)
104 products[nproducts, 1] = $2; # vendor name
105 products[nproducts, 2] = $3; # product id
106 products[nproducts, 3] = $4; # id
108 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
109 products[nproducts, 1], products[nproducts, 2], \
110 products[nproducts, 3]) > hfile
115 ocomment = oparen = 0
118 printf("\t/* ") > hfile
131 printf("%s", $f) > hfile
137 products[nproducts, i] = $f
139 printf("%s", products[nproducts, i]) > hfile
146 if (ocomment && hfile)
147 printf(" */") > hfile
152 function dump_dfile(dfile)
155 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
156 for (i = 1; i <= nproducts; i++) {
157 printf("\t{\n") > dfile
158 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
159 products[i, 1], products[i, 1], products[i, 2]) > dfile
160 printf("\t ") > dfile
162 printf(",\n") > dfile
164 vendi = vendorindex[products[i, 1]];
165 printf("\t \"") > dfile
168 while (vendors[vendi, j] != "") {
171 printf("%s", vendors[vendi, j]) > dfile
175 printf("\",\n") > dfile
177 printf("\t \"") > dfile
180 while (products[i, j] != "") {
183 printf("%s", products[i, j]) > dfile
187 printf("\",\n") > dfile
188 printf("\t},\n") > dfile
190 for (i = 1; i <= nvendors; i++) {
191 printf("\t{\n") > dfile
192 printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
193 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
194 printf("\t \"") > dfile
197 while (vendors[i, j] != "") {
200 printf("%s", vendors[i, j]) > dfile
204 printf("\",\n") > dfile
205 printf("\t NULL,\n") > dfile
206 printf("\t},\n") > dfile
208 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
209 printf("};\n") > dfile
214 nproducts = nvendors = 0
215 # Process the command line
216 for (i = 1; i < ARGC; i++) {
218 if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
221 dfile="usbdevs_data.h"
230 while ((getline < srcfile) > 0) {
239 if ($1 == "vendor") {
243 if ($1 == "product") {
251 if (blanklines < 2 && dfile)
255 # print out the match tables