Home | History | Annotate | Line # | Download | only in isapnp
devlist2h.awk revision 1.5.16.2
      1       1.1  christos #! /usr/bin/awk -f
      2  1.5.16.1     skrll #	$NetBSD: devlist2h.awk,v 1.5.16.2 2004/09/18 14:48:18 skrll 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.5.16.1     skrll function collectline(f) {
     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.5.16.1     skrll 		printf("\n#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"$NetBSD" "$\");\n\n") > cfile
    108       1.1  christos 		printf("#include <sys/param.h>\n") > cfile
    109       1.1  christos 		printf("#include <dev/isapnp/isapnpdevs.h>\n\n") > cfile
    110       1.1  christos 	}
    111       1.1  christos }
    112       1.1  christos BEGIN {
    113  1.5.16.1     skrll 	decl = done = ncompat = nlogicals = ndriver = blanklines = ncompats = 0
    114       1.1  christos 	cfile="isapnpdevs.c"
    115       1.1  christos 	hfile="isapnpdevs.h"
    116       1.1  christos }
    117       1.1  christos NR == 1 {
    118       1.1  christos 	VERSION = $0
    119       1.1  christos 	gsub("\\$", "", VERSION)
    120       1.1  christos 
    121  1.5.16.1     skrll 	printf("/*\t$NetBSD" "$\t*/\n\n") > cfile
    122       1.1  christos 	printf("/*\n") > cfile
    123       1.4  augustss 	printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    124       1.1  christos 	    > cfile
    125       1.1  christos 	printf(" *\n") > cfile
    126       1.1  christos 	printf(" * generated from:\n") > cfile
    127       1.1  christos 	printf(" *\t%s\n", VERSION) > cfile
    128       1.1  christos 	printf(" */\n") > cfile
    129       1.1  christos 
    130  1.5.16.1     skrll 	printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
    131       1.1  christos 	printf("/*\n") > hfile
    132       1.4  augustss 	printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    133       1.1  christos 	    > hfile
    134       1.1  christos 	printf(" *\n") > hfile
    135       1.1  christos 	printf(" * generated from:\n") > hfile
    136       1.1  christos 	printf(" *\t%s\n", VERSION) > hfile
    137       1.1  christos 	printf(" */\n") > hfile
    138       1.1  christos 	printf("\n") > hfile
    139       1.1  christos 	next
    140       1.1  christos }
    141  1.5.16.1     skrll NF > 0 && $1 == "driver" {
    142       1.1  christos 	checkdecl()
    143       1.1  christos 	ndriver++
    144       1.1  christos 
    145       1.1  christos 	driverindex[$2] = ndriver;
    146       1.1  christos 	driver[ndriver, 1] = $2;
    147  1.5.16.1     skrll 	driver[ndriver, 2] = collectline(3);
    148       1.1  christos 	printf("/* %s */\n", driver[ndriver, 2]) > hfile
    149       1.1  christos 	printf("extern const struct isapnp_devinfo isapnp_%s_devinfo;\n",
    150       1.1  christos 	    driver[ndriver, 1]) > hfile
    151       1.1  christos 	next
    152       1.1  christos }
    153  1.5.16.1     skrll NF > 0 && $1 == "devlogic" {
    154       1.1  christos 	checkdecl()
    155       1.1  christos 	nlogicals++
    156       1.1  christos 
    157       1.1  christos 	logicals[nlogicals, 1] = $2;
    158       1.1  christos 	logicals[nlogicals, 2] = $3;
    159       1.3   mycroft 	logicals[nlogicals, 3] = $4;
    160  1.5.16.1     skrll 	logicals[nlogicals, 4] = collectline(5);
    161       1.1  christos 	next
    162       1.1  christos }
    163  1.5.16.1     skrll NF > 0 && $1 == "devcompat" {
    164       1.1  christos 	checkdecl()
    165       1.1  christos 	ncompats++
    166       1.1  christos 
    167       1.1  christos 	compats[ncompats, 1] = $2;
    168       1.1  christos 	compats[ncompats, 2] = $3;
    169       1.3   mycroft 	compats[ncompats, 3] = $4;
    170  1.5.16.1     skrll 	compats[ncompats, 4] = collectline(5);
    171       1.1  christos 	next
    172       1.1  christos }
    173       1.1  christos {
    174       1.1  christos 	if (!done) {
    175       1.1  christos 		if ($0 == "")
    176       1.1  christos 			blanklines++
    177       1.1  christos 		print $0 > hfile
    178       1.1  christos 		if (blanklines < 2)
    179       1.1  christos 			print $0 > cfile
    180       1.1  christos 	}
    181       1.1  christos }
    182       1.1  christos END {
    183       1.1  christos 	# print out the match tables
    184       1.1  christos 
    185       1.1  christos 	printf("\n") > cfile
    186       1.1  christos 
    187       1.1  christos 	for (i = 1; i <= ndriver; i++) {
    188       1.3   mycroft 		nlogical = ncompat = 0;
    189       1.1  christos 		printf("/* %s */\n", driver[i, 2]) > cfile
    190       1.1  christos 		for (j = 1; j <= nlogicals; j++) {
    191       1.1  christos 			if (logicals[j, 1] == driver[i, 1]) {
    192       1.3   mycroft 				if (nlogical == 0)
    193       1.3   mycroft 					printf("static const struct isapnp_matchinfo isapnp_%s_devlogic[] = {\n",
    194       1.3   mycroft 					    driver[i, 1]) > cfile
    195       1.3   mycroft 				nlogical++;
    196       1.3   mycroft 				printf("\t{\"%s\", %d},\t/* %s */\n",
    197       1.3   mycroft 				    logicals[j, 2], logicals[j, 3],
    198       1.3   mycroft 				    logicals[j, 4]) > cfile
    199       1.1  christos 			}
    200       1.1  christos 		}
    201       1.3   mycroft 		if (nlogical != 0)
    202       1.3   mycroft 			printf("};\n") > cfile
    203       1.1  christos 		for (j = 1; j <= ncompats; j++) {
    204       1.1  christos 			if (compats[j, 1] == driver[i, 1]) {
    205       1.3   mycroft 				if (ncompat == 0)
    206       1.3   mycroft 					printf("static const struct isapnp_matchinfo isapnp_%s_devcompat[] = {\n",
    207       1.3   mycroft 					    driver[i, 1]) > cfile
    208       1.3   mycroft 				ncompat++;
    209       1.3   mycroft 				printf("\t{\"%s\", %d},\t/* %s */\n",
    210       1.3   mycroft 				    compats[j, 2], compats[j, 3],
    211       1.3   mycroft 				    compats[j, 4]) > cfile
    212       1.1  christos 			}
    213       1.1  christos 		}
    214       1.3   mycroft 		if (ncompat != 0)
    215       1.3   mycroft 			printf("};\n") > cfile
    216       1.1  christos 		printf("const struct isapnp_devinfo isapnp_%s_devinfo = {\n",
    217       1.1  christos 		    driver[i, 1]) > cfile
    218       1.3   mycroft 		if (nlogical != 0)
    219       1.3   mycroft 			printf("\tisapnp_%s_devlogic, %d,\n",
    220       1.3   mycroft 			    driver[i, 1], nlogical) > cfile
    221       1.3   mycroft 		else
    222       1.3   mycroft 			printf("\tNULL, 0,\n") > cfile
    223       1.3   mycroft 		if (ncompat != 0)
    224       1.3   mycroft 			printf("\tisapnp_%s_devcompat, %d,\n",
    225       1.3   mycroft 			    driver[i, 1], ncompat) > cfile
    226       1.3   mycroft 		else
    227       1.3   mycroft 			printf("\tNULL, 0,\n") > cfile
    228       1.3   mycroft 		printf("};\n\n") > cfile;
    229       1.1  christos 
    230       1.1  christos 	}
    231  1.5.16.1     skrll 	close(cfile)
    232  1.5.16.1     skrll 	close(hfile)
    233       1.1  christos }
    234