Deleted Added
full compact
usbdevs2h.awk (139458) usbdevs2h.awk (139513)
1#! /usr/bin/awk -f
2# $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
1#! /usr/bin/awk -f
2# $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
3# $FreeBSD: head/sys/tools/usbdevs2h.awk 139458 2004-12-30 23:18:34Z imp $
3# $FreeBSD: head/sys/tools/usbdevs2h.awk 139513 2004-12-31 21:02:43Z imp $
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

--- 13 unchanged lines hidden (view full) ---

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#
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

--- 13 unchanged lines hidden (view full) ---

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
33function usage()
34{
35 print "usage: usbdevs2h.awk <srcfile> [-d|-h]";
36 exit 1;
37}
38
34function usage()
35{
36 print "usage: usbdevs2h.awk <srcfile> [-d|-h]";
37 exit 1;
38}
39
39BEGIN {
40function dheader(dfile)
41{
42 if (os == "NetBSD")
43 printf("/*\t\$NetBSD\$\t*/\n\n") > dfile
44 else if (os == "FreeBSD")
45 printf("/* \$FreeBSD\$ */\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}
40
58
41nproducts = nvendors = 0
42# Process the command line
43for (i = 1; i < ARGC; i++) {
44 arg = ARGV[i];
45 if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
46 usage();
47 if (arg ~ /^-.*d/)
48 dfile="usbdevs_data.h"
49 if (arg ~ /^-.*h/)
50 hfile="usbdevs.h"
51 if (arg ~ /devs$/)
52 srcfile = arg;
59function hheader(hfile)
60{
61 if (os == "NetBSD")
62 printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
63 else if (os == "FreeBSD")
64 printf("/* \$FreeBSD\$ */\n\n") > hfile
65 else if (os == "OpenBSD")
66 printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile
67 else
68 printf("/* ??? */\n\n") > hfile
69 printf("/*\n") > hfile
70 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
71 > hfile
72 printf(" *\n") > hfile
73 printf(" * generated from:\n") > hfile
74 printf(" *\t%s\n", VERSION) > hfile
75 printf(" */\n") > hfile
53}
76}
54ARGC = 1;
55line=0;
56
77
57while ((getline < srcfile) > 0) {
58 line++;
59 if (line == 1) {
60 VERSION = $0
61 gsub("\\$", "", VERSION)
62
78
63 if (dfile) {
64 if (os == "NetBSD")
65 printf("/*\t\$NetBSD\$\t*/\n\n") > dfile
66 else if (os == "FreeBSD")
67 printf("/* \$FreeBSD\$ */\n\n") > dfile
68 else if (os == "OpenBSD")
69 printf("/*\t\$OpenBSD\$\t*/\n\n") > dfile
70 else
71 printf("/* ??? */\n\n") > dfile
72 printf("/*\n") > dfile
73 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
74 > dfile
75 printf(" *\n") > dfile
76 printf(" * generated from:\n") > dfile
77 printf(" *\t%s\n", VERSION) > dfile
78 printf(" */\n") > dfile
79 }
80
81 if (hfile) {
82 if (os == "NetBSD")
83 printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
84 else if (os == "FreeBSD")
85 printf("/* \$FreeBSD\$ */\n\n") > hfile
86 else if (os == "OpenBSD")
87 printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile
88 else
89 printf("/* ??? */\n\n") > hfile
90 printf("/*\n") > hfile
91 printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
92 > hfile
93 printf(" *\n") > hfile
94 printf(" * generated from:\n") > hfile
95 printf(" *\t%s\n", VERSION) > hfile
96 printf(" */\n") > hfile
97 }
98 continue;
99 }
100 if ($1 == "vendor") {
79function vendor(hfile)
80{
101 nvendors++
102
103 vendorindex[$2] = nvendors; # record index for this name, for later.
104 vendors[nvendors, 1] = $2; # name
105 vendors[nvendors, 2] = $3; # id
106 if (hfile)
107 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
108 vendors[nvendors, 2]) > hfile

--- 30 unchanged lines hidden (view full) ---

139 i++; f++;
140 }
141 if (oparen && hfile)
142 printf(")") > hfile
143 if (ocomment && hfile)
144 printf(" */") > hfile
145 if (hfile)
146 printf("\n") > hfile
81 nvendors++
82
83 vendorindex[$2] = nvendors; # record index for this name, for later.
84 vendors[nvendors, 1] = $2; # name
85 vendors[nvendors, 2] = $3; # id
86 if (hfile)
87 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
88 vendors[nvendors, 2]) > hfile

--- 30 unchanged lines hidden (view full) ---

119 i++; f++;
120 }
121 if (oparen && hfile)
122 printf(")") > hfile
123 if (ocomment && hfile)
124 printf(" */") > hfile
125 if (hfile)
126 printf("\n") > hfile
127}
147
128
148 continue;
149 }
150 if ($1 == "product") {
129function product(hfile)
130{
151 nproducts++
152
153 products[nproducts, 1] = $2; # vendor name
154 products[nproducts, 2] = $3; # product id
155 products[nproducts, 3] = $4; # id
156 if (hfile)
157 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
158 products[nproducts, 1], products[nproducts, 2], \

--- 32 unchanged lines hidden (view full) ---

191 i++; f++;
192 }
193 if (oparen && hfile)
194 printf(")") > hfile
195 if (ocomment && hfile)
196 printf(" */") > hfile
197 if (hfile)
198 printf("\n") > hfile
131 nproducts++
132
133 products[nproducts, 1] = $2; # vendor name
134 products[nproducts, 2] = $3; # product id
135 products[nproducts, 3] = $4; # id
136 if (hfile)
137 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
138 products[nproducts, 1], products[nproducts, 2], \

--- 32 unchanged lines hidden (view full) ---

171 i++; f++;
172 }
173 if (oparen && hfile)
174 printf(")") > hfile
175 if (ocomment && hfile)
176 printf(" */") > hfile
177 if (hfile)
178 printf("\n") > hfile
179}
199
180
200 continue;
201 }
181function dump_dfile(dfile)
182{
183 printf("\n") > dfile
184 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
185 for (i = 1; i <= nproducts; i++) {
186 printf("\t{\n") > dfile
187 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
188 products[i, 1], products[i, 1], products[i, 2]) > dfile
189 printf("\t ") > dfile
190 printf("0") > dfile
191 printf(",\n") > dfile
192
193 vendi = vendorindex[products[i, 1]];
194 printf("\t \"") > dfile
195 j = 3;
196 needspace = 0;
197 while (vendors[vendi, j] != "") {
198 if (needspace)
199 printf(" ") > dfile
200 printf("%s", vendors[vendi, j]) > dfile
201 needspace = 1
202 j++
203 }
204 printf("\",\n") > dfile
205
206 printf("\t \"") > dfile
207 j = 4;
208 needspace = 0;
209 while (products[i, j] != "") {
210 if (needspace)
211 printf(" ") > dfile
212 printf("%s", products[i, j]) > dfile
213 needspace = 1
214 j++
215 }
216 printf("\",\n") > dfile
217 printf("\t},\n") > dfile
218 }
219 for (i = 1; i <= nvendors; i++) {
220 printf("\t{\n") > dfile
221 printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
222 printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
223 printf("\t \"") > dfile
224 j = 3;
225 needspace = 0;
226 while (vendors[i, j] != "") {
227 if (needspace)
228 printf(" ") > dfile
229 printf("%s", vendors[i, j]) > dfile
230 needspace = 1
231 j++
232 }
233 printf("\",\n") > dfile
234 printf("\t NULL,\n") > dfile
235 printf("\t},\n") > dfile
236 }
237 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
238 printf("};\n") > dfile
239}
240
241BEGIN {
242
243nproducts = nvendors = 0
244# Process the command line
245for (i = 1; i < ARGC; i++) {
246 arg = ARGV[i];
247 if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
248 usage();
249 if (arg ~ /^-.*d/)
250 dfile="usbdevs_data.h"
251 if (arg ~ /^-.*h/)
252 hfile="usbdevs.h"
253 if (arg ~ /devs$/)
254 srcfile = arg;
255}
256ARGC = 1;
257line=0;
258
259while ((getline < srcfile) > 0) {
260 line++;
261 if (line == 1) {
262 VERSION = $0
263 gsub("\\$", "", VERSION)
264
265 if (dfile)
266 dheader(dfile)
267
268 if (hfile)
269 hheader(hfile)
270 continue;
271 }
272 if ($1 == "vendor") {
273 vendor(hfile)
274 continue
275 }
276 if ($1 == "product") {
277 product(hfile)
278 continue
279 }
202 if ($0 == "")
203 blanklines++
204 if (hfile)
205 print $0 > hfile
206 if (blanklines < 2 && dfile)
207 print $0 > dfile
208}
280 if ($0 == "")
281 blanklines++
282 if (hfile)
283 print $0 > hfile
284 if (blanklines < 2 && dfile)
285 print $0 > dfile
286}
209 # print out the match tables
210
287
211 if (dfile) {
212 printf("\n") > dfile
288# print out the match tables
213
289
214 printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
215 for (i = 1; i <= nproducts; i++) {
216 printf("\t{\n") > dfile
217 printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
218 products[i, 1], products[i, 1], products[i, 2]) \
219 > dfile
220 printf("\t ") > dfile
221 printf("0") > dfile
222 printf(",\n") > dfile
223
224 vendi = vendorindex[products[i, 1]];
225 printf("\t \"") > dfile
226 j = 3;
227 needspace = 0;
228 while (vendors[vendi, j] != "") {
229 if (needspace)
230 printf(" ") > dfile
231 printf("%s", vendors[vendi, j]) > dfile
232 needspace = 1
233 j++
234 }
235 printf("\",\n") > dfile
236
237 printf("\t \"") > dfile
238 j = 4;
239 needspace = 0;
240 while (products[i, j] != "") {
241 if (needspace)
242 printf(" ") > dfile
243 printf("%s", products[i, j]) > dfile
244 needspace = 1
245 j++
246 }
247 printf("\",\n") > dfile
248 printf("\t},\n") > dfile
249 }
250 for (i = 1; i <= nvendors; i++) {
251 printf("\t{\n") > dfile
252 printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) \
253 > dfile
254 printf("\t USB_KNOWNDEV_NOPROD,\n") \
255 > dfile
256 printf("\t \"") > dfile
257 j = 3;
258 needspace = 0;
259 while (vendors[i, j] != "") {
260 if (needspace)
261 printf(" ") > dfile
262 printf("%s", vendors[i, j]) > dfile
263 needspace = 1
264 j++
265 }
266 printf("\",\n") > dfile
267 printf("\t NULL,\n") > dfile
268 printf("\t},\n") > dfile
269 }
270 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
271 printf("};\n") > dfile
272 }
290if (dfile)
291 dump_dfile(dfile)
273}
292}