Ticket #94: pci-clean-awk.2

File pci-clean-awk.2, 4.9 KB (added by johndrinkwater, 18 years ago)

Fixes the escapement problems

Line 
1# Clean PCI header script
2#
3# Copyright 2006, Haiku.
4# Distributed under the terms of the MIT License.
5#
6# Authors:
7# John Drinkwater, john@nextraweb.com
8#
9# Use with http://pciids.sourceforge.net/pci.ids
10# run as: awk -f pci-clean pci.ids > pcihdr.h
11
12BEGIN {
13 FS = " "
14 print "#if 0"
15 print "#\tPCIHDR.H: PCI Vendors, Devices, and Class Type information\n#"
16 print "#\tGenerated by pci-clean, sourced from the web at the following URL:\n#\thttp://pciids.sourceforge.net/pci.ids\n#"
17 print "#\tHeader created on " strftime( "%A, %d %b %Y %H:%M:%S %Z", systime() )
18 print "#endif"
19}
20
21# matches vendor - starts with an id as first thing on the line
22/^[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
23 if ( length(vendor) > 0 ) vendor = vendor ",\n"
24 vend = substr($0, 7)
25 gsub( /\"/, "\\\"", vend )
26 vendor = vendor "\t{ 0x" $1 ", \"" vend "\" }"
27 # store vendor ID for possible devices afterwards
28 currentVendor = $1
29}
30
31# matches device
32/^\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
33
34 if ( length(devices) > 0 ) devices = devices ",\n"
35 device = substr($0, 8)
36 gsub( /\"/, "\\\"", device )
37 devices = devices "\t{ 0x" currentVendor ", 0x" $1 ", \"" device "\" }"
38}
39
40# matches subvendor device
41/^\t\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
42
43 if ( length(devices) > 0 ) devices = devices ",\n"
44 device = substr($0, 14)
45 gsub( /\"/, "\\\"", device )
46 devices = devices "\t{ 0x" $1 ", 0x" $2 ", \"" device "\" }"
47}
48
49# match device class - store data for later
50/^C [[:xdigit:]][[:xdigit:]] / {
51 class = $2
52 classdes = substr($0, 7)
53 gsub( /\"/, "\\\"", classdes )
54
55}
56
57# match subclass, use device class data captured earlier, and output
58/^\t[[:xdigit:]][[:xdigit:]] / {
59 if ( length(classes) > 0 ) classes = classes ",\n"
60 if ( currentclass != class) { classes = classes "\n"; currentclass = class }
61 subclassdes = substr($0, 6)
62 gsub( /\"/, "\\\"", subclassdes )
63
64 classes = classes "\t{ 0x" class ", 0x" $1 ", 0x00, \"" classdes "\", \"" subclassdes "\", \"\" }"
65 subclass = $1
66}
67
68# match programming interface
69/^\t\t[[:xdigit:]][[:xdigit:]] / {
70 if ( $1 != "00" ) {
71 if ( length(classes) > 0 ) classes = classes ",\n"
72 progif = substr($0, 7)
73 gsub( /\"/, "\\\"", progif )
74 classes = classes "\t{ 0x" class ", 0x" subclass ", 0x" $1 ", \"" classdes "\", \"" subclassdes "\", \"" progif "\" }"
75 }
76}
77
78# We've processed the file, now output.
79END {
80
81 if ( length( vendor ) > 0 ) {
82 print "\ntypedef struct _PCI_VENTABLE\n{\n\tunsigned short\tVenId ;\n\tchar *\tVenFull ;\n} PCI_VENTABLE, *PPCI_VENTABLE ;\n"
83 print "PCI_VENTABLE\tPciVenTable [] =\n{"
84 print vendor
85 print "};\n\n// Use this value for loop control during searching:\n#define\tPCI_VENTABLE_LEN\t(sizeof(PciVenTable)/sizeof(PCI_VENTABLE))\n"
86 }
87
88 if ( length( devices ) > 0 ) {
89
90 print "typedef struct _PCI_DEVTABLE\n{\n\tunsigned short VenId ;\n\tunsigned short DevId ;\n\tchar *\tChipDesc ;\n} PCI_DEVTABLE, *PPCI_DEVTABLE ;\n"
91 print "PCI_DEVTABLE\tPciDevTable [] =\n{"
92 print devices
93 print "} ;\n\n// Use this value for loop control during searching:\n#define PCI_DEVTABLE_LEN (sizeof(PciDevTable)/sizeof(PCI_DEVTABLE))\n";
94
95 }
96
97 if ( length( classes) > 0 ) {
98 print "typedef struct _PCI_CLASSCODETABLE\n{\n\tunsigned char BaseClass ;\n\tunsigned char SubClass ;\n\tunsigned char ProgIf ;\n\tchar *\t\tBaseDesc ;\n\tchar *\t\tSubDesc ;\n\tchar *\t\tProgDesc ;\n} PCI_CLASSCODETABLE, *PPCI_CLASSCODETABLE ;\n"
99 print "PCI_CLASSCODETABLE PciClassCodeTable [] =\n{"
100 print classes
101 print "} ;\n\n// Use this value for loop control during searching:\n#define PCI_CLASSCODETABLE_LEN (sizeof(PciClassCodeTable)/sizeof(PCI_CLASSCODETABLE))\n"
102
103 }
104
105 print "char *\tPciCommandFlags [] =\n{\n\t\"I/O Access\",\n\t\"Memory Access\",\n\t\"Bus Mastering\",\n\t\"Special Cycles\",\n\t\"Memory Write & Invalidate\",\n\t\"Palette Snoop\",\n\t\"Parity Errors\",\n\t\"Wait Cycles\",\n\t\"System Errors\",\n\t\"Fast Back-To-Back\",\n\t\"Reserved 10\",\n\t\"Reserved 11\",\n\t\"Reserved 12\",\n\t\"Reserved 13\",\n\t\"Reserved 14\",\n\t\"Reserved 15\"\n} ;\n"
106 print "// Use this value for loop control during searching:\n#define PCI_COMMANDFLAGS_LEN (sizeof(PciCommandFlags)/sizeof(char *))\n"
107 print "char *\tPciStatusFlags [] =\n{\n\t\"Reserved 0\",\n\t\"Reserved 1\",\n\t\"Reserved 2\",\n\t\"Reserved 3\",\n\t\"Reserved 4\",\n\t\"66 MHz Capable\",\n\t\"User-Defined Features\",\n\t\"Fast Back-To-Back\",\n\t\"Data Parity Reported\",\n\t\"\",\n\t\"\",\n\t\"Signalled Target Abort\",\n\t\"Received Target Abort\",\n\t\"Received Master Abort\",\n\t\"Signalled System Error\",\n\t\"Detected Parity Error\"\n} ;\n"
108 print "// Use this value for loop control during searching:\n#define PCI_STATUSFLAGS_LEN (sizeof(PciStatusFlags)/sizeof(char *))\n"
109 print "char *\tPciDevSelFlags [] =\n{\n\t\"Fast Devsel Speed\",\n\t\"Medium Devsel Speed\",\n\t\"Slow Devsel Speed\",\n\t\"Reserved 9&10\"\n} ;\n"
110 print "// Use this value for loop control during searching:\n#define PCI_DEVSELFLAGS_LEN (sizeof(PciDevSelFlags)/sizeof(char *))\n\n"
111
112}
113
114