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