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