WARNS6 cleanups
[dragonfly.git] / sys / bus / pci / devlist2h.awk
1 #! /usr/bin/awk -f
2 #       $DragonFly: src/sys/bus/pci/devlist2h.awk,v 1.2 2004/02/19 20:47:56 joerg Exp $
3 #       $NetBSD: devlist2h.awk,v 1.7 2003/12/05 04:33:27 grant Exp $
4 #
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 # 4. The name of the author may not be used to endorse or promote products
20 #    derived from this software without specific prior written permission
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #
33 BEGIN {
34         nproducts = nvendors = blanklines = 0
35         dfile="pcidevs_data.h"
36         hfile="pcidevs.h"
37 }
38 NR == 1 {
39         VERSION = $0
40         gsub("\\$", "", VERSION)
41
42         printf("/*\t$DragonFly" "$\t*/\n\n") > dfile
43         printf("/*\n") > dfile
44         printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
45             > dfile
46         printf(" *\n") > dfile
47         printf(" * generated from:\n") > dfile
48         printf(" *\t%s\n", VERSION) > dfile
49         printf(" */\n") > dfile
50
51         printf("/*\t$DragonFly" "$\t*/\n\n") > hfile
52         printf("/*\n") > hfile
53         printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
54             > hfile
55         printf(" *\n") > hfile
56         printf(" * generated from:\n") > hfile
57         printf(" *\t%s\n", VERSION) > hfile
58         printf(" */\n") > hfile
59
60         next
61 }
62 NF > 0 && $1 == "vendor" {
63         nvendors++
64
65         vendorindex[$2] = nvendors;             # record index for this name, for later.
66         vendors[nvendors, 1] = $2;              # name
67         vendors[nvendors, 2] = $3;              # id
68         printf("#define\tPCI_VENDOR_%s\t%s\t", vendors[nvendors, 1],
69             vendors[nvendors, 2]) > hfile
70
71         i = 3; f = 4;
72
73         # comments
74         ocomment = oparen = 0
75         if (f <= NF) {
76                 printf("\t/* ") > hfile
77                 ocomment = 1;
78         }
79         while (f <= NF) {
80                 if ($f == "#") {
81                         printf("(") > hfile
82                         oparen = 1
83                         f++
84                         continue
85                 }
86                 if (oparen) {
87                         printf("%s", $f) > hfile
88                         if (f < NF)
89                                 printf(" ") > hfile
90                         f++
91                         continue
92                 }
93                 vendors[nvendors, i] = $f
94                 printf("%s", vendors[nvendors, i]) > hfile
95                 if (f < NF)
96                         printf(" ") > hfile
97                 i++; f++;
98         }
99         if (oparen)
100                 printf(")") > hfile
101         if (ocomment)
102                 printf(" */") > hfile
103         printf("\n") > hfile
104
105         next
106 }
107 NF > 0 && $1 == "product" {
108         nproducts++
109
110         products[nproducts, 1] = $2;            # vendor name
111         products[nproducts, 2] = $3;            # product id
112         products[nproducts, 3] = $4;            # id
113         printf("#define\tPCI_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
114             products[nproducts, 2], products[nproducts, 3]) > hfile
115
116         i=4; f = 5;
117
118         # comments
119         ocomment = oparen = 0
120         if (f <= NF) {
121                 printf("\t/* ") > hfile
122                 ocomment = 1;
123         }
124         while (f <= NF) {
125                 if ($f == "#") {
126                         printf("(") > hfile
127                         oparen = 1
128                         f++
129                         continue
130                 }
131                 if (oparen) {
132                         printf("%s", $f) > hfile
133                         if (f < NF)
134                                 printf(" ") > hfile
135                         f++
136                         continue
137                 }
138                 products[nproducts, i] = $f
139                 printf("%s", products[nproducts, i]) > hfile
140                 if (f < NF)
141                         printf(" ") > hfile
142                 i++; f++;
143         }
144         if (oparen)
145                 printf(")") > hfile
146         if (ocomment)
147                 printf(" */") > hfile
148         printf("\n") > hfile
149
150         next
151 }
152 {
153         if ($0 == "")
154                 blanklines++
155         print $0 > hfile
156         if (blanklines < 2)
157                 print $0 > dfile
158 }
159 END {
160         # print out the match tables
161
162         printf("\n") > dfile
163
164         printf("const struct pci_knowndev pci_knowndevs[] = {\n") > dfile
165         for (i = 1; i <= nproducts; i++) {
166                 printf("\t{\n") > dfile
167                 printf("\t    PCI_VENDOR_%s, PCI_PRODUCT_%s_%s,\n",
168                     products[i, 1], products[i, 1], products[i, 2]) \
169                     > dfile
170                 printf("\t    ") > dfile
171                 printf("0") > dfile
172                 printf(",\n") > dfile
173
174                 vendi = vendorindex[products[i, 1]];
175                 printf("\t    \"") > dfile
176                 j = 3;
177                 needspace = 0;
178                 while ((vendi, j) in vendors) {
179                         if (needspace)
180                                 printf(" ") > dfile
181                         printf("%s", vendors[vendi, j]) > dfile
182                         needspace = 1
183                         j++
184                 }
185                 printf("\",\n") > dfile
186
187                 printf("\t    \"") > dfile
188                 j = 4;
189                 needspace = 0;
190                 while ((i, j) in products) {
191                         if (needspace)
192                                 printf(" ") > dfile
193                         printf("%s", products[i, j]) > dfile
194                         needspace = 1
195                         j++
196                 }
197                 printf("\",\n") > dfile
198                 printf("\t},\n") > dfile
199         }
200         for (i = 1; i <= nvendors; i++) {
201                 printf("\t{\n") > dfile
202                 printf("\t    PCI_VENDOR_%s, 0,\n", vendors[i, 1]) \
203                     > dfile
204                 printf("\t    PCI_KNOWNDEV_NOPROD,\n") \
205                     > dfile
206                 printf("\t    \"") > dfile
207                 j = 3;
208                 needspace = 0;
209                 while ((i, j) in vendors) {
210                         if (needspace)
211                                 printf(" ") > dfile
212                         printf("%s", vendors[i, j]) > dfile
213                         needspace = 1
214                         j++
215                 }
216                 printf("\",\n") > dfile
217                 printf("\t    NULL,\n") > dfile
218                 printf("\t},\n") > dfile
219         }
220         printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
221         printf("};\n") > dfile
222         close(dfile)
223         close(hfile)
224 }