Deleted Added
full compact
usbdevs2h.awk (128302) usbdevs2h.awk (139458)
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 128302 2004-04-16 05:22:11Z obrien $
3# $FreeBSD: head/sys/tools/usbdevs2h.awk 139458 2004-12-30 23:18:34Z 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#
33function usage()
34{
35 print "usage: usbdevs2h.awk <srcfile> [-d|-h]";
36 exit 1;
37}
38
33BEGIN {
39BEGIN {
34 nproducts = nvendors = 0
35 dfile="usbdevs_data.h"
36 hfile="usbdevs.h"
40
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;
37}
53}
38NR == 1 {
54ARGC = 1;
55line=0;
56
57while ((getline < srcfile) > 0) {
58 line++;
59 if (line == 1) {
39 VERSION = $0
40 gsub("\\$", "", VERSION)
41
60 VERSION = $0
61 gsub("\\$", "", VERSION)
62
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
58 if (os == "NetBSD")
59 printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
60 else if (os == "FreeBSD")
61 printf("/* \$FreeBSD\$ */\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" {
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") {
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
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
82 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
83 vendors[nvendors, 2]) > hfile
84
106 if (hfile)
107 printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
108 vendors[nvendors, 2]) > hfile
85 i = 3; f = 4;
86
87 # comments
88 ocomment = oparen = 0
89 if (f <= NF) {
109 i = 3; f = 4;
110
111 # comments
112 ocomment = oparen = 0
113 if (f <= NF) {
90 printf("\t/* ") > hfile
114 if (hfile)
115 printf("\t/* ") > hfile
91 ocomment = 1;
92 }
93 while (f <= NF) {
94 if ($f == "#") {
116 ocomment = 1;
117 }
118 while (f <= NF) {
119 if ($f == "#") {
95 printf("(") > hfile
120 if (hfile)
121 printf("(") > hfile
96 oparen = 1
97 f++
98 continue
99 }
100 if (oparen) {
122 oparen = 1
123 f++
124 continue
125 }
126 if (oparen) {
101 printf("%s", $f) > hfile
102 if (f < NF)
127 if (hfile)
128 printf("%s", $f) > hfile
129 if (f < NF && hfile)
103 printf(" ") > hfile
104 f++
105 continue
106 }
107 vendors[nvendors, i] = $f
130 printf(" ") > hfile
131 f++
132 continue
133 }
134 vendors[nvendors, i] = $f
108 printf("%s", vendors[nvendors, i]) > hfile
109 if (f < NF)
135 if (hfile)
136 printf("%s", vendors[nvendors, i]) > hfile
137 if (f < NF && hfile)
110 printf(" ") > hfile
111 i++; f++;
112 }
138 printf(" ") > hfile
139 i++; f++;
140 }
113 if (oparen)
141 if (oparen && hfile)
114 printf(")") > hfile
142 printf(")") > hfile
115 if (ocomment)
143 if (ocomment && hfile)
116 printf(" */") > hfile
144 printf(" */") > hfile
117 printf("\n") > hfile
145 if (hfile)
146 printf("\n") > hfile
118
147
119 next
120}
121$1 == "product" {
148 continue;
149 }
150 if ($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
151 nproducts++
152
153 products[nproducts, 1] = $2; # vendor name
154 products[nproducts, 2] = $3; # product id
155 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
156 if (hfile)
157 printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
158 products[nproducts, 1], products[nproducts, 2], \
159 products[nproducts, 3]) > hfile
129
130 i=4; f = 5;
131
132 # comments
133 ocomment = oparen = 0
134 if (f <= NF) {
160
161 i=4; f = 5;
162
163 # comments
164 ocomment = oparen = 0
165 if (f <= NF) {
135 printf("\t/* ") > hfile
166 if (hfile)
167 printf("\t/* ") > hfile
136 ocomment = 1;
137 }
138 while (f <= NF) {
139 if ($f == "#") {
168 ocomment = 1;
169 }
170 while (f <= NF) {
171 if ($f == "#") {
140 printf("(") > hfile
172 if (hfile)
173 printf("(") > hfile
141 oparen = 1
142 f++
143 continue
144 }
145 if (oparen) {
174 oparen = 1
175 f++
176 continue
177 }
178 if (oparen) {
146 printf("%s", $f) > hfile
147 if (f < NF)
179 if (hfile)
180 printf("%s", $f) > hfile
181 if (f < NF && hfile)
148 printf(" ") > hfile
149 f++
150 continue
151 }
152 products[nproducts, i] = $f
182 printf(" ") > hfile
183 f++
184 continue
185 }
186 products[nproducts, i] = $f
153 printf("%s", products[nproducts, i]) > hfile
154 if (f < NF)
187 if (hfile)
188 printf("%s", products[nproducts, i]) > hfile
189 if (f < NF && hfile)
155 printf(" ") > hfile
156 i++; f++;
157 }
190 printf(" ") > hfile
191 i++; f++;
192 }
158 if (oparen)
193 if (oparen && hfile)
159 printf(")") > hfile
194 printf(")") > hfile
160 if (ocomment)
195 if (ocomment && hfile)
161 printf(" */") > hfile
196 printf(" */") > hfile
162 printf("\n") > hfile
197 if (hfile)
198 printf("\n") > hfile
163
199
164 next
165}
166{
200 continue;
201 }
167 if ($0 == "")
168 blanklines++
202 if ($0 == "")
203 blanklines++
169 print $0 > hfile
170 if (blanklines < 2)
171 print $0 > dfile
204 if (hfile)
205 print $0 > hfile
206 if (blanklines < 2 && dfile)
207 print $0 > dfile
172}
208}
173END {
174 # print out the match tables
175
209 # print out the match tables
210
176 printf("\n") > dfile
211 if (dfile) {
212 printf("\n") > dfile
177
213
178 printf("const 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
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
187
223
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
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
200
236
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++
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
210 }
249 }
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++
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
229 }
269 }
230 printf("\",\n") > dfile
231 printf("\t NULL,\n") > dfile
232 printf("\t},\n") > dfile
270 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
271 printf("};\n") > dfile
233 }
272 }
234 printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
235 printf("};\n") > dfile
236}
273}