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("/*\t\$NetBSD\$\t*/\n\n") > file
47 else if (os == "FreeBSD")
48 printf("/* \$FreeBSD\$ */\n\n") > file
49 else if (os == "OpenBSD")
50 printf("/*\t\$OpenBSD\$\t*/\n\n") > file
52 printf("/* ??? */\n\n") > file
54 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
57 printf(" * generated from:\n") > file
58 printf(" *\t%s\n", VERSION) > file
59 printf(" */\n") > file
62 function vendor(hfile)
66 vendorindex[$2] = nvendors; # record index for this name, for later.
67 vendors[nvendors, 1] = $2; # name
68 vendors[nvendors, 2] = $3; # id
70 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
71 vendors[nvendors, 2]) > hfile
78 printf("\t/* ") > hfile
91 printf("%s", $f) > hfile
97 vendors[nvendors, i] = $f
99 printf("%s", vendors[nvendors, i]) > hfile
106 if (ocomment && hfile)
107 printf(" */") > hfile
112 function product(hfile)
116 products[nproducts, 1] = $2; # vendor name
117 products[nproducts, 2] = $3; # product id
118 products[nproducts, 3] = $4; # id
120 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
121 products[nproducts, 1], products[nproducts, 2], \
122 products[nproducts, 3]) > hfile
127 ocomment = oparen = 0
130 printf("\t/* ") > hfile
143 printf("%s", $f) > hfile
149 products[nproducts, i] = $f
151 printf("%s", products[nproducts, i]) > hfile
158 if (ocomment && hfile)
159 printf(" */") > hfile
164 function dump_dfile(dfile)
167 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
168 for (i = 1; i <= nproducts; i++) {
169 printf("\t{\n") > dfile
170 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
171 products[i, 1], products[i, 1], products[i, 2]) > dfile
172 printf("\t ") > dfile
174 printf(",\n") > dfile
176 vendi = vendorindex[products[i, 1]];
177 printf("\t \"") > dfile
180 while (vendors[vendi, j] != "") {
183 printf("%s", vendors[vendi, j]) > dfile
187 printf("\",\n") > dfile
189 printf("\t \"") > dfile
192 while (products[i, j] != "") {
195 printf("%s", products[i, j]) > dfile
199 printf("\",\n") > dfile
200 printf("\t},\n") > dfile
202 for (i = 1; i <= nvendors; i++) {
203 printf("\t{\n") > dfile
204 printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
205 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
206 printf("\t \"") > dfile
209 while (vendors[i, j] != "") {
212 printf("%s", vendors[i, j]) > dfile
216 printf("\",\n") > dfile
217 printf("\t NULL,\n") > dfile
218 printf("\t},\n") > dfile
220 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
221 printf("};\n") > dfile
226 nproducts = nvendors = 0
227 # Process the command line
228 for (i = 1; i < ARGC; i++) {
230 if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
233 dfile="usbdevs_data.h"
242 while ((getline < srcfile) > 0) {
246 gsub("\\$", "", VERSION)
253 if ($1 == "vendor") {
257 if ($1 == "product") {
265 if (blanklines < 2 && dfile)
269 # print out the match tables