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