[BACK]Return to devlist2h.awk CVS log [TXT][DIR] Up to [local] / sys / dev / pci

Annotation of sys/dev/pci/devlist2h.awk, Revision 1.1

1.1     ! nbrk        1: #! /usr/bin/awk -f
        !             2: #      $OpenBSD: devlist2h.awk,v 1.8 2007/02/21 13:17:28 deraadt Exp $
        !             3: #      $NetBSD: devlist2h.awk,v 1.2 1996/01/22 21:08:09 cgd Exp $
        !             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
        !            12: #    notice, this list of conditions and the following disclaimer.
        !            13: # 2. Redistributions in binary form must reproduce the above copyright
        !            14: #    notice, this list of conditions and the following disclaimer in the
        !            15: #    documentation and/or other materials provided with the distribution.
        !            16: # 3. All advertising materials mentioning features or use of this software
        !            17: #    must display the following acknowledgement:
        !            18: #      This product includes software developed by Christopher G. Demetriou.
        !            19: # 4. The name of the author may not be used to endorse or promote products
        !            20: #    derived from this software without specific prior written permission
        !            21: #
        !            22: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            23: # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            24: # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            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: #
        !            33: BEGIN {
        !            34:        nproducts = nvendor_dup = nvendors = 0
        !            35:        dfile="pcidevs_data.h"
        !            36:        hfile="pcidevs.h"
        !            37: }
        !            38: NR == 1 {
        !            39:        VERSION = $0
        !            40:        gsub("\\$", "", VERSION)
        !            41:
        !            42:        printf("/*\n") > dfile
        !            43:        printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
        !            44:            > dfile
        !            45:        printf(" *\n") > dfile
        !            46:        printf(" * generated from:\n") > dfile
        !            47:        printf(" *\t%s\n", VERSION) > dfile
        !            48:        printf(" */\n\n") > dfile
        !            49:
        !            50:        printf("/*\n") > hfile
        !            51:        printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
        !            52:            > hfile
        !            53:        printf(" *\n") > hfile
        !            54:        printf(" * generated from:\n") > hfile
        !            55:        printf(" *\t%s\n", VERSION) > hfile
        !            56:        printf(" */\n") > hfile
        !            57:
        !            58:        next
        !            59: }
        !            60: $1 == "vendor" {
        !            61:        nvendors++
        !            62:
        !            63:        if ($2 in vendorindex) {
        !            64:                printf("duplicate vendor name %s\n", $2);
        !            65:                nvendor_dup++;
        !            66:        }
        !            67:
        !            68:        vendorindex[$2] = nvendors;             # record index for this name, for later.
        !            69:        vendors[nvendors, 1] = $2;              # name
        !            70:        vendors[nvendors, 2] = $3;              # id
        !            71:        printf("#define\tPCI_VENDOR_%s\t%s\t", vendors[nvendors, 1],
        !            72:            vendors[nvendors, 2]) > hfile
        !            73:
        !            74:        i = 3; f = 4;
        !            75:
        !            76:        # comments
        !            77:        ocomment = oparen = 0
        !            78:        if (f <= NF) {
        !            79:                printf("\t/* ") > hfile
        !            80:                ocomment = 1;
        !            81:        }
        !            82:        while (f <= NF) {
        !            83:                if ($f == "#") {
        !            84:                        printf("(") > hfile
        !            85:                        oparen = 1
        !            86:                        f++
        !            87:                        continue
        !            88:                }
        !            89:                if (oparen) {
        !            90:                        printf("%s", $f) > hfile
        !            91:                        if (f < NF)
        !            92:                                printf(" ") > hfile
        !            93:                        f++
        !            94:                        continue
        !            95:                }
        !            96:                vendors[nvendors, i] = $f
        !            97:                printf("%s", vendors[nvendors, i]) > hfile
        !            98:                if (f < NF)
        !            99:                        printf(" ") > hfile
        !           100:                i++; f++;
        !           101:        }
        !           102:        if (oparen)
        !           103:                printf(")") > hfile
        !           104:        if (ocomment)
        !           105:                printf(" */") > hfile
        !           106:        printf("\n") > hfile
        !           107:
        !           108:        next
        !           109: }
        !           110: $1 == "product" {
        !           111:        nproducts++
        !           112:
        !           113:        products[nproducts, 1] = $2;            # vendor name
        !           114:        products[nproducts, 2] = $3;            # product id
        !           115:        products[nproducts, 3] = $4;            # id
        !           116:        printf("#define\tPCI_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
        !           117:            products[nproducts, 2], products[nproducts, 3]) > hfile
        !           118:
        !           119:        i=4; f = 5;
        !           120:
        !           121:        # comments
        !           122:        ocomment = oparen = 0
        !           123:        if (f <= NF) {
        !           124:                printf("\t/* ") > hfile
        !           125:                ocomment = 1;
        !           126:        }
        !           127:        while (f <= NF) {
        !           128:                if ($f == "#") {
        !           129:                        printf("(") > hfile
        !           130:                        oparen = 1
        !           131:                        f++
        !           132:                        continue
        !           133:                }
        !           134:                if (oparen) {
        !           135:                        printf("%s", $f) > hfile
        !           136:                        if (f < NF)
        !           137:                                printf(" ") > hfile
        !           138:                        f++
        !           139:                        continue
        !           140:                }
        !           141:                products[nproducts, i] = $f
        !           142:                printf("%s", products[nproducts, i]) > hfile
        !           143:                if (f < NF)
        !           144:                        printf(" ") > hfile
        !           145:                i++; f++;
        !           146:        }
        !           147:        if (oparen)
        !           148:                printf(")") > hfile
        !           149:        if (ocomment)
        !           150:                printf(" */") > hfile
        !           151:        printf("\n") > hfile
        !           152:
        !           153:        next
        !           154: }
        !           155: {
        !           156:        if ($0 == "")
        !           157:                blanklines++
        !           158:        print $0 > hfile
        !           159:        if (blanklines < 2)
        !           160:                print $0 > dfile
        !           161: }
        !           162: END {
        !           163:        # print out the match tables
        !           164:
        !           165:        printf("\n") > dfile
        !           166:
        !           167:        if (nvendor_dup > 0)
        !           168:                exit(1);
        !           169:
        !           170:        printf("/* Descriptions of known vendors and devices. */\n") > dfile
        !           171:        printf("struct pci_known_vendor {\n") > dfile
        !           172:        printf("\tpci_vendor_id_t vendor;\n") > dfile
        !           173:        printf("\tconst char *vendorname;\n") > dfile
        !           174:        printf("};\n\n") > dfile
        !           175:
        !           176:        printf("struct pci_known_product {\n") > dfile
        !           177:        printf("\tpci_vendor_id_t vendor;\n") > dfile
        !           178:        printf("\tpci_product_id_t product;\n") > dfile
        !           179:        printf("\tconst char *productname;\n") > dfile
        !           180:        printf("};\n\n") > dfile
        !           181:
        !           182:
        !           183:        printf("static const struct pci_known_product pci_known_products[] = {\n") \
        !           184:            > dfile
        !           185:        for (i = 1; i <= nproducts; i++) {
        !           186:                printf("\t{\n") > dfile
        !           187:                printf("\t    PCI_VENDOR_%s, PCI_PRODUCT_%s_%s,\n",
        !           188:                    products[i, 1], products[i, 1], products[i, 2]) \
        !           189:                    > dfile
        !           190:
        !           191:                printf("\t    \"") > dfile
        !           192:                j = 4;
        !           193:                needspace = 0;
        !           194:                while (products[i, j] != "") {
        !           195:                        if (needspace)
        !           196:                                printf(" ") > dfile
        !           197:                        printf("%s", products[i, j]) > dfile
        !           198:                        needspace = 1
        !           199:                        j++
        !           200:                }
        !           201:                printf("\",\n") > dfile
        !           202:                printf("\t},\n") > dfile
        !           203:        }
        !           204:        printf("\t{ 0, 0, NULL, }\n") > dfile
        !           205:        printf("};\n\n") > dfile
        !           206:
        !           207:        printf("static const struct pci_known_vendor pci_known_vendors[] = {\n") \
        !           208:            > dfile
        !           209:        for (i = 1; i <= nvendors; i++) {
        !           210:                printf("\t{\n") > dfile
        !           211:                printf("\t    PCI_VENDOR_%s,\n", vendors[i, 1]) \
        !           212:                    > dfile
        !           213:                printf("\t    \"") > dfile
        !           214:                j = 3;
        !           215:                needspace = 0;
        !           216:                while (vendors[i, j] != "") {
        !           217:                        if (needspace)
        !           218:                                printf(" ") > dfile
        !           219:                        printf("%s", vendors[i, j]) > dfile
        !           220:                        needspace = 1
        !           221:                        j++
        !           222:                }
        !           223:                printf("\",\n") > dfile
        !           224:                printf("\t},\n") > dfile
        !           225:        }
        !           226:        printf("\t{ 0, NULL, }\n") > dfile
        !           227:        printf("};\n") > dfile
        !           228: }

CVSweb