3 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
4 # Use is subject to license terms.
8 # The contents of this file are subject to the terms of the
9 # Common Development and Distribution License (the "License").
10 # You may not use this file except in compliance with the License.
12 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13 # or http://www.opensolaris.org/os/licensing.
14 # See the License for the specific language governing permissions
15 # and limitations under the License.
17 # When distributing Covered Code, include this CDDL HEADER in each
18 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19 # If applicable, add the following below this CDDL HEADER, with the
20 # fields enclosed by brackets "[]" replaced with your own identifying
21 # information: Portions Copyright [yyyy] [name of copyright owner]
26 # $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
27 # $FreeBSD: src/sys/tools/usbdevs2h.awk,v 1.7 2005/01/07 02:29:25 imp Exp $
29 # Copyright (c) 1995, 1996 Christopher G. Demetriou
30 # All rights reserved.
32 # Redistribution and use in source and binary forms, with or without
33 # modification, are permitted provided that the following conditions
35 # 1. Redistributions of source code must retain the above copyright
36 # notice, this list of conditions and the following disclaimer.
37 # 2. Redistributions in binary form must reproduce the above copyright
38 # notice, this list of conditions and the following disclaimer in the
39 # documentation and/or other materials provided with the distribution.
40 # 3. All advertising materials mentioning features or use of this software
41 # must display the following acknowledgement:
42 # This product includes software developed by Christopher G. Demetriou.
43 # 4. The name of the author may not be used to endorse or promote products
44 # derived from this software without specific prior written permission
46 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 print "usage: usbdevs2h.awk <srcfile> [-d|-D|-h|-H]";
67 printf("/*\t\$NetBSD\$\t*/\n\n") > file
68 else if (os ==
"FreeBSD")
69 printf("/* \$FreeBSD\$ */\n\n") > file
70 else if (os ==
"OpenBSD")
71 printf("/*\t\$OpenBSD\$\t*/\n\n") > file
74 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
77 printf(" * generated from:\n") > file
78 printf(" * %s\n", VERSION
) > file
79 printf(" */\n") > file
82 function header_guard
(file
)
85 printf("#ifndef\t_SYS_USB_USBDEVS_H\n") > file
86 printf("#define\t_SYS_USB_USBDEVS_H\n\n") > file
89 function header_trailer
(file
)
92 printf("#endif\t/* _SYS_USB_USBDEVS_H */\n") > file
95 function vendor
(hfile
)
99 vendorindex
[$
2] = nvendors
; # record index for this name, for later.
100 vendors
[nvendors
, 1] = $
2; # name
101 vendors
[nvendors
, 2] = $
3; # id
103 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors
[nvendors
, 1],
104 vendors
[nvendors
, 2]) > hfile
109 ocomment = oparen =
0
112 printf("\t/* ") > hfile
125 printf("%s", $f
) > hfile
131 vendors
[nvendors
, i
] = $f
133 printf("%s", vendors
[nvendors
, i
]) > hfile
140 if (ocomment
&& hfile
)
141 printf(" */") > hfile
146 function product
(hfile
)
150 products
[nproducts
, 1] = $
2; # vendor name
151 products
[nproducts
, 2] = $
3; # product id
152 products
[nproducts
, 3] = $
4; # id
154 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
155 products
[nproducts
, 1], products
[nproducts
, 2], \
156 products
[nproducts
, 3]) > hfile
161 ocomment = oparen =
0
164 printf("\t/* ") > hfile
177 printf("%s", $f
) > hfile
183 products
[nproducts
, i
] = $f
185 printf("%s", products
[nproducts
, i
]) > hfile
192 if (ocomment
&& hfile
)
193 printf(" */") > hfile
198 function dump_dfile
(dfile
)
201 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
202 for (i =
1; i
<= nproducts
; i
++) {
203 printf("\t{\n") > dfile
204 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
205 products
[i
, 1], products
[i
, 1], products
[i
, 2]) > dfile
206 printf("\t ") > dfile
208 printf(",\n") > dfile
210 vendi = vendorindex
[products
[i
, 1]];
211 printf("\t \"") > dfile
214 while (vendors
[vendi
, j
] != "") {
217 printf("%s", vendors
[vendi
, j
]) > dfile
221 printf("\",\n") > dfile
223 printf("\t \"") > dfile
226 while (products
[i
, j
] != "") {
229 printf("%s", products
[i
, j
]) > dfile
233 printf("\",\n") > dfile
234 printf("\t},\n") > dfile
236 for (i =
1; i
<= nvendors
; i
++) {
237 printf("\t{\n") > dfile
238 printf("\t USB_VENDOR_%s, 0,\n", vendors
[i
, 1]) > dfile
239 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
240 printf("\t \"") > dfile
243 while (vendors
[i
, j
] != "") {
246 printf("%s", vendors
[i
, j
]) > dfile
250 printf("\",\n") > dfile
251 printf("\t NULL,\n") > dfile
252 printf("\t},\n") > dfile
254 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
255 printf("};\n") > dfile
260 nproducts = nvendors =
0
261 # Process the command line
262 for (i =
1; i
< ARGC; i
++) {
264 if (arg !~
/^
-[dDhH
]+$
/ && arg !~
/devs$
/)
267 dfile=
"usbdevs_data.h"
280 while ((getline < srcfile
) > 0) {
284 gsub("\\$", "", VERSION
)
293 if ($
1 ==
"vendor") {
297 if ($
1 ==
"product") {
305 if (blanklines
< 2 && dfile
)
309 # close off the header guard
312 header_trailer
(hfile
)
314 # print out the match tables