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

Annotation of sys/dev/usb/devlist2h.awk, Revision 1.1.1.1

1.1       nbrk        1: #! /usr/bin/awk -f
                      2: #      $OpenBSD: devlist2h.awk,v 1.11 2007/06/04 10:34:04 mbalmer Exp $
                      3: #      $NetBSD: devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek 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 = nvendors = 0
                     35:        dfile="usbdevs_data.h"
                     36:        hfile="usbdevs.h"
                     37: }
                     38: NR == 1 {
                     39:        VERSION = $0
                     40:        gsub("\\$", "", VERSION)
                     41:
                     42:        printf("/*\t\$OpenBSD\$\t*/\n\n") > dfile
                     43:        printf("/*\n") > dfile
                     44:        printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
                     45:            > dfile
                     46:        printf(" *\n") > dfile
                     47:        printf(" * generated from:\n") > dfile
                     48:        printf(" *\t%s\n", VERSION) > dfile
                     49:        printf(" */\n") > dfile
                     50:
                     51:        printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile
                     52:        printf("/*\n") > hfile
                     53:        printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
                     54:            > hfile
                     55:        printf(" *\n") > hfile
                     56:        printf(" * generated from:\n") > hfile
                     57:        printf(" *\t%s\n", VERSION) > hfile
                     58:        printf(" */\n") > hfile
                     59:
                     60:        next
                     61: }
                     62: $1 == "vendor" {
                     63:        nvendors++
                     64:
                     65:        vendorindex[$2] = nvendors;             # record index for this name, for later.
                     66:        vendors[nvendors, 1] = $2;              # name
                     67:        vendors[nvendors, 2] = $3;              # id
                     68:        printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
                     69:            vendors[nvendors, 2]) > hfile
                     70:
                     71:        i = 3; f = 4;
                     72:
                     73:        # comments
                     74:        ocomment = oparen = 0
                     75:        if (f <= NF) {
                     76:                printf("\t/* ") > hfile
                     77:                ocomment = 1;
                     78:        }
                     79:        while (f <= NF) {
                     80:                if ($f == "#") {
                     81:                        printf("(") > hfile
                     82:                        oparen = 1
                     83:                        f++
                     84:                        continue
                     85:                }
                     86:                if (oparen) {
                     87:                        printf("%s", $f) > hfile
                     88:                        if (f < NF)
                     89:                                printf(" ") > hfile
                     90:                        f++
                     91:                        continue
                     92:                }
                     93:                vendors[nvendors, i] = $f
                     94:                printf("%s", vendors[nvendors, i]) > hfile
                     95:                if (f < NF)
                     96:                        printf(" ") > hfile
                     97:                i++; f++;
                     98:        }
                     99:        if (oparen)
                    100:                printf(")") > hfile
                    101:        if (ocomment)
                    102:                printf(" */") > hfile
                    103:        printf("\n") > hfile
                    104:
                    105:        next
                    106: }
                    107: $1 == "product" {
                    108:        nproducts++
                    109:
                    110:        products[nproducts, 1] = $2;            # vendor name
                    111:        products[nproducts, 2] = $3;            # product id
                    112:        products[nproducts, 3] = $4;            # id
                    113:        printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
                    114:            products[nproducts, 2], products[nproducts, 3]) > hfile
                    115:
                    116:        i=4; f = 5;
                    117:
                    118:        # comments
                    119:        ocomment = oparen = 0
                    120:        if (f <= NF) {
                    121:                printf("\t/* ") > hfile
                    122:                ocomment = 1;
                    123:        }
                    124:        while (f <= NF) {
                    125:                if ($f == "#") {
                    126:                        printf("(") > hfile
                    127:                        oparen = 1
                    128:                        f++
                    129:                        continue
                    130:                }
                    131:                if (oparen) {
                    132:                        printf("%s", $f) > hfile
                    133:                        if (f < NF)
                    134:                                printf(" ") > hfile
                    135:                        f++
                    136:                        continue
                    137:                }
                    138:                products[nproducts, i] = $f
                    139:                printf("%s", products[nproducts, i]) > hfile
                    140:                if (f < NF)
                    141:                        printf(" ") > hfile
                    142:                i++; f++;
                    143:        }
                    144:        if (oparen)
                    145:                printf(")") > hfile
                    146:        if (ocomment)
                    147:                printf(" */") > hfile
                    148:        printf("\n") > hfile
                    149:
                    150:        next
                    151: }
                    152: {
                    153:        if ($0 == "")
                    154:                blanklines++
                    155:        print $0 > hfile
                    156:        if (blanklines < 2)
                    157:                print $0 > dfile
                    158: }
                    159: END {
                    160:        # print out the match tables
                    161:
                    162:        printf("\n") > dfile
                    163:
                    164:        printf("/*\n") > dfile
                    165:        printf(" * Descriptions of known vendors and devices (\"products\").\n") > dfile
                    166:        printf(" */\n") > dfile
                    167:        printf("struct usb_known_vendor {\n") > dfile
                    168:        printf("        u_int16_t       vendor;\n") > dfile
                    169:        printf("        char            *vendorname;\n") > dfile
                    170:        printf("};\n\n") > dfile
                    171:
                    172:        printf("struct usb_known_product {\n") > dfile
                    173:        printf("        u_int16_t       vendor;\n") > dfile
                    174:        printf("        u_int16_t       product;\n") > dfile
                    175:        printf("        char            *productname;\n") > dfile
                    176:        printf("};\n\n") > dfile
                    177:        printf("const struct usb_known_product usb_known_products[] = {\n") \
                    178:            > dfile
                    179:        for (i = 1; i <= nproducts; i++) {
                    180:                printf("\t{\n") > dfile
                    181:                printf("\t    USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
                    182:                    products[i, 1], products[i, 1], products[i, 2]) \
                    183:                    > dfile
                    184:
                    185:                printf("\t    \"") > dfile
                    186:                j = 4;
                    187:                needspace = 0;
                    188:                while (products[i, j] != "") {
                    189:                        if (needspace)
                    190:                                printf(" ") > dfile
                    191:                        printf("%s", products[i, j]) > dfile
                    192:                        needspace = 1
                    193:                        j++
                    194:                }
                    195:                printf("\",\n") > dfile
                    196:                printf("\t},\n") > dfile
                    197:        }
                    198:        printf("\t{ 0, 0, NULL }\n") > dfile
                    199:        printf("};\n\n") > dfile
                    200:
                    201:        printf("const struct usb_known_vendor usb_known_vendors[] = {\n") \
                    202:             > dfile
                    203:        for (i = 1; i <= nvendors; i++) {
                    204:                printf("\t{\n") > dfile
                    205:                printf("\t    USB_VENDOR_%s,\n", vendors[i, 1]) \
                    206:                    > dfile
                    207:
                    208:                printf("\t    \"") > dfile
                    209:                j = 3;
                    210:                needspace = 0;
                    211:                while (vendors[i, j] != "") {
                    212:                        if (needspace)
                    213:                                printf(" ") > dfile
                    214:                        printf("%s", vendors[i, j]) > dfile
                    215:                        needspace = 1
                    216:                        j++
                    217:                }
                    218:                printf("\",\n") > dfile
                    219:                printf("\t},\n") > dfile
                    220:        }
                    221:        printf("\t{ 0, NULL }\n") > dfile
                    222:        printf("};\n") > dfile
                    223: }

CVSweb