Ticket #12515: pci-header.awk-workaround.patch

File pci-header.awk-workaround.patch, 4.9 KB (added by dknoto, 5 years ago)

Workaround for an error in awk-4.1.3

  • src/apps/devices/pci-header.awk

    From 06dfc1baefdee4d541036ed71c26853998d1b796 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Dariusz=20Knoci=C5=84ski?= <dknoto@gmail.com>
    Date: Fri, 18 Dec 2015 16:12:37 +0100
    Subject: [PATCH] pci-header.awk: added workaround due to an error in the
     operation of the logical operators '||' and '&&' in awk-4.1.3.
    
    ---
     src/apps/devices/pci-header.awk | 52 +++++++++++++++++++++++++----------------
     1 file changed, 32 insertions(+), 20 deletions(-)
    
    diff --git a/src/apps/devices/pci-header.awk b/src/apps/devices/pci-header.awk
    index f046ef1..7412ca9 100644
    a b BEGIN {  
    3636
    3737# matches vendor - starts with an id as first thing on the line
    3838# because this occurs first in the header file, we output it without worry
    39 /^[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { 
     39/^[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
    4040
    41     if ( vendorcount++ > 0 ) { 
     41    if ( vendorcount++ > 0 ) {
    4242        formatting = ",\n"
    4343    } else {
    4444        formatting = ""
    BEGIN {  
    5252    printf formatting "\t{ 0x" vendorid ", \"" vendor "\", \"\" }" > ofile
    5353}
    5454
    55 # matches device 
    56 /^\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { 
     55# matches device
     56/^\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
    5757
    5858    device = substr($0, 8)
    5959    gsub( /\\/, "&&", device )
    BEGIN {  
    6666    devices[devicecount, 2] = $1
    6767    devices[devicecount, 3] = 0
    6868    devices[devicecount, 4] = 0
    69     devices[devicecount, 5] = device 
     69    devices[devicecount, 5] = device
    7070}
    7171
    7272# matches subvendor device
    73 /^\t\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { 
     73/^\t\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / {
    7474
    7575    device = substr($0, 14)
    7676    gsub( /\"/, "\\\"", device )
    BEGIN {  
    7878    devicecount++
    7979    devices[devicecount, 1] = vendorid
    8080    devices[devicecount, 2] = deviceid
    81     devices[devicecount, 3] = $1 
     81    devices[devicecount, 3] = $1
    8282    devices[devicecount, 4] = $2
    83     devices[devicecount, 5] = device 
     83    devices[devicecount, 5] = device
    8484}
    8585
    8686# match device class - store data for later
    87 /^C [[:xdigit:]][[:xdigit:]]  / { 
     87/^C [[:xdigit:]][[:xdigit:]]  / {
    8888
    8989    class = $2
    9090    classname = substr($0, 7)
    BEGIN {  
    105105    classes[classcount, 4] = classname
    106106    classes[classcount, 5] = subclassname
    107107    classes[classcount, 6] = ""
    108 } 
     108}
    109109
    110110# match programming interface
    111111/^\t\t[[:xdigit:]][[:xdigit:]]  / {
    BEGIN {  
    121121    classes[classcount, 4] = classname
    122122    classes[classcount, 5] = subclassname
    123123    classes[classcount, 6] = proginterfacename
    124 } 
     124}
    125125
    126126# We've processed the file, now output.
    127127END {
    END {  
    144144        print "\n} ;\n\n// Use this value for loop control during searching:\n#define   PCI_DEVTABLE_LEN    (sizeof(PciDevTable)/sizeof(PCI_DEVTABLE))\n" > ofile
    145145
    146146    }
    147    
     147
    148148    if ( classcount > 0 ) {
    149149        print "typedef struct _PCI_CLASSCODETABLE\n{\n\tunsigned char   BaseClass ;\n\tunsigned char    SubClass ;\n\tunsigned char ProgIf ;" > ofile
    150150        print "\tconst char *\t\tBaseDesc ;\n\tconst char *\t\tSubDesc ;\n\tconst char *\t\tProgDesc ;\n}  PCI_CLASSCODETABLE, *PPCI_CLASSCODETABLE ;\n" > ofile
    151151        print "PCI_CLASSCODETABLE PciClassCodeTable [] =\n{" > ofile
    152152        currentclass = classes[1, 1]
    153153        for (i = 1; i <= classcount; i++) {
    154            
    155             if (i != 1) { 
     154
     155            if (i != 1) {
    156156                formatting = ",\n"
    157             } else { 
     157            } else {
    158158                formatting = ""
    159159            }
    160160
    161161            # pretty print separate classes
    162             if ( currentclass != classes[i, 1] ) { 
     162            if ( currentclass != classes[i, 1] ) {
    163163                formatting = formatting "\n"
    164164                currentclass = classes[i, 1]
    165165            }
    166            
    167             # if the next item has the same details, we know we're to skip ourselves 
     166
     167            # if the next item has the same details, we know we're to skip ourselves
    168168            # this is because the programming interface name needs to be used, and we dont have it ourselves
    169             if ( ( classes[i, 1] != classes[i+1, 1] ) || ( classes[i, 2] != classes[i+1, 2] ) || ( classes[i, 3] != classes[i+1, 3] ) ) {
     169
     170            if (classes[i, 1] != classes[i+1, 1])
     171            {
     172                printf formatting "\t{ 0x" classes[i, 1] ", 0x" classes[i, 2] ", 0x" classes[i, 3] ", \"" classes[i, 4] "\", \"" classes[i, 5]  "\", \"" classes[i, 6] "\" }" > ofile
     173                continue;
     174            }
     175            if (classes[i, 2] != classes[i+1, 2])
     176            {
    170177                printf formatting "\t{ 0x" classes[i, 1] ", 0x" classes[i, 2] ", 0x" classes[i, 3] ", \"" classes[i, 4] "\", \"" classes[i, 5]  "\", \"" classes[i, 6] "\" }" > ofile
     178                continue;
     179            }
     180            if (classes[i, 3] != classes[i+1, 3])
     181            {
     182                printf formatting "\t{ 0x" classes[i, 1] ", 0x" classes[i, 2] ", 0x" classes[i, 3] ", \"" classes[i, 4] "\", \"" classes[i, 5]  "\", \"" classes[i, 6] "\" }" > ofile
     183                continue;
    171184            }
    172185        }
    173186        print "\n} ;\n\n// Use this value for loop control during searching:\n#define   PCI_CLASSCODETABLE_LEN  (sizeof(PciClassCodeTable)/sizeof(PCI_CLASSCODETABLE))\n" > ofile
    174 
    175187    }
    176188
    177189    # this is rather ugly, maybe we should include this in a seperate file, and pull it in ?