xref: /netbsd/sys/arch/hp300/dev/devlist2h.awk (revision bf9ec67e)
1#! /usr/bin/awk -f
2#
3#	$NetBSD: devlist2h.awk,v 1.5 1998/01/09 06:59:10 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#
34BEGIN {
35	ndevices = 0
36	fbid = 0
37	dfile="diodevs_data.h"
38	hfile="diodevs.h"
39}
40NR == 1 {
41	VERSION = $0
42	gsub("\\$", "", VERSION)
43
44	printf("/*\t\$NetBSD\$\t*/\n\n") > dfile
45	printf("/*\n") > dfile
46	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
47	    > dfile
48	printf(" *\n") > dfile
49	printf(" * generated from:\n") > dfile
50	printf(" *\t%s\n", VERSION) > dfile
51	printf(" */\n") > dfile
52
53	printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
54	printf("/*\n") > hfile
55	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
56	    > hfile
57	printf(" *\n") > hfile
58	printf(" * generated from:\n") > hfile
59	printf(" *\t%s\n", VERSION) > hfile
60	printf(" */\n") > hfile
61
62	next
63}
64$1 == "device" {
65	ndevices++
66
67	devices[ndevices, 1] = $2		# nickname
68	devices[ndevices, 2] = $3		# dio primary id
69	devices[ndevices, 3] = "0"		# dio secondary id
70	devices[ndevices, 4] = $4		# number of select codes
71						#  used by device
72
73	# if this is the framebuffer entry, save the primary id
74	if ($2 == "FRAMEBUFFER") {
75		fbid = $3;
76	}
77
78	# emit device primary id
79	printf("\n#define\tDIO_DEVICE_ID_%s\t%s\n", devices[ndevices, 1], \
80	    devices[ndevices, 2]) > hfile
81
82	# emit description
83	printf("#define\tDIO_DEVICE_DESC_%s\t\"", devices[ndevices, 1]) \
84	    > hfile
85
86	f = 5;
87
88	while (f <= NF) {
89		printf("%s", $f) > hfile
90		if (f < NF)
91			printf(" ") > hfile
92		f++;
93	}
94	printf("\"\n") > hfile
95
96	next
97}
98$1 == "framebuffer" {
99	ndevices++
100
101	devices[ndevices, 1] = $2		# nickname
102	devices[ndevices, 2] = fbid		# dio primary id
103	devices[ndevices, 3] = $3		# dio secondary id
104	devices[ndevices, 4] = $4		# number of select codes
105						#  used by device
106
107	# emit device secondary id
108	printf("\n#define\tDIO_DEVICE_SECID_%s\t%s\n", devices[ndevices, 1], \
109	    devices[ndevices, 3]) > hfile
110
111	# emit description
112	printf("#define\tDIO_DEVICE_DESC_%s\t\"", devices[ndevices, 1]) \
113	    > hfile
114
115	f = 5;
116
117	while (f <= NF) {
118		printf("%s", $f) > hfile
119		if (f < NF)
120			printf(" ") > hfile
121		f++;
122	}
123	printf("\"\n") > hfile
124
125	next
126}
127{
128	if ($0 == "")
129		blanklines++
130	if (blanklines != 2 && blanklines != 3)
131		print $0 > hfile
132	if (blanklines < 2)
133		print $0 > dfile
134}
135END {
136	# emit device count
137
138	printf("\n") > dfile
139	printf("#define DIO_NDEVICES\t%d\n", ndevices) > dfile
140
141	# emit select code size table
142
143	printf("\n") > dfile
144
145	printf("struct dio_devdata dio_devdatas[] = {\n") > dfile
146	for (i = 1; i <= ndevices; i++) {
147		printf("\t{ %s,\t%s,\t%s },\n", devices[i, 2],
148		    devices[i, 3], devices[i, 4]) > dfile
149	}
150
151	printf("};\n") > dfile
152
153	# emit description table
154
155	printf("\n") > dfile
156	printf("#ifdef DIOVERBOSE\n") > dfile
157
158	printf("struct dio_devdesc dio_devdescs[] = {\n") > dfile
159
160	for (i = 1; i <= ndevices; i++) {
161		printf("\t{ %s,\t%s,\tDIO_DEVICE_DESC_%s },\n",
162		    devices[i, 2], devices[i, 3], devices[i, 1]) > dfile
163	}
164
165	printf("};\n") > dfile
166
167	printf("#endif /* DIOVERBOSE */\n") > dfile
168}
169