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