Home | History | Annotate | Line # | Download | only in pcmcia
devlist2h.awk revision 1.10
      1   1.1  christos #! /usr/bin/awk -f
      2  1.10     perry #	$NetBSD: devlist2h.awk,v 1.10 2005/02/27 15:29:09 perry Exp $
      3   1.3  christos #
      4   1.8   mycroft # Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
      5   1.3  christos # All rights reserved.
      6   1.3  christos #
      7   1.3  christos # This code is derived from software contributed to The NetBSD Foundation
      8   1.3  christos # by Christos Zoulas.
      9   1.3  christos #
     10   1.3  christos # Redistribution and use in source and binary forms, with or without
     11   1.3  christos # modification, are permitted provided that the following conditions
     12   1.3  christos # are met:
     13   1.3  christos # 1. Redistributions of source code must retain the above copyright
     14   1.3  christos #    notice, this list of conditions and the following disclaimer.
     15   1.3  christos # 2. Redistributions in binary form must reproduce the above copyright
     16   1.3  christos #    notice, this list of conditions and the following disclaimer in the
     17   1.3  christos #    documentation and/or other materials provided with the distribution.
     18   1.3  christos # 3. All advertising materials mentioning features or use of this software
     19   1.3  christos #    must display the following acknowledgement:
     20   1.3  christos #        This product includes software developed by the NetBSD
     21   1.3  christos #        Foundation, Inc. and its contributors.
     22   1.3  christos # 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.3  christos #    contributors may be used to endorse or promote products derived
     24   1.3  christos #    from this software without specific prior written permission.
     25   1.3  christos #
     26   1.3  christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.3  christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.3  christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.3  christos # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.3  christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.3  christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.3  christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.3  christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.3  christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.3  christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.3  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.2  christos #      This product includes software developed by Christos Zoulas
     53   1.2  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.7       jmc function collectline(_f, _line) {
     68   1.7       jmc 	_oparen = 0
     69   1.7       jmc 	_line = ""
     70   1.7       jmc 	while (_f <= NF) {
     71   1.7       jmc 		if ($_f == "#") {
     72   1.7       jmc 			_line = _line "("
     73   1.7       jmc 			_oparen = 1
     74   1.7       jmc 			_f++
     75   1.2  christos 			continue
     76   1.2  christos 		}
     77   1.7       jmc 		if (_oparen) {
     78   1.7       jmc 			_line = _line $_f
     79   1.7       jmc 			if (_f < NF)
     80   1.7       jmc 				_line = _line " "
     81   1.7       jmc 			_f++
     82   1.2  christos 			continue
     83   1.2  christos 		}
     84   1.7       jmc 		_line = _line $_f
     85   1.7       jmc 		if (_f < NF)
     86   1.7       jmc 			_line = _line " "
     87   1.7       jmc 		_f++
     88   1.2  christos 	}
     89   1.7       jmc 	if (_oparen)
     90   1.7       jmc 		_line = _line ")"
     91   1.7       jmc 	return _line
     92   1.2  christos }
     93   1.1  christos BEGIN {
     94   1.7       jmc 	nproducts = nvendors = blanklines = 0
     95   1.1  christos 	dfile="pcmciadevs_data.h"
     96   1.1  christos 	hfile="pcmciadevs.h"
     97   1.5  christos 	line=""
     98   1.1  christos }
     99   1.1  christos NR == 1 {
    100   1.1  christos 	VERSION = $0
    101   1.1  christos 	gsub("\\$", "", VERSION)
    102  1.10     perry 	gsub(/ $/, "", VERSION)
    103   1.1  christos 
    104   1.7       jmc 	printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
    105   1.1  christos 	printf("/*\n") > dfile
    106   1.1  christos 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    107   1.1  christos 	    > dfile
    108   1.1  christos 	printf(" *\n") > dfile
    109   1.1  christos 	printf(" * generated from:\n") > dfile
    110   1.1  christos 	printf(" *\t%s\n", VERSION) > dfile
    111   1.1  christos 	printf(" */\n") > dfile
    112   1.1  christos 
    113   1.7       jmc 	printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
    114   1.1  christos 	printf("/*\n") > hfile
    115   1.1  christos 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    116   1.1  christos 	    > hfile
    117   1.1  christos 	printf(" *\n") > hfile
    118   1.1  christos 	printf(" * generated from:\n") > hfile
    119   1.1  christos 	printf(" *\t%s\n", VERSION) > hfile
    120   1.1  christos 	printf(" */\n") > hfile
    121   1.1  christos 
    122   1.1  christos 	next
    123   1.1  christos }
    124   1.7       jmc NF > 0 && $1 == "vendor" {
    125   1.1  christos 	nvendors++
    126   1.1  christos 
    127   1.1  christos 	vendorindex[$2] = nvendors;		# record index for this name, for later.
    128   1.1  christos 	vendors[nvendors, 1] = $2;		# name
    129   1.1  christos 	vendors[nvendors, 2] = $3;		# id
    130   1.1  christos 	printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1],
    131   1.1  christos 	    vendors[nvendors, 2]) > hfile
    132   1.2  christos 	vendors[nvendors, 3] = collectline(4, line)
    133   1.2  christos 	printf("/* %s */\n", vendors[nvendors, 3]) > hfile
    134   1.1  christos 	next
    135   1.1  christos }
    136   1.7       jmc NF > 0 && $1 == "product" {
    137   1.1  christos 	nproducts++
    138   1.1  christos 
    139   1.1  christos 	products[nproducts, 1] = $2;		# vendor name
    140   1.1  christos 	products[nproducts, 2] = $3;		# product id
    141   1.1  christos 	products[nproducts, 3] = $4;		# id
    142   1.1  christos 
    143   1.1  christos 	f = 5;
    144   1.1  christos 
    145   1.1  christos 	if ($4 == "{") {
    146   1.1  christos 		products[nproducts, 3] = -1
    147   1.1  christos 		z = "{ "
    148   1.1  christos 		for (i = 0; i < 4; i++) {
    149   1.1  christos 			if (f <= NF) {
    150   1.1  christos 				gsub("&sp", " ", $f)
    151   1.1  christos 				gsub("&tab", "\t", $f)
    152   1.1  christos 				gsub("&nl", "\n", $f)
    153   1.1  christos 				z = z $f " "
    154   1.1  christos 				f++
    155   1.1  christos 			}
    156   1.1  christos 			else {
    157   1.1  christos 				if (i == 3)
    158   1.1  christos 					z = z "NULL "
    159   1.1  christos 				else
    160   1.1  christos 					z = z "NULL, "
    161   1.1  christos 			}
    162   1.1  christos 		}
    163   1.1  christos 		products[nproducts, 4] = z $f
    164   1.1  christos 		f++
    165   1.1  christos 	}
    166   1.1  christos 	else {
    167   1.1  christos 		products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
    168   1.1  christos 	}
    169   1.1  christos 	printf("#define\tPCMCIA_CIS_%s_%s\t%s\n",
    170   1.1  christos 	    products[nproducts, 1], products[nproducts, 2],
    171   1.1  christos 	    products[nproducts, 4]) > hfile
    172   1.1  christos 	printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
    173   1.1  christos 	    products[nproducts, 2], products[nproducts, 3]) > hfile
    174   1.1  christos 
    175   1.2  christos 	products[nproducts, 5] = collectline(f, line)
    176   1.1  christos 
    177   1.1  christos 	next
    178   1.1  christos }
    179   1.1  christos {
    180   1.1  christos 	if ($0 == "")
    181   1.1  christos 		blanklines++
    182   1.1  christos 	print $0 > hfile
    183   1.1  christos 	if (blanklines < 2)
    184   1.1  christos 		print $0 > dfile
    185   1.1  christos }
    186   1.1  christos END {
    187   1.1  christos 	# print out the match tables
    188   1.1  christos 
    189   1.1  christos 	printf("\n") > dfile
    190   1.1  christos 
    191   1.4      haya 	printf("struct pcmcia_knowndev {\n") > dfile
    192   1.4      haya 	printf("\tint vendorid;\n") > dfile
    193   1.4      haya 	printf("\tint productid;\n") > dfile
    194   1.4      haya 	printf("\tstruct pcmcia_knowndev_cis {\n") > dfile
    195   1.4      haya 	printf("\t\tchar *vendor;\n") > dfile
    196   1.4      haya 	printf("\t\tchar *product;\n") > dfile
    197   1.4      haya 	printf("\t\tchar *version;\n") > dfile
    198   1.4      haya 	printf("\t\tchar *revision;\n") > dfile
    199   1.4      haya 	printf("\t}cis;\n") > dfile
    200   1.4      haya 	printf("\tint flags;\n") > dfile
    201   1.4      haya 	printf("\tchar *vendorname;\n") > dfile
    202   1.4      haya 	printf("\tchar *devicename;\n") > dfile
    203   1.4      haya 	printf("\tint reserve;\n") > dfile
    204   1.4      haya 	printf("};\n\n") > dfile
    205   1.4      haya 	printf("#define	PCMCIA_CIS_INVALID\t\t{ NULL, NULL, NULL, NULL }\n") > dfile
    206   1.4      haya 	printf("#define	PCMCIA_KNOWNDEV_NOPROD\t\t0\n\n") > dfile
    207   1.1  christos 	printf("struct pcmcia_knowndev pcmcia_knowndevs[] = {\n") > dfile
    208   1.1  christos 	for (i = 1; i <= nproducts; i++) {
    209   1.1  christos 		printf("\t{\n") > dfile
    210   1.1  christos 		if (products[i, 3] == -1) {
    211   1.1  christos 			printf("\t    PCMCIA_VENDOR_UNKNOWN, PCMCIA_PRODUCT_%s_%s,\n",
    212   1.1  christos 			    products[i, 1], products[i, 2]) > dfile
    213   1.1  christos 		} else {
    214   1.1  christos 			printf("\t    PCMCIA_VENDOR_%s, PCMCIA_PRODUCT_%s_%s,\n",
    215   1.1  christos 			    products[i, 1], products[i, 1], products[i, 2]) > dfile
    216   1.1  christos 		}
    217   1.9     perry 		printf("\t    PCMCIA_CIS_%s_%s,\n",
    218   1.1  christos 		    products[i, 1], products[i, 2]) > dfile
    219   1.1  christos 		printf("\t    ") > dfile
    220   1.1  christos 		printf("0") > dfile
    221   1.1  christos 		printf(",\n") > dfile
    222   1.1  christos 
    223   1.7       jmc 		if (products[i, 1] in vendorindex) {
    224   1.7       jmc 			vendi = vendorindex[products[i, 1]];
    225   1.7       jmc 			vendname = vendors[vendi, 3]
    226   1.7       jmc 		}
    227   1.7       jmc 		else
    228   1.7       jmc 			vendname = ""
    229   1.7       jmc 		printf("\t    \"%s\",\n", vendname) > dfile
    230   1.4      haya 		printf("\t    \"%s\",\t}\n", products[i, 5]) > dfile
    231   1.4      haya 		printf("\t,\n") > dfile
    232   1.1  christos 	}
    233   1.1  christos 	for (i = 1; i <= nvendors; i++) {
    234   1.1  christos 		printf("\t{\n") > dfile
    235   1.4      haya 		printf("\t    PCMCIA_VENDOR_%s,\n", vendors[i, 1]) > dfile
    236   1.1  christos 		printf("\t    PCMCIA_KNOWNDEV_NOPROD,\n") > dfile
    237   1.1  christos 		printf("\t    PCMCIA_CIS_INVALID,\n") > dfile
    238   1.4      haya 		printf("\t    0,\n") > dfile
    239   1.2  christos 		printf("\t    \"%s\",\n", vendors[i, 3]) > dfile
    240   1.1  christos 		printf("\t    NULL,\n") > dfile
    241   1.1  christos 		printf("\t},\n") > dfile
    242   1.1  christos 	}
    243   1.1  christos 	printf("\t{ 0, 0, { NULL, NULL, NULL, NULL }, 0, NULL, NULL, }\n") > dfile
    244   1.1  christos 	printf("};\n") > dfile
    245   1.7       jmc 	close(dfile)
    246   1.7       jmc 	close(hfile)
    247   1.1  christos }
    248