Annotation of src/sys/dev/eisa/devlist2h.awk, revision 1.2

1.1       cgd         1: #! /usr/bin/awk -f
1.2     ! cgd         2: #      $NetBSD: devlist2h.awk,v 1.1 1996/02/26 23:46:20 cgd Exp $
1.1       cgd         3: #
                      4: # Copyright (c) 1995, 1996 Christopher G. Demetriou
                      5: # All rights reserved.
                      6: #
                      7: # Redistribution and use in source and binary forms, with or without
                      8: # modification, are permitted provided that the following conditions
                      9: # are met:
                     10: # 1. Redistributions of source code must retain the above copyright
                     11: #    notice, this list of conditions and the following disclaimer.
                     12: # 2. Redistributions in binary form must reproduce the above copyright
                     13: #    notice, this list of conditions and the following disclaimer in the
                     14: #    documentation and/or other materials provided with the distribution.
                     15: # 3. All advertising materials mentioning features or use of this software
                     16: #    must display the following acknowledgement:
                     17: #      This product includes software developed by Christopher G. Demetriou.
                     18: # 4. The name of the author may not be used to endorse or promote products
                     19: #    derived from this software without specific prior written permission
                     20: #
                     21: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     22: # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     23: # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     24: # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     25: # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     26: # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     27: # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     28: # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     29: # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     30: # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     31: #
                     32: BEGIN {
                     33:        nproducts = nvendors = 0
                     34:        dfile="eisadevs_data.h"
                     35:        hfile="eisadevs.h"
                     36: }
                     37: NR == 1 {
                     38:        VERSION = $0
                     39:        gsub("\\$", "", VERSION)
                     40: 
                     41:        printf("/*\n") > dfile
                     42:        printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
                     43:            > dfile
                     44:        printf(" *\n") > dfile
                     45:        printf(" * generated from:\n") > dfile
                     46:        printf(" *\t%s\n", VERSION) > dfile
                     47:        printf(" */\n") > dfile
                     48: 
                     49:        printf("/*\n") > hfile
                     50:        printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
                     51:            > hfile
                     52:        printf(" *\n") > hfile
                     53:        printf(" * generated from:\n") > hfile
                     54:        printf(" *\t%s\n", VERSION) > hfile
                     55:        printf(" */\n") > hfile
                     56: 
                     57:        next
                     58: }
                     59: $1 == "vendor" {
                     60:        nvendors++
                     61: 
                     62:        vendorindex[$2] = nvendors;     # record index for this name, for later.
                     63:        vendors[nvendors, 1] = $2;      # name/ID
                     64:        i = 2; f = 3;
                     65: 
                     66:        # comments
                     67:        ocomment = oparen = 0
                     68:        if (f <= NF) {
                     69:                ocomment = 1;
                     70:        }
                     71:        while (f <= NF) {
                     72:                if ($f == "#") {
                     73:                        oparen = 1
                     74:                        f++
                     75:                        continue
                     76:                }
                     77:                if (oparen) {
                     78:                        f++
                     79:                        continue
                     80:                }
                     81:                vendors[nvendors, i] = $f
                     82:                i++; f++;
                     83:        }
                     84: 
                     85:        next
                     86: }
                     87: $1 == "product" {
                     88:        nproducts++
                     89: 
                     90:        products[nproducts, 1] = $2;            # vendor name
                     91:        products[nproducts, 2] = $3;            # product id
                     92:        printf("#define\tEISA_PRODUCT_%s%s\t\"", products[nproducts, 1],
1.2     ! cgd        93:            products[nproducts, 2]) > hfile
1.1       cgd        94: 
                     95:        i = vendorindex[products[nproducts, 1]]; j = 2;
                     96:        needspace = 0;
                     97:        while (vendors[i, j] != "") {
                     98:                if (needspace)
                     99:                        printf(" ") > hfile
                    100:                printf("%s", vendors[i, j]) > hfile
                    101:                needspace = 1
                    102:                j++
                    103:        }
                    104: 
                    105:        if (needspace)
                    106:                printf(" ") > hfile
                    107: 
                    108:        i=3; f = 4;
                    109: 
                    110:        # comments
                    111:        ocomment = oparen = 0
                    112:        if (f <= NF) {
                    113:                ocomment = 1;
                    114:        }
                    115:        while (f <= NF) {
                    116:                if ($f == "#") {
                    117:                        printf("(") > hfile
                    118:                        oparen = 1
                    119:                        f++
                    120:                        continue
                    121:                }
                    122:                if (oparen) {
                    123:                        printf("%s", $f) > hfile
                    124:                        if (f < NF)
                    125:                                printf(" ") > hfile
                    126:                        f++
                    127:                        continue
                    128:                }
                    129:                products[nproducts, i] = $f
                    130:                printf("%s", products[nproducts, i]) > hfile
                    131:                if (f < NF)
                    132:                        printf(" ") > hfile
                    133:                i++; f++;
                    134:        }
                    135:        if (oparen)
                    136:                printf(")") > hfile
                    137:        if (ocomment)
                    138:                printf("\"") > hfile
                    139:        printf("\n") > hfile
                    140: 
                    141:        next
                    142: }
                    143: {
                    144:        if ($0 == "")
                    145:                blanklines++
                    146:        if (blanklines != 2 && blanklines != 3)
                    147:                print $0 > hfile
                    148:        if (blanklines < 2)
                    149:                print $0 > dfile
                    150: }
                    151: END {
                    152:        # print out the match tables
                    153: 
                    154:        printf("\n") > dfile
                    155: 
                    156:        printf("struct eisa_knowndev eisa_knowndevs[] = {\n") > dfile
                    157:        for (i = 1; i <= nproducts; i++) {
                    158:                printf("\t{\n") > dfile
                    159:                printf("\t    0,\n") > dfile
                    160:                printf("\t    \"%s%s\",\n", products[i, 1], products[i, 2]) \
                    161:                    > dfile
                    162:                printf("\t    EISA_PRODUCT_%s%s,\n", \
                    163:                    products[i, 1], products[i, 2]) \
                    164:                    > dfile
                    165: 
                    166:                printf("\t},\n") > dfile
                    167:        }
                    168:        for (i = 1; i <= nvendors; i++) {
                    169:                printf("\t{\n") > dfile
                    170:                printf("\t    EISA_KNOWNDEV_NOPROD,\n") \
                    171:                    > dfile
                    172:                printf("\t    \"%s\",\n", vendors[i, 1]) \
                    173:                    > dfile
                    174:                printf("\t    \"") > dfile
                    175:                j = 2;
                    176:                needspace = 0;
                    177:                while (vendors[i, j] != "") {
                    178:                        if (needspace)
                    179:                                printf(" ") > dfile
                    180:                        printf("%s", vendors[i, j]) > dfile
                    181:                        needspace = 1
                    182:                        j++
                    183:                }
                    184:                printf("\",\n") > dfile
                    185:                printf("\t},\n") > dfile
                    186:        }
                    187:        printf("\t{ 0, NULL, NULL, }\n") > dfile
                    188:        printf("};\n") > dfile
                    189: }

CVSweb <webmaster@jp.NetBSD.org>