3 # $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
6 # SPDX-License-Identifier: BSD-4-Clause
8 # Copyright (c) 1995, 1996 Christopher G. Demetriou
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # 3. All advertising materials mentioning features or use of this software
20 # must display the following acknowledgement:
21 # This product includes software developed by Christopher G. Demetriou.
22 # 4. The name of the author may not be used to endorse or promote products
23 # derived from this software without specific prior written permission
25 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 print "usage: usbdevs2h.awk <srcfile> [-d|-h]";
46 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
48 printf(" */\n") > file
51 function vendor(hfile)
55 vendorindex[$2] = nvendors; # record index for this name, for later.
56 vendors[nvendors, 1] = $2; # name
57 vendors[nvendors, 2] = $3; # id
59 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
60 vendors[nvendors, 2]) > hfile
67 printf("\t/* ") > hfile
80 printf("%s", $f) > hfile
86 vendors[nvendors, i] = $f
88 printf("%s", vendors[nvendors, i]) > hfile
95 if (ocomment && hfile)
101 function product(hfile)
105 products[nproducts, 1] = $2; # vendor name
106 products[nproducts, 2] = $3; # product id
107 products[nproducts, 3] = $4; # id
109 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
110 products[nproducts, 1], products[nproducts, 2], \
111 products[nproducts, 3]) > hfile
116 ocomment = oparen = 0
119 printf("\t/* ") > hfile
132 printf("%s", $f) > hfile
138 products[nproducts, i] = $f
140 printf("%s", products[nproducts, i]) > hfile
147 if (ocomment && hfile)
148 printf(" */") > hfile
153 function dump_dfile(dfile)
156 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
157 for (i = 1; i <= nproducts; i++) {
158 printf("\t{\n") > dfile
159 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
160 products[i, 1], products[i, 1], products[i, 2]) > dfile
161 printf("\t ") > dfile
163 printf(",\n") > dfile
165 vendi = vendorindex[products[i, 1]];
166 printf("\t \"") > dfile
169 while (vendors[vendi, j] != "") {
172 printf("%s", vendors[vendi, j]) > dfile
176 printf("\",\n") > dfile
178 printf("\t \"") > dfile
181 while (products[i, j] != "") {
184 printf("%s", products[i, j]) > dfile
188 printf("\",\n") > dfile
189 printf("\t},\n") > dfile
191 for (i = 1; i <= nvendors; i++) {
192 printf("\t{\n") > dfile
193 printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
194 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
195 printf("\t \"") > dfile
198 while (vendors[i, j] != "") {
201 printf("%s", vendors[i, j]) > dfile
205 printf("\",\n") > dfile
206 printf("\t NULL,\n") > dfile
207 printf("\t},\n") > dfile
209 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
210 printf("};\n") > dfile
215 nproducts = nvendors = 0
216 # Process the command line
217 for (i = 1; i < ARGC; i++) {
219 if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
222 dfile="usbdevs_data.h"
231 while ((getline < srcfile) > 0) {
240 if ($1 == "vendor") {
244 if ($1 == "product") {
252 if (blanklines < 2 && dfile)
256 # print out the match tables