Make modules work again part 1: wire up the module build for bus/
[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.3 2003/08/15 01:19:54 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         printf("/*\n") > dfile
41         printf(" *\t\$DragonFly\$\n *\n") > dfile
42         printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
43             > dfile
44         printf(" *\n") > dfile
45         printf(" */\n") > dfile
46
47         printf("/*\n") > hfile
48         printf(" *\t\$DragonFly\$\n *\n") > hfile
49         printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
50             > hfile
51         printf(" *\n") > hfile
52         printf(" */\n") > hfile
53 }
54 $1 == "vendor" {
55         nvendors++
56
57         vendorindex[$2] = nvendors;             # record index for this name, for later.
58         vendors[nvendors, 1] = $2;              # name
59         vendors[nvendors, 2] = $3;              # id
60         printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
61             vendors[nvendors, 2]) > hfile
62
63         i = 3; f = 4;
64
65         # comments
66         ocomment = oparen = 0
67         if (f <= NF) {
68                 printf("\t/* ") > hfile
69                 ocomment = 1;
70         }
71         while (f <= NF) {
72                 if ($f == "#") {
73                         printf("(") > hfile
74                         oparen = 1
75                         f++
76                         continue
77                 }
78                 if (oparen) {
79                         printf("%s", $f) > hfile
80                         if (f < NF)
81                                 printf(" ") > hfile
82                         f++
83                         continue
84                 }
85                 vendors[nvendors, i] = $f
86                 printf("%s", vendors[nvendors, i]) > hfile
87                 if (f < NF)
88                         printf(" ") > hfile
89                 i++; f++;
90         }
91         if (oparen)
92                 printf(")") > hfile
93         if (ocomment)
94                 printf(" */") > hfile
95         printf("\n") > hfile
96
97         next
98 }
99 $1 == "product" {
100         nproducts++
101
102         products[nproducts, 1] = $2;            # vendor name
103         products[nproducts, 2] = $3;            # product id
104         products[nproducts, 3] = $4;            # id
105         printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
106             products[nproducts, 2], products[nproducts, 3]) > hfile
107
108         i=4; f = 5;
109
110         # comments
111         ocomment = oparen = 0
112         if (f <= NF) {
113                 printf("\t/* ") > hfile
114                 ocomment = 1;
115         }
116         while (f <= NF) {
117                 if ($f == "#") {
118                         printf("(") > hfile
119                         oparen = 1
120                         f++
121                         continue
122                 }
123                 if (oparen) {
124                         printf("%s", $f) > hfile
125                         if (f < NF)
126                                 printf(" ") > hfile
127                         f++
128                         continue
129                 }
130                 products[nproducts, i] = $f
131                 printf("%s", products[nproducts, i]) > hfile
132                 if (f < NF)
133                         printf(" ") > hfile
134                 i++; f++;
135         }
136         if (oparen)
137                 printf(")") > hfile
138         if (ocomment)
139                 printf(" */") > hfile
140         printf("\n") > hfile
141
142         next
143 }
144 {
145         if ($0 == "")
146                 blanklines++
147         print $0 > hfile
148         if (blanklines < 2)
149                 print $0 > dfile
150 }
151 END {
152         # print out the match tables
153
154         printf("\n") > dfile
155
156         printf("struct usb_knowndev usb_knowndevs[] = {\n") > dfile
157         for (i = 1; i <= nproducts; i++) {
158                 printf("\t{\n") > dfile
159                 printf("\t    USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
160                     products[i, 1], products[i, 1], products[i, 2]) \
161                     > dfile
162                 printf("\t    ") > dfile
163                 printf("0") > dfile
164                 printf(",\n") > dfile
165
166                 vendi = vendorindex[products[i, 1]];
167                 printf("\t    \"") > dfile
168                 j = 3;
169                 needspace = 0;
170                 while (vendors[vendi, j] != "") {
171                         if (needspace)
172                                 printf(" ") > dfile
173                         printf("%s", vendors[vendi, j]) > dfile
174                         needspace = 1
175                         j++
176                 }
177                 printf("\",\n") > dfile
178
179                 printf("\t    \"") > dfile
180                 j = 4;
181                 needspace = 0;
182                 while (products[i, j] != "") {
183                         if (needspace)
184                                 printf(" ") > dfile
185                         printf("%s", products[i, j]) > dfile
186                         needspace = 1
187                         j++
188                 }
189                 printf("\",\n") > dfile
190                 printf("\t},\n") > dfile
191         }
192         for (i = 1; i <= nvendors; i++) {
193                 printf("\t{\n") > dfile
194                 printf("\t    USB_VENDOR_%s, 0,\n", vendors[i, 1]) \
195                     > dfile
196                 printf("\t    USB_KNOWNDEV_NOPROD,\n") \
197                     > dfile
198                 printf("\t    \"") > dfile
199                 j = 3;
200                 needspace = 0;
201                 while (vendors[i, j] != "") {
202                         if (needspace)
203                                 printf(" ") > dfile
204                         printf("%s", vendors[i, j]) > dfile
205                         needspace = 1
206                         j++
207                 }
208                 printf("\",\n") > dfile
209                 printf("\t    NULL,\n") > dfile
210                 printf("\t},\n") > dfile
211         }
212         printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
213         printf("};\n") > dfile
214 }