Now that I understand the poorly written BSD routing code and what
[dragonfly.git] / sys / bus / usb / devlist2h.awk
1 #! /usr/bin/awk -f
2 #  
3 # $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
4 # $FreeBSD: src/sys/dev/usb/devlist2h.awk,v 1.2 2002/04/01 19:22:04 joe Exp $
5 # $DragonFly: src/sys/bus/usb/Attic/devlist2h.awk,v 1.4 2003/12/30 01:01:44 dillon Exp $
6 #
7 # Copyright (c) 1995, 1996 Christopher G. Demetriou
8 # All rights reserved.
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
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
23 #
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.
34 #
35 BEGIN {
36         nproducts = nvendors = 0
37         dfile="usbdevs_data.h"
38         hfile="usbdevs.h"
39 }
40 NR == 1 {
41         printf("/*\n") > dfile
42         printf(" *\t\$DragonFly\$\n *\n") > dfile
43         printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
44             > dfile
45         printf(" *\n") > dfile
46         printf(" */\n") > dfile
47
48         printf("/*\n") > hfile
49         printf(" *\t\$DragonFly\$\n *\n") > hfile
50         printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
51             > hfile
52         printf(" *\n") > hfile
53         printf(" */\n") > hfile
54 }
55 $1 == "vendor" {
56         nvendors++
57
58         vendorindex[$2] = nvendors;             # record index for this name, for later.
59         vendors[nvendors, 1] = $2;              # name
60         vendors[nvendors, 2] = $3;              # id
61         printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
62             vendors[nvendors, 2]) > hfile
63
64         i = 3; f = 4;
65
66         # comments
67         ocomment = oparen = 0
68         if (f <= NF) {
69                 printf("\t/* ") > hfile
70                 ocomment = 1;
71         }
72         while (f <= NF) {
73                 if ($f == "#") {
74                         printf("(") > hfile
75                         oparen = 1
76                         f++
77                         continue
78                 }
79                 if (oparen) {
80                         printf("%s", $f) > hfile
81                         if (f < NF)
82                                 printf(" ") > hfile
83                         f++
84                         continue
85                 }
86                 vendors[nvendors, i] = $f
87                 printf("%s", vendors[nvendors, i]) > hfile
88                 if (f < NF)
89                         printf(" ") > hfile
90                 i++; f++;
91         }
92         if (oparen)
93                 printf(")") > hfile
94         if (ocomment)
95                 printf(" */") > hfile
96         printf("\n") > hfile
97
98         next
99 }
100 $1 == "product" {
101         nproducts++
102
103         products[nproducts, 1] = $2;            # vendor name
104         products[nproducts, 2] = $3;            # product id
105         products[nproducts, 3] = $4;            # id
106         printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
107             products[nproducts, 2], products[nproducts, 3]) > hfile
108
109         i=4; f = 5;
110
111         # comments
112         ocomment = oparen = 0
113         if (f <= NF) {
114                 printf("\t/* ") > hfile
115                 ocomment = 1;
116         }
117         while (f <= NF) {
118                 if ($f == "#") {
119                         printf("(") > hfile
120                         oparen = 1
121                         f++
122                         continue
123                 }
124                 if (oparen) {
125                         printf("%s", $f) > hfile
126                         if (f < NF)
127                                 printf(" ") > hfile
128                         f++
129                         continue
130                 }
131                 products[nproducts, i] = $f
132                 printf("%s", products[nproducts, i]) > hfile
133                 if (f < NF)
134                         printf(" ") > hfile
135                 i++; f++;
136         }
137         if (oparen)
138                 printf(")") > hfile
139         if (ocomment)
140                 printf(" */") > hfile
141         printf("\n") > hfile
142
143         next
144 }
145 {
146         if ($0 == "")
147                 blanklines++
148         print $0 > hfile
149         if (blanklines < 2)
150                 print $0 > dfile
151 }
152 END {
153         # print out the match tables
154
155         printf("\n") > dfile
156
157         printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
158         for (i = 1; i <= nproducts; i++) {
159                 printf("\t{\n") > dfile
160                 printf("\t    USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
161                     products[i, 1], products[i, 1], products[i, 2]) \
162                     > dfile
163                 printf("\t    ") > dfile
164                 printf("0") > dfile
165                 printf(",\n") > dfile
166
167                 vendi = vendorindex[products[i, 1]];
168                 printf("\t    \"") > dfile
169                 j = 3;
170                 needspace = 0;
171                 while (vendors[vendi, j] != "") {
172                         if (needspace)
173                                 printf(" ") > dfile
174                         printf("%s", vendors[vendi, j]) > dfile
175                         needspace = 1
176                         j++
177                 }
178                 printf("\",\n") > dfile
179
180                 printf("\t    \"") > dfile
181                 j = 4;
182                 needspace = 0;
183                 while (products[i, j] != "") {
184                         if (needspace)
185                                 printf(" ") > dfile
186                         printf("%s", products[i, j]) > dfile
187                         needspace = 1
188                         j++
189                 }
190                 printf("\",\n") > dfile
191                 printf("\t},\n") > dfile
192         }
193         for (i = 1; i <= nvendors; i++) {
194                 printf("\t{\n") > dfile
195                 printf("\t    USB_VENDOR_%s, 0,\n", vendors[i, 1]) \
196                     > dfile
197                 printf("\t    USB_KNOWNDEV_NOPROD,\n") \
198                     > dfile
199                 printf("\t    \"") > dfile
200                 j = 3;
201                 needspace = 0;
202                 while (vendors[i, j] != "") {
203                         if (needspace)
204                                 printf(" ") > dfile
205                         printf("%s", vendors[i, j]) > dfile
206                         needspace = 1
207                         j++
208                 }
209                 printf("\",\n") > dfile
210                 printf("\t    NULL,\n") > dfile
211                 printf("\t},\n") > dfile
212         }
213         printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
214         printf("};\n") > dfile
215 }