Home | History | Annotate | Line # | Download | only in pcmcia
      1   1.1  christos #! /usr/bin/awk -f
      2  1.13  christos #	$NetBSD: devlist2h.awk,v 1.13 2017/06/03 14:46:29 christos 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 #
     19   1.3  christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.3  christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.3  christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.3  christos # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.3  christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.3  christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.3  christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.3  christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.3  christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.3  christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.3  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.2  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.7       jmc function collectline(_f, _line) {
     60   1.7       jmc 	_oparen = 0
     61   1.7       jmc 	_line = ""
     62   1.7       jmc 	while (_f <= NF) {
     63   1.7       jmc 		if ($_f == "#") {
     64   1.7       jmc 			_line = _line "("
     65   1.7       jmc 			_oparen = 1
     66   1.7       jmc 			_f++
     67   1.2  christos 			continue
     68   1.2  christos 		}
     69   1.7       jmc 		if (_oparen) {
     70   1.7       jmc 			_line = _line $_f
     71   1.7       jmc 			if (_f < NF)
     72   1.7       jmc 				_line = _line " "
     73   1.7       jmc 			_f++
     74   1.2  christos 			continue
     75   1.2  christos 		}
     76   1.7       jmc 		_line = _line $_f
     77   1.7       jmc 		if (_f < NF)
     78   1.7       jmc 			_line = _line " "
     79   1.7       jmc 		_f++
     80   1.2  christos 	}
     81   1.7       jmc 	if (_oparen)
     82   1.7       jmc 		_line = _line ")"
     83   1.7       jmc 	return _line
     84   1.2  christos }
     85   1.1  christos BEGIN {
     86   1.7       jmc 	nproducts = nvendors = blanklines = 0
     87   1.1  christos 	dfile="pcmciadevs_data.h"
     88   1.1  christos 	hfile="pcmciadevs.h"
     89   1.5  christos 	line=""
     90   1.1  christos }
     91   1.1  christos NR == 1 {
     92   1.1  christos 	VERSION = $0
     93   1.1  christos 	gsub("\\$", "", VERSION)
     94  1.10     perry 	gsub(/ $/, "", VERSION)
     95   1.1  christos 
     96   1.7       jmc 	printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
     97   1.1  christos 	printf("/*\n") > dfile
     98   1.1  christos 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
     99   1.1  christos 	    > dfile
    100   1.1  christos 	printf(" *\n") > dfile
    101   1.1  christos 	printf(" * generated from:\n") > dfile
    102   1.1  christos 	printf(" *\t%s\n", VERSION) > dfile
    103   1.1  christos 	printf(" */\n") > dfile
    104   1.1  christos 
    105   1.7       jmc 	printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
    106   1.1  christos 	printf("/*\n") > hfile
    107   1.1  christos 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    108   1.1  christos 	    > hfile
    109   1.1  christos 	printf(" *\n") > hfile
    110   1.1  christos 	printf(" * generated from:\n") > hfile
    111   1.1  christos 	printf(" *\t%s\n", VERSION) > hfile
    112   1.1  christos 	printf(" */\n") > hfile
    113   1.1  christos 
    114   1.1  christos 	next
    115   1.1  christos }
    116   1.7       jmc NF > 0 && $1 == "vendor" {
    117   1.1  christos 	nvendors++
    118   1.1  christos 
    119   1.1  christos 	vendorindex[$2] = nvendors;		# record index for this name, for later.
    120   1.1  christos 	vendors[nvendors, 1] = $2;		# name
    121   1.1  christos 	vendors[nvendors, 2] = $3;		# id
    122   1.1  christos 	printf("#define\tPCMCIA_VENDOR_%s\t%s\t", vendors[nvendors, 1],
    123   1.1  christos 	    vendors[nvendors, 2]) > hfile
    124   1.2  christos 	vendors[nvendors, 3] = collectline(4, line)
    125   1.2  christos 	printf("/* %s */\n", vendors[nvendors, 3]) > hfile
    126   1.1  christos 	next
    127   1.1  christos }
    128   1.7       jmc NF > 0 && $1 == "product" {
    129   1.1  christos 	nproducts++
    130   1.1  christos 
    131   1.1  christos 	products[nproducts, 1] = $2;		# vendor name
    132   1.1  christos 	products[nproducts, 2] = $3;		# product id
    133   1.1  christos 	products[nproducts, 3] = $4;		# id
    134   1.1  christos 
    135   1.1  christos 	f = 5;
    136   1.1  christos 
    137   1.1  christos 	if ($4 == "{") {
    138   1.1  christos 		products[nproducts, 3] = -1
    139   1.1  christos 		z = "{ "
    140   1.1  christos 		for (i = 0; i < 4; i++) {
    141   1.1  christos 			if (f <= NF) {
    142   1.1  christos 				gsub("&sp", " ", $f)
    143   1.1  christos 				gsub("&tab", "\t", $f)
    144   1.1  christos 				gsub("&nl", "\n", $f)
    145   1.1  christos 				z = z $f " "
    146   1.1  christos 				f++
    147   1.1  christos 			}
    148   1.1  christos 			else {
    149   1.1  christos 				if (i == 3)
    150   1.1  christos 					z = z "NULL "
    151   1.1  christos 				else
    152   1.1  christos 					z = z "NULL, "
    153   1.1  christos 			}
    154   1.1  christos 		}
    155   1.1  christos 		products[nproducts, 4] = z $f
    156   1.1  christos 		f++
    157   1.1  christos 	}
    158   1.1  christos 	else {
    159   1.1  christos 		products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
    160   1.1  christos 	}
    161   1.1  christos 	printf("#define\tPCMCIA_CIS_%s_%s\t%s\n",
    162   1.1  christos 	    products[nproducts, 1], products[nproducts, 2],
    163   1.1  christos 	    products[nproducts, 4]) > hfile
    164   1.1  christos 	printf("#define\tPCMCIA_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
    165   1.1  christos 	    products[nproducts, 2], products[nproducts, 3]) > hfile
    166   1.1  christos 
    167   1.2  christos 	products[nproducts, 5] = collectline(f, line)
    168   1.1  christos 
    169   1.1  christos 	next
    170   1.1  christos }
    171   1.1  christos {
    172   1.1  christos 	if ($0 == "")
    173   1.1  christos 		blanklines++
    174   1.1  christos 	print $0 > hfile
    175   1.1  christos 	if (blanklines < 2)
    176   1.1  christos 		print $0 > dfile
    177   1.1  christos }
    178   1.1  christos END {
    179   1.1  christos 	# print out the match tables
    180   1.1  christos 
    181   1.1  christos 	printf("\n") > dfile
    182   1.1  christos 
    183   1.4      haya 	printf("struct pcmcia_knowndev {\n") > dfile
    184   1.4      haya 	printf("\tint vendorid;\n") > dfile
    185   1.4      haya 	printf("\tint productid;\n") > dfile
    186   1.4      haya 	printf("\tstruct pcmcia_knowndev_cis {\n") > dfile
    187   1.4      haya 	printf("\t\tchar *vendor;\n") > dfile
    188   1.4      haya 	printf("\t\tchar *product;\n") > dfile
    189   1.4      haya 	printf("\t\tchar *version;\n") > dfile
    190   1.4      haya 	printf("\t\tchar *revision;\n") > dfile
    191   1.4      haya 	printf("\t}cis;\n") > dfile
    192   1.4      haya 	printf("\tint flags;\n") > dfile
    193   1.4      haya 	printf("\tchar *vendorname;\n") > dfile
    194   1.4      haya 	printf("\tchar *devicename;\n") > dfile
    195   1.4      haya 	printf("\tint reserve;\n") > dfile
    196   1.4      haya 	printf("};\n\n") > dfile
    197   1.4      haya 	printf("#define	PCMCIA_CIS_INVALID\t\t{ NULL, NULL, NULL, NULL }\n") > dfile
    198   1.4      haya 	printf("#define	PCMCIA_KNOWNDEV_NOPROD\t\t0\n\n") > dfile
    199   1.1  christos 	printf("struct pcmcia_knowndev pcmcia_knowndevs[] = {\n") > dfile
    200   1.1  christos 	for (i = 1; i <= nproducts; i++) {
    201   1.1  christos 		printf("\t{\n") > dfile
    202   1.1  christos 		if (products[i, 3] == -1) {
    203   1.1  christos 			printf("\t    PCMCIA_VENDOR_UNKNOWN, PCMCIA_PRODUCT_%s_%s,\n",
    204   1.1  christos 			    products[i, 1], products[i, 2]) > dfile
    205   1.1  christos 		} else {
    206   1.1  christos 			printf("\t    PCMCIA_VENDOR_%s, PCMCIA_PRODUCT_%s_%s,\n",
    207   1.1  christos 			    products[i, 1], products[i, 1], products[i, 2]) > dfile
    208   1.1  christos 		}
    209   1.9     perry 		printf("\t    PCMCIA_CIS_%s_%s,\n",
    210   1.1  christos 		    products[i, 1], products[i, 2]) > dfile
    211   1.1  christos 		printf("\t    ") > dfile
    212   1.1  christos 		printf("0") > dfile
    213   1.1  christos 		printf(",\n") > dfile
    214   1.1  christos 
    215   1.7       jmc 		if (products[i, 1] in vendorindex) {
    216   1.7       jmc 			vendi = vendorindex[products[i, 1]];
    217   1.7       jmc 			vendname = vendors[vendi, 3]
    218   1.7       jmc 		}
    219   1.7       jmc 		else
    220   1.7       jmc 			vendname = ""
    221   1.7       jmc 		printf("\t    \"%s\",\n", vendname) > dfile
    222   1.4      haya 		printf("\t    \"%s\",\t}\n", products[i, 5]) > dfile
    223   1.4      haya 		printf("\t,\n") > dfile
    224   1.1  christos 	}
    225   1.1  christos 	for (i = 1; i <= nvendors; i++) {
    226   1.1  christos 		printf("\t{\n") > dfile
    227   1.4      haya 		printf("\t    PCMCIA_VENDOR_%s,\n", vendors[i, 1]) > dfile
    228   1.1  christos 		printf("\t    PCMCIA_KNOWNDEV_NOPROD,\n") > dfile
    229   1.1  christos 		printf("\t    PCMCIA_CIS_INVALID,\n") > dfile
    230   1.4      haya 		printf("\t    0,\n") > dfile
    231   1.2  christos 		printf("\t    \"%s\",\n", vendors[i, 3]) > dfile
    232   1.1  christos 		printf("\t    NULL,\n") > dfile
    233   1.1  christos 		printf("\t},\n") > dfile
    234   1.1  christos 	}
    235   1.1  christos 	printf("\t{ 0, 0, { NULL, NULL, NULL, NULL }, 0, NULL, NULL, }\n") > dfile
    236   1.1  christos 	printf("};\n") > dfile
    237   1.7       jmc 	close(dfile)
    238   1.7       jmc 	close(hfile)
    239   1.1  christos }
    240