devlist2h.awk revision 1.1 1 #! /usr/bin/awk -f
2 # $NetBSD: devlist2h.awk,v 1.1 1998/07/23 19:30:44 christos Exp $
3 #
4 # Copyright (c) 1998, Christos Zoulas
5 # Copyright (c) 1995, 1996 Christopher G. Demetriou
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # 3. All advertising materials mentioning features or use of this software
17 # must display the following acknowledgement:
18 # This product includes software developed by Christopher G. Demetriou.
19 # This product includes software developed by Christos Zoulas
20 # 4. The name of the author(s) 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 #
34 function collectline(f, line) {
35 oparen = 0
36 line = ""
37 while (f <= NF) {
38 if ($f == "#") {
39 line = line "("
40 oparen = 1
41 f++
42 continue
43 }
44 if (oparen) {
45 line = line $f
46 if (f < NF)
47 line = line " "
48 f++
49 continue
50 }
51 line = line $f
52 if (f < NF)
53 line = line " "
54 f++
55 }
56 if (oparen)
57 line = line ")"
58 return line
59 }
60 function checkdecl() {
61 done = 1
62 if (!decl) {
63 decl = 1;
64 printf("struct isapnp_devinfo {\n") > hfile
65 printf("\tconst char *const *devlogic;\n") > hfile
66 printf("\tconst char *const *devcompat;\n") > hfile
67 printf("};\n\n") > hfile
68 printf("#include <sys/param.h>\n") > cfile
69 printf("#include <dev/isapnp/isapnpdevs.h>\n\n") > cfile
70 }
71 }
72 BEGIN {
73 decl = done = ncompat = nlogicals = ndriver = 0
74 cfile="isapnpdevs.c"
75 hfile="isapnpdevs.h"
76 }
77 NR == 1 {
78 VERSION = $0
79 gsub("\\$", "", VERSION)
80
81 printf("/*\t\$NetBSD\$\t*/\n\n") > cfile
82 printf("/*\n") > cfile
83 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
84 > cfile
85 printf(" *\n") > cfile
86 printf(" * generated from:\n") > cfile
87 printf(" *\t%s\n", VERSION) > cfile
88 printf(" */\n") > cfile
89
90 printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
91 printf("/*\n") > hfile
92 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
93 > hfile
94 printf(" *\n") > hfile
95 printf(" * generated from:\n") > hfile
96 printf(" *\t%s\n", VERSION) > hfile
97 printf(" */\n") > hfile
98 printf("\n") > hfile
99 next
100 }
101 $1 == "driver" {
102 checkdecl()
103 ndriver++
104
105 driverindex[$2] = ndriver;
106 driver[ndriver, 1] = $2;
107 driver[ndriver, 2] = collectline(3, line);
108 printf("/* %s */\n", driver[ndriver, 2]) > hfile
109 printf("extern const struct isapnp_devinfo isapnp_%s_devinfo;\n",
110 driver[ndriver, 1]) > hfile
111 next
112 }
113 $1 == "devlogic" {
114 checkdecl()
115 nlogicals++
116
117 logicals[nlogicals, 1] = $2;
118 logicals[nlogicals, 2] = $3;
119 logicals[nlogicals, 3] = collectline(4, line);
120 next
121 }
122 $1 == "devcompat" {
123 checkdecl()
124 ncompats++
125
126 compats[ncompats, 1] = $2;
127 compats[ncompats, 2] = $3;
128 compats[ncompats, 3] = collectline(4, line);
129 next
130 }
131 {
132 if (!done) {
133 if ($0 == "")
134 blanklines++
135 print $0 > hfile
136 if (blanklines < 2)
137 print $0 > cfile
138 }
139 }
140 END {
141 # print out the match tables
142
143 printf("\n") > cfile
144
145 for (i = 1; i <= ndriver; i++) {
146 printf("/* %s */\n", driver[i, 2]) > cfile
147 printf("static const char *isapnp_%s_devlogic[] = {\n",
148 driver[i, 1]) > cfile
149 for (j = 1; j <= nlogicals; j++) {
150 if (logicals[j, 1] == driver[i, 1]) {
151 printf("\t\"%s\",\t/* %s */\n", logicals[j, 2],
152 logicals[j, 3]) > cfile
153 }
154 }
155 printf("\tNULL\n};\n") > cfile
156 printf("static const char *isapnp_%s_devcompat[] = {\n",
157 driver[i, 1]) > cfile
158 for (j = 1; j <= ncompats; j++) {
159 if (compats[j, 1] == driver[i, 1]) {
160 printf("\t\"%s\",\t/* %s */\n", compats[j, 2],
161 compats[j, 3]) > cfile
162 }
163 }
164 printf("\tNULL\n};\n") > cfile
165 printf("const struct isapnp_devinfo isapnp_%s_devinfo = {\n",
166 driver[i, 1]) > cfile
167 printf("\tisapnp_%s_devlogic, isapnp_%s_devcompat\n};\n",
168 driver[i, 1], driver[i, 1]) > cfile
169 printf("\n") > cfile;
170
171 }
172 }
173