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