Home | History | Annotate | Line # | Download | only in dev
devlist2h.awk revision 1.1
      1 #! /usr/bin/awk -f
      2 #
      3 #	$NetBSD: devlist2h.awk,v 1.1 1996/12/17 08:41:02 thorpej Exp $
      4 #
      5 # Copyright (c) 1996 Jason R. Thorpe.  All rights reserved.
      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 Christopher G. Demetriou.
     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 	ndevices = 0
     36 	fbid = 0
     37 	dfile="diodevs_data.h"
     38 	hfile="diodevs.h"
     39 }
     40 NR == 1 {
     41 	VERSION = $0
     42 	gsub("\\$", "", VERSION)
     43 
     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("/*\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 $1 == "device" {
     63 	ndevices++
     64 
     65 	devices[ndevices, 1] = $2		# nickname
     66 	devices[ndevices, 2] = $3		# dio primary id
     67 	devices[ndevices, 3] = "0"		# dio secondary id
     68 	devices[ndevices, 4] = $4		# number of select codes
     69 						#  used by device
     70 
     71 	# if this is the framebuffer entry, save the primary id
     72 	if ($2 == "FRAMEBUFFER") {
     73 		fbid = $3;
     74 	}
     75 
     76 	# emit device primary id
     77 	printf("\n#define\tDIO_DEVICE_ID_%s\t%s\n", devices[ndevices, 1], \
     78 	    devices[ndevices, 2]) > hfile
     79 
     80 	# emit description
     81 	printf("#define\tDIO_DEVICE_DESC_%s\t\"", devices[ndevices, 1]) \
     82 	    > hfile
     83 
     84 	f = 5;
     85 
     86 	while (f <= NF) {
     87 		printf("%s", $f) > hfile
     88 		if (f < NF)
     89 			printf(" ") > hfile
     90 		f++;
     91 	}
     92 	printf("\"\n") > hfile
     93 
     94 	next
     95 }
     96 $1 == "framebuffer" {
     97 	ndevices++
     98 
     99 	devices[ndevices, 1] = $2		# nickname
    100 	devices[ndevices, 2] = fbid		# dio primary id
    101 	devices[ndevices, 3] = $3		# dio secondary id
    102 	devices[ndevices, 4] = $4		# number of select codes
    103 						#  used by device
    104 
    105 	# emit device secondary id
    106 	printf("\n#define\tDIO_DEVICE_SECID_%s\t%s\n", devices[ndevices, 1], \
    107 	    devices[ndevices, 3]) > hfile
    108 
    109 	# emit description
    110 	printf("#define\tDIO_DEVICE_DESC_%s\t\"", devices[ndevices, 1]) \
    111 	    > hfile
    112 
    113 	f = 5;
    114 
    115 	while (f <= NF) {
    116 		printf("%s", $f) > hfile
    117 		if (f < NF)
    118 			printf(" ") > hfile
    119 		f++;
    120 	}
    121 	printf("\"\n") > hfile
    122 
    123 	next
    124 }
    125 {
    126 	if ($0 == "")
    127 		blanklines++
    128 	if (blanklines != 2 && blanklines != 3)
    129 		print $0 > hfile
    130 	if (blanklines < 2)
    131 		print $0 > dfile
    132 }
    133 END {
    134 	# emit device count
    135 
    136 	printf("\n") > dfile
    137 	printf("#define DIO_NDEVICES\t%d\n", ndevices) > dfile
    138 
    139 	# emit select code size table
    140 
    141 	printf("\n") > dfile
    142 
    143 	printf("struct dio_devdata dio_devdatas[] = {\n") > dfile
    144 	for (i = 1; i <= ndevices; i++) {
    145 		printf("\t{ %s,\t%s,\t%s },\n", devices[i, 2],
    146 		    devices[i, 3], devices[i, 4]) > dfile
    147 	}
    148 
    149 	printf("};\n") > dfile
    150 
    151 	# emit description table
    152 
    153 	printf("\n") > dfile
    154 	printf("#ifdef DIOVERBOSE\n") > dfile
    155 
    156 	printf("struct dio_devdesc dio_devdescs[] = {\n") > dfile
    157 
    158 	for (i = 1; i <= ndevices; i++) {
    159 		printf("\t{ %s,\t%s,\tDIO_DEVICE_DESC_%s },\n",
    160 		    devices[i, 2], devices[i, 3], devices[i, 1]) > dfile
    161 	}
    162 
    163 	printf("};\n") > dfile
    164 
    165 	printf("#endif /* DIOVERBOSE */\n") > dfile
    166 }
    167