Home | History | Annotate | Line # | Download | only in isapnp
devlist2h.awk revision 1.3
      1  1.1  christos #! /usr/bin/awk -f
      2  1.3   mycroft #	$NetBSD: devlist2h.awk,v 1.3 1999/03/22 09:38:57 mycroft Exp $
      3  1.2  christos #
      4  1.2  christos # Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.2  christos # All rights reserved.
      6  1.2  christos #
      7  1.2  christos # This code is derived from software contributed to The NetBSD Foundation
      8  1.2  christos # by Christos Zoulas.
      9  1.2  christos #
     10  1.2  christos # Redistribution and use in source and binary forms, with or without
     11  1.2  christos # modification, are permitted provided that the following conditions
     12  1.2  christos # are met:
     13  1.2  christos # 1. Redistributions of source code must retain the above copyright
     14  1.2  christos #    notice, this list of conditions and the following disclaimer.
     15  1.2  christos # 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  christos #    notice, this list of conditions and the following disclaimer in the
     17  1.2  christos #    documentation and/or other materials provided with the distribution.
     18  1.2  christos # 3. All advertising materials mentioning features or use of this software
     19  1.2  christos #    must display the following acknowledgement:
     20  1.2  christos #        This product includes software developed by the NetBSD
     21  1.2  christos #        Foundation, Inc. and its contributors.
     22  1.2  christos # 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2  christos #    contributors may be used to endorse or promote products derived
     24  1.2  christos #    from this software without specific prior written permission.
     25  1.2  christos #
     26  1.2  christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2  christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2  christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2  christos # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2  christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2  christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2  christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2  christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2  christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2  christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2  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.1  christos #      This product includes software developed by Christos Zoulas
     53  1.1  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.1  christos function collectline(f, line) {
     68  1.1  christos 	oparen = 0
     69  1.1  christos 	line = ""
     70  1.1  christos 	while (f <= NF) {
     71  1.1  christos 		if ($f == "#") {
     72  1.1  christos 			line = line "("
     73  1.1  christos 			oparen = 1
     74  1.1  christos 			f++
     75  1.1  christos 			continue
     76  1.1  christos 		}
     77  1.1  christos 		if (oparen) {
     78  1.1  christos 			line = line $f
     79  1.1  christos 			if (f < NF)
     80  1.1  christos 				line = line " "
     81  1.1  christos 			f++
     82  1.1  christos 			continue
     83  1.1  christos 		}
     84  1.1  christos 		line = line $f
     85  1.1  christos 		if (f < NF)
     86  1.1  christos 			line = line " "
     87  1.1  christos 		f++
     88  1.1  christos 	}
     89  1.1  christos 	if (oparen)
     90  1.1  christos 		line = line ")"
     91  1.1  christos 	return line
     92  1.1  christos }
     93  1.1  christos function checkdecl() {
     94  1.1  christos 	done = 1
     95  1.1  christos 	if (!decl) {
     96  1.1  christos 		decl = 1;
     97  1.3   mycroft 		printf("struct isapnp_matchinfo {\n") > hfile
     98  1.3   mycroft 		printf("\tconst char *name;\n") > hfile
     99  1.3   mycroft 		printf("\tint variant;\n") > hfile
    100  1.3   mycroft 		printf("};\n\n") > hfile
    101  1.1  christos 		printf("struct isapnp_devinfo {\n") > hfile
    102  1.3   mycroft 		printf("\tconst struct isapnp_matchinfo *devlogic;\n") > hfile
    103  1.3   mycroft 		printf("\tint nlogic;\n") > hfile
    104  1.3   mycroft 		printf("\tconst struct isapnp_matchinfo *devcompat;\n") > hfile
    105  1.3   mycroft 		printf("\tint ncompat;\n") > hfile
    106  1.1  christos 		printf("};\n\n") > hfile
    107  1.1  christos 		printf("#include <sys/param.h>\n") > cfile
    108  1.1  christos 		printf("#include <dev/isapnp/isapnpdevs.h>\n\n") > cfile
    109  1.1  christos 	}
    110  1.1  christos }
    111  1.1  christos BEGIN {
    112  1.1  christos 	decl = done = ncompat = nlogicals = ndriver = 0
    113  1.1  christos 	cfile="isapnpdevs.c"
    114  1.1  christos 	hfile="isapnpdevs.h"
    115  1.1  christos }
    116  1.1  christos NR == 1 {
    117  1.1  christos 	VERSION = $0
    118  1.1  christos 	gsub("\\$", "", VERSION)
    119  1.1  christos 
    120  1.1  christos 	printf("/*\t\$NetBSD\$\t*/\n\n") > cfile
    121  1.1  christos 	printf("/*\n") > cfile
    122  1.1  christos 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    123  1.1  christos 	    > cfile
    124  1.1  christos 	printf(" *\n") > cfile
    125  1.1  christos 	printf(" * generated from:\n") > cfile
    126  1.1  christos 	printf(" *\t%s\n", VERSION) > cfile
    127  1.1  christos 	printf(" */\n") > cfile
    128  1.1  christos 
    129  1.1  christos 	printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
    130  1.1  christos 	printf("/*\n") > hfile
    131  1.1  christos 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    132  1.1  christos 	    > hfile
    133  1.1  christos 	printf(" *\n") > hfile
    134  1.1  christos 	printf(" * generated from:\n") > hfile
    135  1.1  christos 	printf(" *\t%s\n", VERSION) > hfile
    136  1.1  christos 	printf(" */\n") > hfile
    137  1.1  christos 	printf("\n") > hfile
    138  1.1  christos 	next
    139  1.1  christos }
    140  1.1  christos $1 == "driver" {
    141  1.1  christos 	checkdecl()
    142  1.1  christos 	ndriver++
    143  1.1  christos 
    144  1.1  christos 	driverindex[$2] = ndriver;
    145  1.1  christos 	driver[ndriver, 1] = $2;
    146  1.1  christos 	driver[ndriver, 2] = collectline(3, line);
    147  1.1  christos 	printf("/* %s */\n", driver[ndriver, 2]) > hfile
    148  1.1  christos 	printf("extern const struct isapnp_devinfo isapnp_%s_devinfo;\n",
    149  1.1  christos 	    driver[ndriver, 1]) > hfile
    150  1.1  christos 	next
    151  1.1  christos }
    152  1.1  christos $1 == "devlogic" {
    153  1.1  christos 	checkdecl()
    154  1.1  christos 	nlogicals++
    155  1.1  christos 
    156  1.1  christos 	logicals[nlogicals, 1] = $2;
    157  1.1  christos 	logicals[nlogicals, 2] = $3;
    158  1.3   mycroft 	logicals[nlogicals, 3] = $4;
    159  1.3   mycroft 	logicals[nlogicals, 4] = collectline(5, line);
    160  1.1  christos 	next
    161  1.1  christos }
    162  1.1  christos $1 == "devcompat" {
    163  1.1  christos 	checkdecl()
    164  1.1  christos 	ncompats++
    165  1.1  christos 
    166  1.1  christos 	compats[ncompats, 1] = $2;
    167  1.1  christos 	compats[ncompats, 2] = $3;
    168  1.3   mycroft 	compats[ncompats, 3] = $4;
    169  1.3   mycroft 	compats[ncompats, 4] = collectline(5, line);
    170  1.1  christos 	next
    171  1.1  christos }
    172  1.1  christos {
    173  1.1  christos 	if (!done) {
    174  1.1  christos 		if ($0 == "")
    175  1.1  christos 			blanklines++
    176  1.1  christos 		print $0 > hfile
    177  1.1  christos 		if (blanklines < 2)
    178  1.1  christos 			print $0 > cfile
    179  1.1  christos 	}
    180  1.1  christos }
    181  1.1  christos END {
    182  1.1  christos 	# print out the match tables
    183  1.1  christos 
    184  1.1  christos 	printf("\n") > cfile
    185  1.1  christos 
    186  1.1  christos 	for (i = 1; i <= ndriver; i++) {
    187  1.3   mycroft 		nlogical = ncompat = 0;
    188  1.1  christos 		printf("/* %s */\n", driver[i, 2]) > cfile
    189  1.1  christos 		for (j = 1; j <= nlogicals; j++) {
    190  1.1  christos 			if (logicals[j, 1] == driver[i, 1]) {
    191  1.3   mycroft 				if (nlogical == 0)
    192  1.3   mycroft 					printf("static const struct isapnp_matchinfo isapnp_%s_devlogic[] = {\n",
    193  1.3   mycroft 					    driver[i, 1]) > cfile
    194  1.3   mycroft 				nlogical++;
    195  1.3   mycroft 				printf("\t{\"%s\", %d},\t/* %s */\n",
    196  1.3   mycroft 				    logicals[j, 2], logicals[j, 3],
    197  1.3   mycroft 				    logicals[j, 4]) > cfile
    198  1.1  christos 			}
    199  1.1  christos 		}
    200  1.3   mycroft 		if (nlogical != 0)
    201  1.3   mycroft 			printf("};\n") > cfile
    202  1.1  christos 		for (j = 1; j <= ncompats; j++) {
    203  1.1  christos 			if (compats[j, 1] == driver[i, 1]) {
    204  1.3   mycroft 				if (ncompat == 0)
    205  1.3   mycroft 					printf("static const struct isapnp_matchinfo isapnp_%s_devcompat[] = {\n",
    206  1.3   mycroft 					    driver[i, 1]) > cfile
    207  1.3   mycroft 				ncompat++;
    208  1.3   mycroft 				printf("\t{\"%s\", %d},\t/* %s */\n",
    209  1.3   mycroft 				    compats[j, 2], compats[j, 3],
    210  1.3   mycroft 				    compats[j, 4]) > cfile
    211  1.1  christos 			}
    212  1.1  christos 		}
    213  1.3   mycroft 		if (ncompat != 0)
    214  1.3   mycroft 			printf("};\n") > cfile
    215  1.1  christos 		printf("const struct isapnp_devinfo isapnp_%s_devinfo = {\n",
    216  1.1  christos 		    driver[i, 1]) > cfile
    217  1.3   mycroft 		if (nlogical != 0)
    218  1.3   mycroft 			printf("\tisapnp_%s_devlogic, %d,\n",
    219  1.3   mycroft 			    driver[i, 1], nlogical) > cfile
    220  1.3   mycroft 		else
    221  1.3   mycroft 			printf("\tNULL, 0,\n") > cfile
    222  1.3   mycroft 		if (ncompat != 0)
    223  1.3   mycroft 			printf("\tisapnp_%s_devcompat, %d,\n",
    224  1.3   mycroft 			    driver[i, 1], ncompat) > cfile
    225  1.3   mycroft 		else
    226  1.3   mycroft 			printf("\tNULL, 0,\n") > cfile
    227  1.3   mycroft 		printf("};\n\n") > cfile;
    228  1.1  christos 
    229  1.1  christos 	}
    230  1.1  christos }
    231