Home | History | Annotate | Line # | Download | only in pcmcia
devlist2h.awk revision 1.4
      1  1.1  christos #! /usr/bin/awk -f
      2  1.4      haya #	$NetBSD: devlist2h.awk,v 1.4 2001/11/08 09:02:17 haya Exp $
      3  1.3  christos #
      4  1.3  christos # Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.3  christos # All rights reserved.
      6  1.3  christos #
      7  1.3  christos # This code is derived from software contributed to The NetBSD Foundation
      8  1.3  christos # by Christos Zoulas.
      9  1.3  christos #
     10  1.3  christos # Redistribution and use in source and binary forms, with or without
     11  1.3  christos # modification, are permitted provided that the following conditions
     12  1.3  christos # are met:
     13  1.3  christos # 1. Redistributions of source code must retain the above copyright
     14  1.3  christos #    notice, this list of conditions and the following disclaimer.
     15  1.3  christos # 2. Redistributions in binary form must reproduce the above copyright
     16  1.3  christos #    notice, this list of conditions and the following disclaimer in the
     17  1.3  christos #    documentation and/or other materials provided with the distribution.
     18  1.3  christos # 3. All advertising materials mentioning features or use of this software
     19  1.3  christos #    must display the following acknowledgement:
     20  1.3  christos #        This product includes software developed by the NetBSD
     21  1.3  christos #        Foundation, Inc. and its contributors.
     22  1.3  christos # 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.3  christos #    contributors may be used to endorse or promote products derived
     24  1.3  christos #    from this software without specific prior written permission.
     25  1.3  christos #
     26  1.3  christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.3  christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.3  christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.3  christos # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.3  christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.3  christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.3  christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.3  christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.3  christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.3  christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.3  christos # POSSIBILITY OF SUCH DAMAGE.
     37  1.1  christos #
     38  1.1  christos # Copyright (c) 1995, 1996 Christopher G. Demetriou
     39  1.1  christos # All rights reserved.
     40  1.1  christos #
     41  1.1  christos # Redistribution and use in source and binary forms, with or without
     42  1.1  christos # modification, are permitted provided that the following conditions
     43  1.1  christos # are met:
     44  1.1  christos # 1. Redistributions of source code must retain the above copyright
     45  1.1  christos #    notice, this list of conditions and the following disclaimer.
     46  1.1  christos # 2. Redistributions in binary form must reproduce the above copyright
     47  1.1  christos #    notice, this list of conditions and the following disclaimer in the
     48  1.1  christos #    documentation and/or other materials provided with the distribution.
     49  1.1  christos # 3. All advertising materials mentioning features or use of this software
     50  1.1  christos #    must display the following acknowledgement:
     51  1.1  christos #      This product includes software developed by Christopher G. Demetriou.
     52  1.2  christos #      This product includes software developed by Christos Zoulas
     53  1.2  christos # 4. The name of the author(s) may not be used to endorse or promote products
     54  1.1  christos #    derived from this software without specific prior written permission
     55  1.1  christos #
     56  1.1  christos # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     57  1.1  christos # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     58  1.1  christos # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     59  1.1  christos # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     60  1.1  christos # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     61  1.1  christos # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     62  1.1  christos # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     63  1.1  christos # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     64  1.1  christos # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     65  1.1  christos # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     66  1.1  christos #
     67  1.2  christos function collectline(f, line) {
     68  1.2  christos 	oparen = 0
     69  1.2  christos 	line = ""
     70  1.2  christos 	while (f <= NF) {
     71  1.2  christos 		if ($f == "#") {
     72  1.2  christos 			line = line "("
     73  1.2  christos 			oparen = 1
     74  1.2  christos 			f++
     75  1.2  christos 			continue
     76  1.2  christos 		}
     77  1.2  christos 		if (oparen) {
     78  1.2  christos 			line = line $f
     79  1.2  christos 			if (f < NF)
     80  1.2  christos 				line = line " "
     81  1.2  christos 			f++
     82  1.2  christos 			continue
     83  1.2  christos 		}
     84  1.2  christos 		line = line $f
     85  1.2  christos 		if (f < NF)
     86  1.2  christos 			line = line " "
     87  1.2  christos 		f++
     88  1.2  christos 	}
     89  1.2  christos 	if (oparen)
     90  1.2  christos 		line = line ")"
     91  1.2  christos 	return line
     92  1.2  christos }
     93  1.1  christos BEGIN {
     94  1.1  christos 	nproducts = nvendors = 0
     95  1.1  christos 	dfile="pcmciadevs_data.h"
     96  1.1  christos 	hfile="pcmciadevs.h"
     97  1.1  christos }
     98  1.1  christos NR == 1 {
     99  1.1  christos 	VERSION = $0
    100  1.1  christos 	gsub("\\$", "", VERSION)
    101  1.1  christos 
    102  1.1  christos 	printf("/*\t\$NetBSD\$\t*/\n\n") > dfile
    103  1.1  christos 	printf("/*\n") > dfile
    104  1.1  christos 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    105  1.1  christos 	    > dfile
    106  1.1  christos 	printf(" *\n") > dfile
    107  1.1  christos 	printf(" * generated from:\n") > dfile
    108  1.1  christos 	printf(" *\t%s\n", VERSION) > dfile
    109  1.1  christos 	printf(" */\n") > dfile
    110  1.1  christos 
    111  1.1  christos 	printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
    112  1.1  christos 	printf("/*\n") > hfile
    113  1.1  christos 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    114  1.1  christos 	    > hfile
    115  1.1  christos 	printf(" *\n") > hfile
    116  1.1  christos 	printf(" * generated from:\n") > hfile
    117  1.1  christos 	printf(" *\t%s\n", VERSION) > hfile
    118  1.1  christos 	printf(" */\n") > hfile
    119  1.1  christos 
    120  1.1  christos 	next
    121  1.1  christos }
    122  1.1  christos $1 == "vendor" {
    123  1.1  christos 	nvendors++
    124  1.1  christos 
    125  1.1  christos 	vendorindex[$2] = nvendors;		# record index for this name, for later.
    126  1.1  christos 	vendors[nvendors, 1] = $2;		# name
    127  1.1  christos 	vendors[nvendors, 2] = $3;		# id
    128  1.1  christos 	printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1],
    129  1.1  christos 	    vendors[nvendors, 2]) > hfile
    130  1.2  christos 	vendors[nvendors, 3] = collectline(4, line)
    131  1.2  christos 	printf("/* %s */\n", vendors[nvendors, 3]) > hfile
    132  1.1  christos 	next
    133  1.1  christos }
    134  1.1  christos $1 == "product" {
    135  1.1  christos 	nproducts++
    136  1.1  christos 
    137  1.1  christos 	products[nproducts, 1] = $2;		# vendor name
    138  1.1  christos 	products[nproducts, 2] = $3;		# product id
    139  1.1  christos 	products[nproducts, 3] = $4;		# id
    140  1.1  christos 
    141  1.1  christos 	f = 5;
    142  1.1  christos 
    143  1.1  christos 	if ($4 == "{") {
    144  1.1  christos 		products[nproducts, 3] = -1
    145  1.1  christos 		z = "{ "
    146  1.1  christos 		for (i = 0; i < 4; i++) {
    147  1.1  christos 			if (f <= NF) {
    148  1.1  christos 				gsub("&sp", " ", $f)
    149  1.1  christos 				gsub("&tab", "\t", $f)
    150  1.1  christos 				gsub("&nl", "\n", $f)
    151  1.1  christos 				z = z $f " "
    152  1.1  christos 				f++
    153  1.1  christos 			}
    154  1.1  christos 			else {
    155  1.1  christos 				if (i == 3)
    156  1.1  christos 					z = z "NULL "
    157  1.1  christos 				else
    158  1.1  christos 					z = z "NULL, "
    159  1.1  christos 			}
    160  1.1  christos 		}
    161  1.1  christos 		products[nproducts, 4] = z $f
    162  1.1  christos 		f++
    163  1.1  christos 	}
    164  1.1  christos 	else {
    165  1.1  christos 		products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
    166  1.1  christos 	}
    167  1.1  christos 	printf("#define\tPCMCIA_CIS_%s_%s\t%s\n",
    168  1.1  christos 	    products[nproducts, 1], products[nproducts, 2],
    169  1.1  christos 	    products[nproducts, 4]) > hfile
    170  1.1  christos 	printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
    171  1.1  christos 	    products[nproducts, 2], products[nproducts, 3]) > hfile
    172  1.1  christos 
    173  1.2  christos 	products[nproducts, 5] = collectline(f, line)
    174  1.1  christos 
    175  1.1  christos 	printf("#define\tPCMCIA_STR_%s_%s\t\"%s\"\n",
    176  1.1  christos 	    products[nproducts, 1], products[nproducts, 2],
    177  1.1  christos 	    products[nproducts, 5]) > hfile
    178  1.1  christos 
    179  1.1  christos 	next
    180  1.1  christos }
    181  1.1  christos {
    182  1.1  christos 	if ($0 == "")
    183  1.1  christos 		blanklines++
    184  1.1  christos 	print $0 > hfile
    185  1.1  christos 	if (blanklines < 2)
    186  1.1  christos 		print $0 > dfile
    187  1.1  christos }
    188  1.1  christos END {
    189  1.1  christos 	# print out the match tables
    190  1.1  christos 
    191  1.1  christos 	printf("\n") > dfile
    192  1.1  christos 
    193  1.4      haya 	printf("struct pcmcia_knowndev {\n") > dfile
    194  1.4      haya 	printf("\tint vendorid;\n") > dfile
    195  1.4      haya 	printf("\tint productid;\n") > dfile
    196  1.4      haya 	printf("\tstruct pcmcia_knowndev_cis {\n") > dfile
    197  1.4      haya 	printf("\t\tchar *vendor;\n") > dfile
    198  1.4      haya 	printf("\t\tchar *product;\n") > dfile
    199  1.4      haya 	printf("\t\tchar *version;\n") > dfile
    200  1.4      haya 	printf("\t\tchar *revision;\n") > dfile
    201  1.4      haya 	printf("\t}cis;\n") > dfile
    202  1.4      haya 	printf("\tint flags;\n") > dfile
    203  1.4      haya 	printf("\tchar *vendorname;\n") > dfile
    204  1.4      haya 	printf("\tchar *devicename;\n") > dfile
    205  1.4      haya 	printf("\tint reserve;\n") > dfile
    206  1.4      haya 	printf("};\n\n") > dfile
    207  1.4      haya 	printf("#define	PCMCIA_CIS_INVALID\t\t{ NULL, NULL, NULL, NULL }\n") > dfile
    208  1.4      haya 	printf("#define	PCMCIA_KNOWNDEV_NOPROD\t\t0\n\n") > dfile
    209  1.1  christos 	printf("struct pcmcia_knowndev pcmcia_knowndevs[] = {\n") > dfile
    210  1.1  christos 	for (i = 1; i <= nproducts; i++) {
    211  1.1  christos 		printf("\t{\n") > dfile
    212  1.1  christos 		if (products[i, 3] == -1) {
    213  1.1  christos 			printf("\t    PCMCIA_VENDOR_UNKNOWN, PCMCIA_PRODUCT_%s_%s,\n",
    214  1.1  christos 			    products[i, 1], products[i, 2]) > dfile
    215  1.1  christos 		} else {
    216  1.1  christos 			printf("\t    PCMCIA_VENDOR_%s, PCMCIA_PRODUCT_%s_%s,\n",
    217  1.1  christos 			    products[i, 1], products[i, 1], products[i, 2]) > dfile
    218  1.1  christos 		}
    219  1.1  christos 		printf("\t    PCMCIA_CIS_%s_%s,\n", 
    220  1.1  christos 		    products[i, 1], products[i, 2]) > dfile
    221  1.1  christos 		printf("\t    ") > dfile
    222  1.1  christos 		printf("0") > dfile
    223  1.1  christos 		printf(",\n") > dfile
    224  1.1  christos 
    225  1.1  christos 		vendi = vendorindex[products[i, 1]];
    226  1.2  christos 		printf("\t    \"%s\",\n", vendors[vendi, 3]) > dfile
    227  1.4      haya 		printf("\t    \"%s\",\t}\n", products[i, 5]) > dfile
    228  1.4      haya 		printf("\t,\n") > dfile
    229  1.1  christos 	}
    230  1.1  christos 	for (i = 1; i <= nvendors; i++) {
    231  1.1  christos 		printf("\t{\n") > dfile
    232  1.4      haya 		printf("\t    PCMCIA_VENDOR_%s,\n", vendors[i, 1]) > dfile
    233  1.1  christos 		printf("\t    PCMCIA_KNOWNDEV_NOPROD,\n") > dfile
    234  1.1  christos 		printf("\t    PCMCIA_CIS_INVALID,\n") > dfile
    235  1.4      haya 		printf("\t    0,\n") > dfile
    236  1.2  christos 		printf("\t    \"%s\",\n", vendors[i, 3]) > dfile
    237  1.1  christos 		printf("\t    NULL,\n") > dfile
    238  1.1  christos 		printf("\t},\n") > dfile
    239  1.1  christos 	}
    240  1.1  christos 	printf("\t{ 0, 0, { NULL, NULL, NULL, NULL }, 0, NULL, NULL, }\n") > dfile
    241  1.1  christos 	printf("};\n") > dfile
    242  1.1  christos }
    243