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