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