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: sdiodevs2h.awk <srcfile> [-d|-h]";
45 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
48 printf(" * generated from:\n") > file
49 printf(" *\t%s\n", VERSION) > file
50 printf(" */\n") > file
53 function vendor(hfile)
57 vendorindex[$2] = nvendors; # record index for this name, for later.
58 vendors[nvendors, 1] = $2; # name
59 vendors[nvendors, 2] = $3; # id
61 printf("#define\tSDIO_VENDOR_%s\t%s\t", vendors[nvendors, 1],
62 vendors[nvendors, 2]) > hfile
69 printf("\t/* ") > hfile
82 printf("%s", $f) > hfile
88 vendors[nvendors, i] = $f
90 printf("%s", vendors[nvendors, i]) > hfile
97 if (ocomment && hfile)
103 function product(hfile)
107 products[nproducts, 1] = $2; # vendor name
108 products[nproducts, 2] = $3; # product id
109 products[nproducts, 3] = $4; # id
111 printf("#define\tSDIO_PRODUCT_%s_%s\t%s\t", \
112 products[nproducts, 1], products[nproducts, 2], \
113 products[nproducts, 3]) > hfile
118 ocomment = oparen = 0
121 printf("\t/* ") > hfile
134 printf("%s", $f) > hfile
140 products[nproducts, i] = $f
142 printf("%s", products[nproducts, i]) > hfile
149 if (ocomment && hfile)
150 printf(" */") > hfile
155 function dump_dfile(dfile)
158 printf("const struct sdio_knowndev sdio_knowndevs[] = {\n") > dfile
159 for (i = 1; i <= nproducts; i++) {
160 printf("\t{\n") > dfile
161 printf("\t SDIO_VENDOR_%s, SDIO_PRODUCT_%s_%s,\n",
162 products[i, 1], products[i, 1], products[i, 2]) > dfile
163 printf("\t ") > dfile
165 printf(",\n") > dfile
167 vendi = vendorindex[products[i, 1]];
168 printf("\t \"") > dfile
171 while (vendors[vendi, j] != "") {
174 printf("%s", vendors[vendi, j]) > dfile
178 printf("\",\n") > dfile
180 printf("\t \"") > dfile
183 while (products[i, j] != "") {
186 printf("%s", products[i, j]) > dfile
190 printf("\",\n") > dfile
191 printf("\t},\n") > dfile
193 for (i = 1; i <= nvendors; i++) {
194 printf("\t{\n") > dfile
195 printf("\t SDIO_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
196 printf("\t SDIO_KNOWNDEV_NOPROD,\n") > dfile
197 printf("\t \"") > dfile
200 while (vendors[i, j] != "") {
203 printf("%s", vendors[i, j]) > dfile
207 printf("\",\n") > dfile
208 printf("\t NULL,\n") > dfile
209 printf("\t},\n") > dfile
211 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
212 printf("};\n") > dfile
217 nproducts = nvendors = 0
218 # Process the command line
219 for (i = 1; i < ARGC; i++) {
221 if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
224 dfile="sdiodevs_data.h"
233 while ((getline < srcfile) > 0) {
237 gsub("\\$", "", VERSION)
244 if ($1 == "vendor") {
248 if ($1 == "product") {
256 if (blanklines < 2 && dfile)
260 # print out the match tables