Home | History | Annotate | Line # | Download | only in isapnp
devlist2h.awk revision 1.2
      1 #! /usr/bin/awk -f
      2 #	$NetBSD: devlist2h.awk,v 1.2 1998/09/05 14:42:05 christos 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_devinfo {\n") > hfile
     98 		printf("\tconst char *const *devlogic;\n") > hfile
     99 		printf("\tconst char *const *devcompat;\n") > hfile
    100 		printf("};\n\n") > hfile
    101 		printf("#include <sys/param.h>\n") > cfile
    102 		printf("#include <dev/isapnp/isapnpdevs.h>\n\n") > cfile
    103 	}
    104 }
    105 BEGIN {
    106 	decl = done = ncompat = nlogicals = ndriver = 0
    107 	cfile="isapnpdevs.c"
    108 	hfile="isapnpdevs.h"
    109 }
    110 NR == 1 {
    111 	VERSION = $0
    112 	gsub("\\$", "", VERSION)
    113 
    114 	printf("/*\t\$NetBSD\$\t*/\n\n") > cfile
    115 	printf("/*\n") > cfile
    116 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    117 	    > cfile
    118 	printf(" *\n") > cfile
    119 	printf(" * generated from:\n") > cfile
    120 	printf(" *\t%s\n", VERSION) > cfile
    121 	printf(" */\n") > cfile
    122 
    123 	printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
    124 	printf("/*\n") > hfile
    125 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    126 	    > hfile
    127 	printf(" *\n") > hfile
    128 	printf(" * generated from:\n") > hfile
    129 	printf(" *\t%s\n", VERSION) > hfile
    130 	printf(" */\n") > hfile
    131 	printf("\n") > hfile
    132 	next
    133 }
    134 $1 == "driver" {
    135 	checkdecl()
    136 	ndriver++
    137 
    138 	driverindex[$2] = ndriver;
    139 	driver[ndriver, 1] = $2;
    140 	driver[ndriver, 2] = collectline(3, line);
    141 	printf("/* %s */\n", driver[ndriver, 2]) > hfile
    142 	printf("extern const struct isapnp_devinfo isapnp_%s_devinfo;\n",
    143 	    driver[ndriver, 1]) > hfile
    144 	next
    145 }
    146 $1 == "devlogic" {
    147 	checkdecl()
    148 	nlogicals++
    149 
    150 	logicals[nlogicals, 1] = $2;
    151 	logicals[nlogicals, 2] = $3;
    152 	logicals[nlogicals, 3] = collectline(4, line);
    153 	next
    154 }
    155 $1 == "devcompat" {
    156 	checkdecl()
    157 	ncompats++
    158 
    159 	compats[ncompats, 1] = $2;
    160 	compats[ncompats, 2] = $3;
    161 	compats[ncompats, 3] = collectline(4, line);
    162 	next
    163 }
    164 {
    165 	if (!done) {
    166 		if ($0 == "")
    167 			blanklines++
    168 		print $0 > hfile
    169 		if (blanklines < 2)
    170 			print $0 > cfile
    171 	}
    172 }
    173 END {
    174 	# print out the match tables
    175 
    176 	printf("\n") > cfile
    177 
    178 	for (i = 1; i <= ndriver; i++) {
    179 		printf("/* %s */\n", driver[i, 2]) > cfile
    180 		printf("static const char *isapnp_%s_devlogic[] = {\n",
    181 		    driver[i, 1]) > cfile
    182 		for (j = 1; j <= nlogicals; j++) {
    183 			if (logicals[j, 1] == driver[i, 1]) {
    184 				printf("\t\"%s\",\t/* %s */\n", logicals[j, 2],
    185 				    logicals[j, 3]) > cfile
    186 			}
    187 		}
    188 		printf("\tNULL\n};\n") > cfile
    189 		printf("static const char *isapnp_%s_devcompat[] = {\n",
    190 		    driver[i, 1]) > cfile
    191 		for (j = 1; j <= ncompats; j++) {
    192 			if (compats[j, 1] == driver[i, 1]) {
    193 				printf("\t\"%s\",\t/* %s */\n", compats[j, 2],
    194 				    compats[j, 3]) > cfile
    195 			}
    196 		}
    197 		printf("\tNULL\n};\n") > cfile
    198 		printf("const struct isapnp_devinfo isapnp_%s_devinfo = {\n",
    199 		    driver[i, 1]) > cfile
    200 		printf("\tisapnp_%s_devlogic, isapnp_%s_devcompat\n};\n",
    201 		    driver[i, 1], driver[i, 1]) > cfile
    202 		printf("\n") > cfile;
    203 
    204 	}
    205 }
    206