Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / usb / devlist2h.awk
blob1f99a66af8d96c4a7bac8e8878bd6246eddcef47
1 #! /usr/bin/awk -f
2 # $NetBSD: devlist2h.awk,v 1.9.24.4 2005/03/04 16:50:54 skrll Exp $
4 # Copyright (c) 1995, 1996 Christopher G. Demetriou
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. All advertising materials mentioning features or use of this software
16 # must display the following acknowledgement:
17 # This product includes software developed by Christopher G. Demetriou.
18 # 4. The name of the author may not be used to endorse or promote products
19 # derived from this software without specific prior written permission
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 BEGIN {
33 nproducts = nvendors = blanklines = 0
34 dfile="usbdevs_data.h"
35 hfile="usbdevs.h"
37 NR == 1 {
38 VERSION = $0
39 gsub("\\$", "", VERSION)
40 gsub(/ $/, "", VERSION)
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
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
74 next
76 NF > 0 && $1 == "vendor" {
77 nvendors++
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
85 i = 3; f = 4;
87 # comments
88 ocomment = oparen = 0
89 if (f <= NF) {
90 printf("\t/* ") > hfile
91 ocomment = 1;
93 while (f <= NF) {
94 if ($f == "#") {
95 printf("(") > hfile
96 oparen = 1
97 f++
98 continue
100 if (oparen) {
101 printf("%s", $f) > hfile
102 if (f < NF)
103 printf(" ") > hfile
105 continue
107 vendors[nvendors, i] = $f
108 printf("%s", vendors[nvendors, i]) > hfile
109 if (f < NF)
110 printf(" ") > hfile
111 i++; f++;
113 if (oparen)
114 printf(")") > hfile
115 if (ocomment)
116 printf(" */") > hfile
117 printf("\n") > hfile
119 next
121 NF > 0 && $1 == "product" {
122 nproducts++
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
130 i=4; f = 5;
132 # comments
133 ocomment = oparen = 0
134 if (f <= NF) {
135 printf("\t/* ") > hfile
136 ocomment = 1;
138 while (f <= NF) {
139 if ($f == "#") {
140 printf("(") > hfile
141 oparen = 1
143 continue
145 if (oparen) {
146 printf("%s", $f) > hfile
147 if (f < NF)
148 printf(" ") > hfile
150 continue
152 products[nproducts, i] = $f
153 printf("%s", products[nproducts, i]) > hfile
154 if (f < NF)
155 printf(" ") > hfile
156 i++; f++;
158 if (oparen)
159 printf(")") > hfile
160 if (ocomment)
161 printf(" */") > hfile
162 printf("\n") > hfile
164 next
167 if ($0 == "")
168 blanklines++
169 print $0 > hfile
170 if (blanklines < 2)
171 print $0 > dfile
173 END {
174 # print out the match tables
176 printf("\n") > dfile
178 printf("const struct usb_vendor usb_vendors[] = {\n") > dfile
179 for (i = 1; i <= nvendors; i++) {
180 printf("\t{\n") > dfile
181 printf("\t USB_VENDOR_%s,\n", vendors[i, 1]) \
182 > dfile
184 printf("\t \"") > dfile
185 j = 3;
186 needspace = 0;
187 while ((i, j) in vendors) {
188 if (needspace)
189 printf(" ") > dfile
190 printf("%s", vendors[i, j]) > dfile
191 needspace = 1
194 printf("\",\n") > dfile
195 printf("\t},\n") > dfile
197 printf("};\n") > dfile
198 printf("const int usb_nvendors = %d;\n", nvendors) > dfile
200 printf("\n") > dfile
202 printf("const struct usb_product usb_products[] = {\n") > dfile
203 for (i = 1; i <= nproducts; i++) {
204 printf("\t{\n") > dfile
205 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
206 products[i, 1], products[i, 1], products[i, 2]) \
207 > dfile
209 printf("\t \"") > dfile
210 j = 4;
211 needspace = 0;
212 while ((i, j) in products) {
213 if (needspace)
214 printf(" ") > dfile
215 printf("%s", products[i, j]) > dfile
216 needspace = 1
219 printf("\",\n") > dfile
220 printf("\t},\n") > dfile
222 printf("};\n") > dfile
223 printf("const int usb_nproducts = %d;\n", nproducts) > dfile
225 close(dfile)
226 close(hfile)