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