Home | History | Annotate | Line # | Download | only in tc
devlist2h.awk revision 1.3
      1 #! /usr/bin/awk -f
      2 #	$NetBSD: devlist2h.awk,v 1.3 1996/06/05 18:32:19 cgd 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 = 0
     34 	dfile="tcdevs_data.h"
     35 	hfile="tcdevs.h"
     36 }
     37 NR == 1 {
     38 	VERSION = $0
     39 	gsub("\\$", "", VERSION)
     40 
     41 	printf("/*\n") > dfile
     42 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
     43 	    > dfile
     44 	printf(" *\n") > dfile
     45 	printf(" * generated from:\n") > dfile
     46 	printf(" *\t%s\n", VERSION) > dfile
     47 	printf(" */\n") > dfile
     48 
     49 	printf("/*\n") > hfile
     50 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
     51 	    > hfile
     52 	printf(" *\n") > hfile
     53 	printf(" * generated from:\n") > hfile
     54 	printf(" *\t%s\n", VERSION) > hfile
     55 	printf(" */\n") > hfile
     56 
     57 	next
     58 }
     59 $1 == "device" {
     60 	ndevices++
     61 
     62 	devices[ndevices, 0] = $2;		# devices id
     63 	devices[ndevices, 1] = $2;		# C identifier for device
     64 	gsub("-", "_", devices[ndevices, 1]);
     65 
     66 	devices[ndevices, 2] = $3;		# driver name
     67 
     68 	printf("\n") > hfile
     69 	printf("#define\tTC_DEVICE_%s\t\"%s\"\n", devices[ndevices, 1],
     70 	    devices[ndevices, 2]) > hfile
     71 
     72 	printf("#define\tTC_DESCRIPTION_%s\t\"", devices[ndevices, 1]) > hfile
     73 
     74 	f = 4;
     75 	i = 3;
     76 
     77 	# comments
     78 	ocomment = oparen = 0
     79 	if (f <= NF) {
     80 		ocomment = 1;
     81 	}
     82 	while (f <= NF) {
     83 		if ($f == "#") {
     84 			printf("(") > hfile
     85 			oparen = 1
     86 			f++
     87 			continue
     88 		}
     89 		if (oparen) {
     90 			printf("%s", $f) > hfile
     91 			if (f < NF)
     92 				printf(" ") > hfile
     93 			f++
     94 			continue
     95 		}
     96 		devices[ndevices, i] = $f
     97 		printf("%s", devices[ndevices, i]) > hfile
     98 		if (f < NF)
     99 			printf(" ") > hfile
    100 		i++; f++;
    101 	}
    102 	if (oparen)
    103 		printf(")") > hfile
    104 	if (ocomment)
    105 		printf("\"") > hfile
    106 	printf("\n") > hfile
    107 
    108 	next
    109 }
    110 {
    111 	if ($0 == "")
    112 		blanklines++
    113 	if (blanklines < 2)
    114 		print $0 > hfile
    115 	if (blanklines < 2)
    116 		print $0 > dfile
    117 }
    118 END {
    119 	# print out the match tables
    120 
    121 	printf("\n") > dfile
    122 
    123 	printf("struct tc_knowndev tc_knowndevs[] = {\n") > dfile
    124 	for (i = 1; i <= ndevices; i++) {
    125 		printf("\t{\n") > dfile
    126 		printf("\t    \"%-8s\",\n", devices[i, 0]) \
    127 		    > dfile
    128 		printf("\t    TC_DEVICE_%s,\n", devices[i, 1]) \
    129 		    > dfile
    130 		printf("\t    TC_DESCRIPTION_%s,\n", devices[i, 1]) \
    131 		    > dfile
    132 
    133 		printf("\t},\n") > dfile
    134 	}
    135 	printf("\t{ NULL, NULL, NULL, }\n") > dfile
    136 	printf("};\n") > dfile
    137 }
    138