Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / dev / misc / pccard / devlist2h.awk
1 #! /usr/bin/awk -f
2 #       $NetBSD: devlist2h.awk,v 1.3 1998/09/05 14:42:06 christos Exp $
3 # $FreeBSD: src/sys/dev/pccard/devlist2h.awk,v 1.1 1999/10/26 06:52:28 imp Exp $
4 # $DragonFly: src/sys/dev/misc/pccard/Attic/devlist2h.awk,v 1.2 2003/06/17 04:28:29 dillon Exp $
5 #
6 # Copyright (c) 1998 The NetBSD Foundation, Inc.
7 # All rights reserved.
8 #
9 # This code is derived from software contributed to The NetBSD Foundation
10 # by Christos Zoulas.
11 #
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions
14 # are met:
15 # 1. Redistributions of source code must retain the above copyright
16 #    notice, this list of conditions and the following disclaimer.
17 # 2. Redistributions in binary form must reproduce the above copyright
18 #    notice, this list of conditions and the following disclaimer in the
19 #    documentation and/or other materials provided with the distribution.
20 # 3. All advertising materials mentioning features or use of this software
21 #    must display the following acknowledgement:
22 #        This product includes software developed by the NetBSD
23 #        Foundation, Inc. and its contributors.
24 # 4. Neither the name of The NetBSD Foundation nor the names of its
25 #    contributors may be used to endorse or promote products derived
26 #    from this software without specific prior written permission.
27 #
28 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 # POSSIBILITY OF SUCH DAMAGE.
39 #
40 # Copyright (c) 1995, 1996 Christopher G. Demetriou
41 # All rights reserved.
42 #
43 # Redistribution and use in source and binary forms, with or without
44 # modification, are permitted provided that the following conditions
45 # are met:
46 # 1. Redistributions of source code must retain the above copyright
47 #    notice, this list of conditions and the following disclaimer.
48 # 2. Redistributions in binary form must reproduce the above copyright
49 #    notice, this list of conditions and the following disclaimer in the
50 #    documentation and/or other materials provided with the distribution.
51 # 3. All advertising materials mentioning features or use of this software
52 #    must display the following acknowledgement:
53 #      This product includes software developed by Christopher G. Demetriou.
54 #      This product includes software developed by Christos Zoulas
55 # 4. The name of the author(s) may not be used to endorse or promote products
56 #    derived from this software without specific prior written permission
57 #
58 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 #
69 function collectline(f, line) {
70         oparen = 0
71         line = ""
72         while (f <= NF) {
73                 if ($f == "#") {
74                         line = line "("
75                         oparen = 1
76                         f++
77                         continue
78                 }
79                 if (oparen) {
80                         line = line $f
81                         if (f < NF)
82                                 line = line " "
83                         f++
84                         continue
85                 }
86                 line = line $f
87                 if (f < NF)
88                         line = line " "
89                 f++
90         }
91         if (oparen)
92                 line = line ")"
93         return line
94 }
95 BEGIN {
96         nproducts = nvendors = 0
97         dfile="pccarddevs_data.h"
98         hfile="pccarddevs.h"
99 }
100 NR == 1 {
101         VERSION = $0
102         gsub("\\$", "", VERSION)
103
104         printf("/*\t\$FreeBSD\$\t*/\n\n") > dfile
105         printf("/*\n") > dfile
106         printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
107             > dfile
108         printf(" *\n") > dfile
109         printf(" * generated from:\n") > dfile
110         printf(" *\t%s\n", VERSION) > dfile
111         printf(" */\n") > dfile
112
113         printf("/*\t\$FreeBSD\$\t*/\n\n") > hfile
114         printf("/*\n") > hfile
115         printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
116             > hfile
117         printf(" *\n") > hfile
118         printf(" * generated from:\n") > hfile
119         printf(" *\t%s\n", VERSION) > hfile
120         printf(" */\n") > hfile
121
122         next
123 }
124 $1 == "vendor" {
125         nvendors++
126
127         vendorindex[$2] = nvendors;             # record index for this name, for later.
128         vendors[nvendors, 1] = $2;              # name
129         vendors[nvendors, 2] = $3;              # id
130         printf("#define\tPCCARD_VENDOR_%s\t%s\t", vendors[nvendors, 1],
131             vendors[nvendors, 2]) > hfile
132         vendors[nvendors, 3] = collectline(4, line)
133         printf("/* %s */\n", vendors[nvendors, 3]) > hfile
134         next
135 }
136 $1 == "product" {
137         nproducts++
138
139         products[nproducts, 1] = $2;            # vendor name
140         products[nproducts, 2] = $3;            # product id
141         products[nproducts, 3] = $4;            # id
142
143         f = 5;
144
145         if ($4 == "{") {
146                 products[nproducts, 3] = -1
147                 z = "{ "
148                 for (i = 0; i < 4; i++) {
149                         if (f <= NF) {
150                                 gsub("&sp", " ", $f)
151                                 gsub("&tab", "\t", $f)
152                                 gsub("&nl", "\n", $f)
153                                 z = z $f " "
154                                 f++
155                         }
156                         else {
157                                 if (i == 3)
158                                         z = z "NULL "
159                                 else
160                                         z = z "NULL, "
161                         }
162                 }
163                 products[nproducts, 4] = z $f
164                 f++
165         }
166         else {
167                 products[nproducts, 4] = "{ NULL, NULL, NULL, NULL }"
168         }
169         printf("#define\tPCCARD_CIS_%s_%s\t%s\n",
170             products[nproducts, 1], products[nproducts, 2],
171             products[nproducts, 4]) > hfile
172         printf("#define\tPCCARD_PRODUCT_%s_%s\t%s\n", products[nproducts, 1],
173             products[nproducts, 2], products[nproducts, 3]) > hfile
174
175         products[nproducts, 5] = collectline(f, line)
176
177         printf("#define\tPCCARD_STR_%s_%s\t\"%s\"\n",
178             products[nproducts, 1], products[nproducts, 2],
179             products[nproducts, 5]) > hfile
180
181         next
182 }
183 {
184         if ($0 == "")
185                 blanklines++
186         print $0 > hfile
187         if (blanklines < 2)
188                 print $0 > dfile
189 }
190 END {
191         # print out the match tables
192
193         printf("\n") > dfile
194
195         printf("struct pccard_knowndev pccard_knowndevs[] = {\n") > dfile
196         for (i = 1; i <= nproducts; i++) {
197                 printf("\t{\n") > dfile
198                 if (products[i, 3] == -1) {
199                         printf("\t    PCCARD_VENDOR_UNKNOWN, PCCARD_PRODUCT_%s_%s,\n",
200                             products[i, 1], products[i, 2]) > dfile
201                 } else {
202                         printf("\t    PCCARD_VENDOR_%s, PCCARD_PRODUCT_%s_%s,\n",
203                             products[i, 1], products[i, 1], products[i, 2]) > dfile
204                 }
205                 printf("\t    PCCARD_CIS_%s_%s,\n", 
206                     products[i, 1], products[i, 2]) > dfile
207                 printf("\t    ") > dfile
208                 printf("0") > dfile
209                 printf(",\n") > dfile
210
211                 vendi = vendorindex[products[i, 1]];
212                 printf("\t    \"%s\",\n", vendors[vendi, 3]) > dfile
213                 printf("\t    \"%s\"\t},\n", products[i, 5]) > dfile
214                 printf("\t},\n") > dfile
215         }
216         for (i = 1; i <= nvendors; i++) {
217                 printf("\t{\n") > dfile
218                 printf("\t    PCCARD_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
219                 printf("\t    PCCARD_KNOWNDEV_NOPROD,\n") > dfile
220                 printf("\t    PCCARD_CIS_INVALID,\n") > dfile
221                 printf("\t    \"%s\",\n", vendors[i, 3]) > dfile
222                 printf("\t    NULL,\n") > dfile
223                 printf("\t},\n") > dfile
224         }
225         printf("\t{ 0, 0, { NULL, NULL, NULL, NULL }, 0, NULL, NULL, }\n") > dfile
226         printf("};\n") > dfile
227 }