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