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