3 # Copyright 2006-2012, Haiku.
4 # Distributed under the terms of the MIT License.
7 # John Drinkwater, john@nextraweb.com
9 # Use with http://www.linux-usb.org/usb.ids
10 # run as: awk -v HEADERFILE=usbhdr.h -f usb-header.awk usb.ids
14 # field separator, defining because user could have overridden
17 # Pass this in from outside with -v HEADERFILE=filenametouse
18 # we require usbhdr.h for our system
21 # possibly use this in the future
22 cleanvalues =
"[^A-Za-z0-9{}\"'&@?!*.,:;+<> \\t\\/_\\[\\]=#()-]"
23 # ToDo: currently IDs aren't checked, we dumbly assume the source is clean
25 # descriptive output header
27 print "#\tUSBHDR.H: USB Vendors, Devices\n#" > ofile
28 print "#\tGenerated by usb-header.awk, source data from the following URI:\n#\thttp://www.linux-usb.org/usb.ids\n#" > ofile
29 print "#\tHeader created on " strftime
( "%A, %d %b %Y %H:%M:%S %Z", systime
() ) > ofile
30 print "#endif" > ofile
32 # and we start with vendors..
33 print "\ntypedef struct _USB_VENTABLE\n{\n\tunsigned short\tVenId ;\n\tconst char *\tVenName ;\n} USB_VENTABLE, *PUSB_VENTABLE ;\n" > ofile
34 print "USB_VENTABLE\tUsbVenTable [] =\n{" > ofile
37 # matches vendor - starts with an id as first thing on the line
38 # because this occurs first in the header file, we output it without worry
39 /^
[[:xdigit
:]][[:xdigit
:]][[:xdigit
:]][[:xdigit
:]] / {
41 if ( vendorcount
++ > 0 ) {
47 # store vendor ID for possible devices afterwards
49 vendor =
substr($
0, 7)
50 gsub( /\"/, "&&", vendor
)
52 printf formatting
"\t{ 0x" vendorid
", \"" vendor
"\" }" > ofile
56 /^
\t[[:xdigit
:]][[:xdigit
:]][[:xdigit
:]][[:xdigit
:]] / {
58 device =
substr($
0, 8)
59 gsub( /\\/, "&&", device
)
60 gsub( /\"/, "&&", device
)
62 # store device ID for possible devices afterwards
65 devices
[devicecount
, 1] = vendorid
66 devices
[devicecount
, 2] = $
1
67 devices
[devicecount
, 3] = device
70 # We've processed the file, now output.
73 print "\n};\n\n// Use this value for loop control during searching:\n#define\tUSB_VENTABLE_LEN\t(sizeof(UsbVenTable)/sizeof(USB_VENTABLE))\n" > ofile
75 if ( devicecount
> 0 ) {
77 print "typedef struct _USB_DEVTABLE\n{\n\tunsigned short VenId ;\n\tunsigned short DevId ;\n\tconst char *\tChipDesc ;\n} USB_DEVTABLE, *PUSB_DEVTABLE ;\n" > ofile
78 print "USB_DEVTABLE\tUsbDevTable [] =\n{" > ofile
79 for (i =
1; i
<= devicecount
; i
++) {
86 printf formatting
"\t{ 0x" devices
[i
, 1] ", 0x" devices
[i
, 2] ", \"" devices
[i
, 3] "\" }" > ofile
88 print "\n} ;\n\n// Use this value for loop control during searching:\n#define USB_DEVTABLE_LEN (sizeof(UsbDevTable)/sizeof(USB_DEVTABLE))\n" > ofile