devlist2h.awk revision 1.2 1 1.1 christos #! /usr/bin/awk -f
2 1.2 christos # $NetBSD: devlist2h.awk,v 1.2 1998/09/05 14:42:05 christos Exp $
3 1.2 christos #
4 1.2 christos # Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.2 christos # All rights reserved.
6 1.2 christos #
7 1.2 christos # This code is derived from software contributed to The NetBSD Foundation
8 1.2 christos # by Christos Zoulas.
9 1.2 christos #
10 1.2 christos # Redistribution and use in source and binary forms, with or without
11 1.2 christos # modification, are permitted provided that the following conditions
12 1.2 christos # are met:
13 1.2 christos # 1. Redistributions of source code must retain the above copyright
14 1.2 christos # notice, this list of conditions and the following disclaimer.
15 1.2 christos # 2. Redistributions in binary form must reproduce the above copyright
16 1.2 christos # notice, this list of conditions and the following disclaimer in the
17 1.2 christos # documentation and/or other materials provided with the distribution.
18 1.2 christos # 3. All advertising materials mentioning features or use of this software
19 1.2 christos # must display the following acknowledgement:
20 1.2 christos # This product includes software developed by the NetBSD
21 1.2 christos # Foundation, Inc. and its contributors.
22 1.2 christos # 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 christos # contributors may be used to endorse or promote products derived
24 1.2 christos # from this software without specific prior written permission.
25 1.2 christos #
26 1.2 christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 christos # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2 christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 christos # POSSIBILITY OF SUCH DAMAGE.
37 1.1 christos #
38 1.1 christos # Copyright (c) 1995, 1996 Christopher G. Demetriou
39 1.1 christos # All rights reserved.
40 1.1 christos #
41 1.1 christos # Redistribution and use in source and binary forms, with or without
42 1.1 christos # modification, are permitted provided that the following conditions
43 1.1 christos # are met:
44 1.1 christos # 1. Redistributions of source code must retain the above copyright
45 1.1 christos # notice, this list of conditions and the following disclaimer.
46 1.1 christos # 2. Redistributions in binary form must reproduce the above copyright
47 1.1 christos # notice, this list of conditions and the following disclaimer in the
48 1.1 christos # documentation and/or other materials provided with the distribution.
49 1.1 christos # 3. All advertising materials mentioning features or use of this software
50 1.1 christos # must display the following acknowledgement:
51 1.1 christos # This product includes software developed by Christopher G. Demetriou.
52 1.1 christos # This product includes software developed by Christos Zoulas
53 1.1 christos # 4. The name of the author(s) may not be used to endorse or promote products
54 1.1 christos # derived from this software without specific prior written permission
55 1.1 christos #
56 1.1 christos # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
57 1.1 christos # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 1.1 christos # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 1.1 christos # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
60 1.1 christos # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 1.1 christos # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 1.1 christos # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 1.1 christos # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 1.1 christos # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
65 1.1 christos # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 1.1 christos #
67 1.1 christos function collectline(f, line) {
68 1.1 christos oparen = 0
69 1.1 christos line = ""
70 1.1 christos while (f <= NF) {
71 1.1 christos if ($f == "#") {
72 1.1 christos line = line "("
73 1.1 christos oparen = 1
74 1.1 christos f++
75 1.1 christos continue
76 1.1 christos }
77 1.1 christos if (oparen) {
78 1.1 christos line = line $f
79 1.1 christos if (f < NF)
80 1.1 christos line = line " "
81 1.1 christos f++
82 1.1 christos continue
83 1.1 christos }
84 1.1 christos line = line $f
85 1.1 christos if (f < NF)
86 1.1 christos line = line " "
87 1.1 christos f++
88 1.1 christos }
89 1.1 christos if (oparen)
90 1.1 christos line = line ")"
91 1.1 christos return line
92 1.1 christos }
93 1.1 christos function checkdecl() {
94 1.1 christos done = 1
95 1.1 christos if (!decl) {
96 1.1 christos decl = 1;
97 1.1 christos printf("struct isapnp_devinfo {\n") > hfile
98 1.1 christos printf("\tconst char *const *devlogic;\n") > hfile
99 1.1 christos printf("\tconst char *const *devcompat;\n") > hfile
100 1.1 christos printf("};\n\n") > hfile
101 1.1 christos printf("#include <sys/param.h>\n") > cfile
102 1.1 christos printf("#include <dev/isapnp/isapnpdevs.h>\n\n") > cfile
103 1.1 christos }
104 1.1 christos }
105 1.1 christos BEGIN {
106 1.1 christos decl = done = ncompat = nlogicals = ndriver = 0
107 1.1 christos cfile="isapnpdevs.c"
108 1.1 christos hfile="isapnpdevs.h"
109 1.1 christos }
110 1.1 christos NR == 1 {
111 1.1 christos VERSION = $0
112 1.1 christos gsub("\\$", "", VERSION)
113 1.1 christos
114 1.1 christos printf("/*\t\$NetBSD\$\t*/\n\n") > cfile
115 1.1 christos printf("/*\n") > cfile
116 1.1 christos printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
117 1.1 christos > cfile
118 1.1 christos printf(" *\n") > cfile
119 1.1 christos printf(" * generated from:\n") > cfile
120 1.1 christos printf(" *\t%s\n", VERSION) > cfile
121 1.1 christos printf(" */\n") > cfile
122 1.1 christos
123 1.1 christos printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
124 1.1 christos printf("/*\n") > hfile
125 1.1 christos printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
126 1.1 christos > hfile
127 1.1 christos printf(" *\n") > hfile
128 1.1 christos printf(" * generated from:\n") > hfile
129 1.1 christos printf(" *\t%s\n", VERSION) > hfile
130 1.1 christos printf(" */\n") > hfile
131 1.1 christos printf("\n") > hfile
132 1.1 christos next
133 1.1 christos }
134 1.1 christos $1 == "driver" {
135 1.1 christos checkdecl()
136 1.1 christos ndriver++
137 1.1 christos
138 1.1 christos driverindex[$2] = ndriver;
139 1.1 christos driver[ndriver, 1] = $2;
140 1.1 christos driver[ndriver, 2] = collectline(3, line);
141 1.1 christos printf("/* %s */\n", driver[ndriver, 2]) > hfile
142 1.1 christos printf("extern const struct isapnp_devinfo isapnp_%s_devinfo;\n",
143 1.1 christos driver[ndriver, 1]) > hfile
144 1.1 christos next
145 1.1 christos }
146 1.1 christos $1 == "devlogic" {
147 1.1 christos checkdecl()
148 1.1 christos nlogicals++
149 1.1 christos
150 1.1 christos logicals[nlogicals, 1] = $2;
151 1.1 christos logicals[nlogicals, 2] = $3;
152 1.1 christos logicals[nlogicals, 3] = collectline(4, line);
153 1.1 christos next
154 1.1 christos }
155 1.1 christos $1 == "devcompat" {
156 1.1 christos checkdecl()
157 1.1 christos ncompats++
158 1.1 christos
159 1.1 christos compats[ncompats, 1] = $2;
160 1.1 christos compats[ncompats, 2] = $3;
161 1.1 christos compats[ncompats, 3] = collectline(4, line);
162 1.1 christos next
163 1.1 christos }
164 1.1 christos {
165 1.1 christos if (!done) {
166 1.1 christos if ($0 == "")
167 1.1 christos blanklines++
168 1.1 christos print $0 > hfile
169 1.1 christos if (blanklines < 2)
170 1.1 christos print $0 > cfile
171 1.1 christos }
172 1.1 christos }
173 1.1 christos END {
174 1.1 christos # print out the match tables
175 1.1 christos
176 1.1 christos printf("\n") > cfile
177 1.1 christos
178 1.1 christos for (i = 1; i <= ndriver; i++) {
179 1.1 christos printf("/* %s */\n", driver[i, 2]) > cfile
180 1.1 christos printf("static const char *isapnp_%s_devlogic[] = {\n",
181 1.1 christos driver[i, 1]) > cfile
182 1.1 christos for (j = 1; j <= nlogicals; j++) {
183 1.1 christos if (logicals[j, 1] == driver[i, 1]) {
184 1.1 christos printf("\t\"%s\",\t/* %s */\n", logicals[j, 2],
185 1.1 christos logicals[j, 3]) > cfile
186 1.1 christos }
187 1.1 christos }
188 1.1 christos printf("\tNULL\n};\n") > cfile
189 1.1 christos printf("static const char *isapnp_%s_devcompat[] = {\n",
190 1.1 christos driver[i, 1]) > cfile
191 1.1 christos for (j = 1; j <= ncompats; j++) {
192 1.1 christos if (compats[j, 1] == driver[i, 1]) {
193 1.1 christos printf("\t\"%s\",\t/* %s */\n", compats[j, 2],
194 1.1 christos compats[j, 3]) > cfile
195 1.1 christos }
196 1.1 christos }
197 1.1 christos printf("\tNULL\n};\n") > cfile
198 1.1 christos printf("const struct isapnp_devinfo isapnp_%s_devinfo = {\n",
199 1.1 christos driver[i, 1]) > cfile
200 1.1 christos printf("\tisapnp_%s_devlogic, isapnp_%s_devcompat\n};\n",
201 1.1 christos driver[i, 1], driver[i, 1]) > cfile
202 1.1 christos printf("\n") > cfile;
203 1.1 christos
204 1.1 christos }
205 1.1 christos }
206