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