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