From 1f955d54d8d08f9492c51d8a20b99c137bcb0add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 2 Feb 2006 13:22:19 +0000 Subject: [PATCH] John Drinkwater provided a new version which could avoid problem met with some R5 awk this one doesn't require pipe usage git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16199 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/devices/Jamfile | 2 +- src/preferences/devices/pci-clean.awk | 127 +++++++++++++++----------- 2 files changed, 75 insertions(+), 54 deletions(-) diff --git a/src/preferences/devices/Jamfile b/src/preferences/devices/Jamfile index 9204e9b6fb..75f81ee0cc 100644 --- a/src/preferences/devices/Jamfile +++ b/src/preferences/devices/Jamfile @@ -51,7 +51,7 @@ rule PCIHeaderGen actions PCIHeaderGen1 { - awk -f $(2[2]) $(2[1]) > $(1) + awk -v HEADERFILE=$(1) -f $(2[2]) $(2[1]) } PCIHeaderGen [ FGristFiles pcihdr.h ] : pci.ids : pci-clean.awk ; diff --git a/src/preferences/devices/pci-clean.awk b/src/preferences/devices/pci-clean.awk index d7613a0e2f..d6656f1b0f 100644 --- a/src/preferences/devices/pci-clean.awk +++ b/src/preferences/devices/pci-clean.awk @@ -7,26 +7,27 @@ # John Drinkwater, john@nextraweb.com # # Use with http://pciids.sourceforge.net/pci.ids -# run as: awk -f pci-clean.awk pci.ids > pcihdr.h +# run as: awk -v HEADERFILE=pcihdr.h -f pci-header.awk pci.ids BEGIN { FS = " " - print "#if 0" - print "#\tPCIHDR.H: PCI Vendors, Devices, and Class Type information\n#" - print "#\tGenerated by pci-clean, sourced from the web at the following URL:\n#\thttp://pciids.sourceforge.net/pci.ids\n#" - print "#\tHeader created on " strftime( "%A, %d %b %Y %H:%M:%S %Z", systime() ) - print "#endif" + ofile = HEADERFILE + print "#if 0" > ofile + print "#\tPCIHDR.H: PCI Vendors, Devices, and Class Type information\n#" > ofile + print "#\tGenerated by pci-clean, sourced from the web at the following URL:\n#\thttp://pciids.sourceforge.net/pci.ids\n#" > ofile + print "#\tHeader created on " strftime( "%A, %d %b %Y %H:%M:%S %Z", systime() ) > ofile + print "#endif" > ofile + + print "\ntypedef struct _PCI_VENTABLE\n{\n\tunsigned short\tVenId ;\n\tchar *\tVenFull ;\n\tchar *\tVenShort ;\n} PCI_VENTABLE, *PPCI_VENTABLE ;\n" > ofile + print "PCI_VENTABLE\tPciVenTable [] =\n{" > ofile - print "typedef struct _PCI_DEVTABLE\n{\n\tunsigned short VenId ;\n\tunsigned short DevId ;\n\tchar *\tChipDesc ;\n\tchar *\tChip ;\n} PCI_DEVTABLE, *PPCI_DEVTABLE ;\n" - print "PCI_DEVTABLE\tPciDevTable [] =\n{" } # matches vendor - starts with an id as first thing on the line /^[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { - if ( length(vendor) > 0 ) vendor = vendor ",\n" - vend = substr($0, 7) - gsub( /\"/, "\\\"", vend ) - vendor = vendor "\t{ 0x" $1 ", \"" vend "\" }" + if ( vendor++ > 0 ) { a = ",\n" } else { a = "" } + vend = substr($0, 7); gsub( /\"/, "\\\"", vend ) + printf a "\t{ 0x" $1 ", \"" vend "\" }" > ofile # store vendor ID for possible devices afterwards currentVendor = $1 } @@ -34,76 +35,96 @@ BEGIN { # matches device /^\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { - if ( devices++ > 0 ) { a = "," } else { a = "" } - device = substr($0, 8) - gsub( /\"/, "\\\"", device ) - print "\t" a "{ 0x" currentVendor ", 0x" $1 ", \"" device "\" }" + device = substr($0, 8); gsub( /\"/, "\\\"", device ) + devicecount++ + devices[devicecount, 1] = currentVendor + devices[devicecount, 2] = $1 + devices[devicecount, 3] = device } # matches subvendor device /^\t\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { - if ( devices++ > 0 ) { a = "," } else { a = "" } - device = substr($0, 14) - gsub( /\"/, "\\\"", device ) - print "\t" a "{ 0x" $1 ", 0x" $2 ", \"" device "\" }" + device = substr($0, 14); gsub( /\"/, "\\\"", device ) + devicecount++ + devices[devicecount, 1] = $1 + devices[devicecount, 2] = $2 + devices[devicecount, 3] = device } # match device class - store data for later /^C [[:xdigit:]][[:xdigit:]] / { class = $2 - classdes = substr($0, 7) - gsub( /\"/, "\\\"", classdes ) - + classdes = substr($0, 7); gsub( /\"/, "\\\"", classdes ) } # match subclass, use device class data captured earlier, and output /^\t[[:xdigit:]][[:xdigit:]] / { - if ( length(classes) > 0 ) classes = classes ",\n" - if ( currentclass != class) { classes = classes "\n"; currentclass = class } - subclassdes = substr($0, 6) - gsub( /\"/, "\\\"", subclassdes ) - - classes = classes "\t{ 0x" class ", 0x" $1 ", 0x00, \"" classdes "\", \"" subclassdes "\", \"\" }" + # if ( currentclass != class) { classes = classes "\n"; currentclass = class } + subclassdes = substr($0, 6); gsub( /\"/, "\\\"", subclassdes ) subclass = $1 + classcount++; + classes[classcount, 1] = class + classes[classcount, 2] = subclass + classes[classcount, 3] = "00" + classes[classcount, 4] = classdes + classes[classcount, 5] = subclassdes + classes[classcount, 6] = "" } # match programming interface /^\t\t[[:xdigit:]][[:xdigit:]] / { - if ( $1 != "00" ) { - if ( length(classes) > 0 ) classes = classes ",\n" - progif = substr($0, 7) - gsub( /\"/, "\\\"", progif ) - classes = classes "\t{ 0x" class ", 0x" subclass ", 0x" $1 ", \"" classdes "\", \"" subclassdes "\", \"" progif "\" }" - } + #if ( $1 != "00" ) { + #if ( length(classes) > 0 ) classes = classes ",\n" + progif = substr($0, 7); gsub( /\"/, "\\\"", progif ) + + classcount++; + classes[classcount, 1] = class + classes[classcount, 2] = subclass + classes[classcount, 3] = $1 + classes[classcount, 4] = classdes + classes[classcount, 5] = subclassdes + classes[classcount, 6] = progif + #} } # We've processed the file, now output. END { - print "} ;\n\n// Use this value for loop control during searching:\n#define PCI_DEVTABLE_LEN (sizeof(PciDevTable)/sizeof(PCI_DEVTABLE))\n"; + print "\n};\n\n// Use this value for loop control during searching:\n#define\tPCI_VENTABLE_LEN\t(sizeof(PciVenTable)/sizeof(PCI_VENTABLE))\n" > ofile + + if ( devicecount > 0 ) { + + print "typedef struct _PCI_DEVTABLE\n{\n\tunsigned short VenId ;\n\tunsigned short DevId ;\n\tchar *\tChipDesc ;\n\tchar *\tChip ;\n} PCI_DEVTABLE, *PPCI_DEVTABLE ;\n" > ofile + print "PCI_DEVTABLE\tPciDevTable [] =\n{" > ofile + for (i = 1; i <= devicecount; i++) { + if (i != 1) { a = ",\n" } else { a = "" } + printf a "\t{ 0x" devices[i, 1] ", 0x" devices[i, 2] ", \"" devices[i, 3] "\" }" > ofile + } + print "\n} ;\n\n// Use this value for loop control during searching:\n#define PCI_DEVTABLE_LEN (sizeof(PciDevTable)/sizeof(PCI_DEVTABLE))\n" > ofile - if ( length( vendor ) > 0 ) { - print "\ntypedef struct _PCI_VENTABLE\n{\n\tunsigned short\tVenId ;\n\tchar *\tVenFull ;\n\tchar *\tVenShort ;\n} PCI_VENTABLE, *PPCI_VENTABLE ;\n" - print "PCI_VENTABLE\tPciVenTable [] =\n{" - print vendor - print "};\n\n// Use this value for loop control during searching:\n#define\tPCI_VENTABLE_LEN\t(sizeof(PciVenTable)/sizeof(PCI_VENTABLE))\n" } - - if ( length( classes) > 0 ) { - 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" - print "PCI_CLASSCODETABLE PciClassCodeTable [] =\n{" - print classes - print "} ;\n\n// Use this value for loop control during searching:\n#define PCI_CLASSCODETABLE_LEN (sizeof(PciClassCodeTable)/sizeof(PCI_CLASSCODETABLE))\n" + + if ( classcount > 0 ) { + 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" > ofile + print "PCI_CLASSCODETABLE PciClassCodeTable [] =\n{" > ofile + for (i = 1; i <= classcount; i++) { + if (i != 1) { a = ",\n" } else { a = "" } + if ( ( classes[i, 1] == classes[i+1, 1] ) && ( classes[i, 2] == classes[i+1, 2] ) && ( classes[i, 3] == classes[i+1, 3] ) ) { + } else { + printf a "\t{ 0x" classes[i, 1] ", 0x" classes[i, 2] ", 0x" classes[i, 3] ", \"" classes[i, 4] "\", \"" classes[i, 5] "\", \"" classes[i, 6] "\" }" > ofile + } + } + print "\n} ;\n\n// Use this value for loop control during searching:\n#define PCI_CLASSCODETABLE_LEN (sizeof(PciClassCodeTable)/sizeof(PCI_CLASSCODETABLE))\n" > ofile } - 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" - print "// Use this value for loop control during searching:\n#define PCI_COMMANDFLAGS_LEN (sizeof(PciCommandFlags)/sizeof(char *))\n" - 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" - print "// Use this value for loop control during searching:\n#define PCI_STATUSFLAGS_LEN (sizeof(PciStatusFlags)/sizeof(char *))\n" - 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" - print "// Use this value for loop control during searching:\n#define PCI_DEVSELFLAGS_LEN (sizeof(PciDevSelFlags)/sizeof(char *))\n\n" + 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" > ofile + print "// Use this value for loop control during searching:\n#define PCI_COMMANDFLAGS_LEN (sizeof(PciCommandFlags)/sizeof(char *))\n" > ofile + 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" > ofile + print "// Use this value for loop control during searching:\n#define PCI_STATUSFLAGS_LEN (sizeof(PciStatusFlags)/sizeof(char *))\n" > ofile + 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" > ofile + print "// Use this value for loop control during searching:\n#define PCI_DEVSELFLAGS_LEN (sizeof(PciDevSelFlags)/sizeof(char *))\n\n" > ofile }