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") \
49 printf(" * generated from:\n") > file
50 printf(" *\t%s\n", VERSION) > file
51 printf(" */\n") > file
54 function vendor(hfile)
58 vendorindex[$2] = nvendors; # record index for this name, for later.
59 vendors[nvendors, 1] = $2; # name
60 vendors[nvendors, 2] = $3; # id
62 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
63 vendors[nvendors, 2]) > hfile
70 printf("\t/* ") > hfile
83 printf("%s", $f) > hfile
89 vendors[nvendors, i] = $f
91 printf("%s", vendors[nvendors, i]) > hfile
98 if (ocomment && hfile)
104 function product(hfile)
108 products[nproducts, 1] = $2; # vendor name
109 products[nproducts, 2] = $3; # product id
110 products[nproducts, 3] = $4; # id
112 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
113 products[nproducts, 1], products[nproducts, 2], \
114 products[nproducts, 3]) > hfile
119 ocomment = oparen = 0
122 printf("\t/* ") > hfile
135 printf("%s", $f) > hfile
141 products[nproducts, i] = $f
143 printf("%s", products[nproducts, i]) > hfile
150 if (ocomment && hfile)
151 printf(" */") > hfile
156 function dump_dfile(dfile)
159 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
160 for (i = 1; i <= nproducts; i++) {
161 printf("\t{\n") > dfile
162 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
163 products[i, 1], products[i, 1], products[i, 2]) > dfile
164 printf("\t ") > dfile
166 printf(",\n") > dfile
168 vendi = vendorindex[products[i, 1]];
169 printf("\t \"") > dfile
172 while (vendors[vendi, j] != "") {
175 printf("%s", vendors[vendi, j]) > dfile
179 printf("\",\n") > dfile
181 printf("\t \"") > dfile
184 while (products[i, j] != "") {
187 printf("%s", products[i, j]) > dfile
191 printf("\",\n") > dfile
192 printf("\t},\n") > dfile
194 for (i = 1; i <= nvendors; i++) {
195 printf("\t{\n") > dfile
196 printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
197 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
198 printf("\t \"") > dfile
201 while (vendors[i, j] != "") {
204 printf("%s", vendors[i, j]) > dfile
208 printf("\",\n") > dfile
209 printf("\t NULL,\n") > dfile
210 printf("\t},\n") > dfile
212 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
213 printf("};\n") > dfile
218 nproducts = nvendors = 0
219 # Process the command line
220 for (i = 1; i < ARGC; i++) {
222 if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
225 dfile="usbdevs_data.h"
234 while ((getline < srcfile) > 0) {
238 gsub("\\$", "", VERSION)
245 if ($1 == "vendor") {
249 if ($1 == "product") {
257 if (blanklines < 2 && dfile)
261 # print out the match tables