rename td_token to td_xtoken to deal with conflict against sys/thread.h
[dragonfly.git] / sys / bus / usb / devlist2h.awk
1 #! /usr/bin/awk -f
2 #       $NetBSD: devlist2h.awk,v 1.6 1999/08/17 16:06:20 augustss Exp $
3 #  $FreeBSD: src/sys/dev/usb/devlist2h.awk,v 1.1 1999/11/18 18:02:44 n_hibma Exp $
4 #  $DragonFly: src/sys/bus/usb/Attic/devlist2h.awk,v 1.2 2003/06/17 04:28:32 dillon Exp $
5 #
6 # Copyright (c) 1995, 1996 Christopher G. Demetriou
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 #    notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 #    notice, this list of conditions and the following disclaimer in the
16 #    documentation and/or other materials provided with the distribution.
17 # 3. All advertising materials mentioning features or use of this software
18 #    must display the following acknowledgement:
19 #      This product includes software developed by Christopher G. Demetriou.
20 # 4. The name of the author may not be used to endorse or promote products
21 #    derived from this software without specific prior written permission
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #
34 BEGIN {
35         nproducts = nvendors = 0
36         dfile="usbdevs_data.h"
37         hfile="usbdevs.h"
38 }
39 NR == 1 {
40         VERSION = $0
41         gsub("\\$", "", VERSION)
42
43         if (os == "NetBSD")
44                 printf("/*\t\$NetBSD\$\t*/\n\n") > dfile
45         else if (os == "FreeBSD")
46                 printf("/*\t\$FreeBSD\$\t*/\n\n") > dfile
47         else if (os == "OpenBSD")
48                 printf("/*\t\$OpenBSD\$\t*/\n\n") > dfile
49         else
50                 printf("/* ??? */\n\n") > dfile
51         printf("/*\n") > dfile
52         printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
53             > dfile
54         printf(" *\n") > dfile
55         printf(" * generated from:\n") > dfile
56         printf(" *\t%s\n", VERSION) > dfile
57         printf(" */\n") > dfile
58
59         if (os == "NetBSD")
60                 printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
61         else if (os == "FreeBSD")
62                 printf("/*\t\$FreeBSD\$\t*/\n\n") > hfile
63         else if (os == "OpenBSD")
64                 printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile
65         else
66                 printf("/* ??? */\n\n") > hfile
67         printf("/*\n") > hfile
68         printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
69             > hfile
70         printf(" *\n") > hfile
71         printf(" * generated from:\n") > hfile
72         printf(" *\t%s\n", VERSION) > hfile
73         printf(" */\n") > hfile
74
75         next
76 }
77 $1 == "vendor" {
78         nvendors++
79
80         vendorindex[$2] = nvendors;             # record index for this name, for later.
81         vendors[nvendors, 1] = $2;              # name
82         vendors[nvendors, 2] = $3;              # id
83         printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
84             vendors[nvendors, 2]) > hfile
85
86         i = 3; f = 4;
87
88         # comments
89         ocomment = oparen = 0
90         if (f <= NF) {
91                 printf("\t/* ") > hfile
92                 ocomment = 1;
93         }
94         while (f <= NF) {
95                 if ($f == "#") {
96                         printf("(") > hfile
97                         oparen = 1
98                         f++
99                         continue
100                 }
101                 if (oparen) {
102                         printf("%s", $f) > hfile
103                         if (f < NF)
104                                 printf(" ") > hfile
105                         f++
106                         continue
107                 }
108                 vendors[nvendors, i] = $f
109                 printf("%s", vendors[nvendors, i]) > hfile
110                 if (f < NF)
111                         printf(" ") > hfile
112                 i++; f++;
113         }
114         if (oparen)
115                 printf(")") > hfile
116         if (ocomment)
117                 printf(" */") > hfile
118         printf("\n") > hfile
119
120         next
121 }
122 $1 == "product" {
123         nproducts++
124
125         products[nproducts, 1] = $2;            # vendor name
126         products[nproducts, 2] = $3;            # product id
127         products[nproducts, 3] = $4;            # id
128         printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
129             products[nproducts, 2], products[nproducts, 3]) > hfile
130
131         i=4; f = 5;
132
133         # comments
134         ocomment = oparen = 0
135         if (f <= NF) {
136                 printf("\t/* ") > hfile
137                 ocomment = 1;
138         }
139         while (f <= NF) {
140                 if ($f == "#") {
141                         printf("(") > hfile
142                         oparen = 1
143                         f++
144                         continue
145                 }
146                 if (oparen) {
147                         printf("%s", $f) > hfile
148                         if (f < NF)
149                                 printf(" ") > hfile
150                         f++
151                         continue
152                 }
153                 products[nproducts, i] = $f
154                 printf("%s", products[nproducts, i]) > hfile
155                 if (f < NF)
156                         printf(" ") > hfile
157                 i++; f++;
158         }
159         if (oparen)
160                 printf(")") > hfile
161         if (ocomment)
162                 printf(" */") > hfile
163         printf("\n") > hfile
164
165         next
166 }
167 {
168         if ($0 == "")
169                 blanklines++
170         print $0 > hfile
171         if (blanklines < 2)
172                 print $0 > dfile
173 }
174 END {
175         # print out the match tables
176
177         printf("\n") > dfile
178
179         printf("struct usb_knowndev usb_knowndevs[] = {\n") > dfile
180         for (i = 1; i <= nproducts; i++) {
181                 printf("\t{\n") > dfile
182                 printf("\t    USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
183                     products[i, 1], products[i, 1], products[i, 2]) \
184                     > dfile
185                 printf("\t    ") > dfile
186                 printf("0") > dfile
187                 printf(",\n") > dfile
188
189                 vendi = vendorindex[products[i, 1]];
190                 printf("\t    \"") > dfile
191                 j = 3;
192                 needspace = 0;
193                 while (vendors[vendi, j] != "") {
194                         if (needspace)
195                                 printf(" ") > dfile
196                         printf("%s", vendors[vendi, j]) > dfile
197                         needspace = 1
198                         j++
199                 }
200                 printf("\",\n") > dfile
201
202                 printf("\t    \"") > dfile
203                 j = 4;
204                 needspace = 0;
205                 while (products[i, j] != "") {
206                         if (needspace)
207                                 printf(" ") > dfile
208                         printf("%s", products[i, j]) > dfile
209                         needspace = 1
210                         j++
211                 }
212                 printf("\",\n") > dfile
213                 printf("\t},\n") > dfile
214         }
215         for (i = 1; i <= nvendors; i++) {
216                 printf("\t{\n") > dfile
217                 printf("\t    USB_VENDOR_%s, 0,\n", vendors[i, 1]) \
218                     > dfile
219                 printf("\t    USB_KNOWNDEV_NOPROD,\n") \
220                     > dfile
221                 printf("\t    \"") > dfile
222                 j = 3;
223                 needspace = 0;
224                 while (vendors[i, j] != "") {
225                         if (needspace)
226                                 printf(" ") > dfile
227                         printf("%s", vendors[i, j]) > dfile
228                         needspace = 1
229                         j++
230                 }
231                 printf("\",\n") > dfile
232                 printf("\t    NULL,\n") > dfile
233                 printf("\t},\n") > dfile
234         }
235         printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
236         printf("};\n") > dfile
237 }