Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / devlist2h.awk
blob2738c4d8aa20e63ff1d06e2f5a06cef98f9940bb
1 #! /usr/bin/awk -f
2 # $NetBSD: devlist2h.awk,v 1.12 2005/12/11 12:22:49 christos Exp $
4 # Copyright (c) 1995, 1996 Christopher G. Demetriou
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. All advertising materials mentioning features or use of this software
16 # must display the following acknowledgement:
17 # This product includes software developed by Christopher G. Demetriou.
18 # 4. The name of the author may not be used to endorse or promote products
19 # derived from this software without specific prior written permission
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 BEGIN {
33 nproducts = nvendors = blanklines = 0
34 nchars = 1
35 dfile="pcidevs_data.h"
36 hfile="pcidevs.h"
38 NR == 1 {
39 VERSION = $0
40 gsub("\\$", "", VERSION)
41 gsub(/ $/, "", VERSION)
43 printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
44 printf("/*\n") > dfile
45 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
46 > dfile
47 printf(" *\n") > dfile
48 printf(" * generated from:\n") > dfile
49 printf(" *\t%s\n", VERSION) > dfile
50 printf(" */\n") > dfile
52 printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
53 printf("/*\n") > hfile
54 printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
55 > hfile
56 printf(" *\n") > hfile
57 printf(" * generated from:\n") > hfile
58 printf(" *\t%s\n", VERSION) > hfile
59 printf(" */\n") > hfile
61 next
63 NF > 0 && $1 == "vendor" {
64 nvendors++
66 vendorindex[$2] = nvendors; # record index for this name, for later.
67 vendors[nvendors, 1] = $2; # name
68 vendors[nvendors, 2] = $3; # id
69 printf("#define\tPCI_VENDOR_%s\t%s", vendors[nvendors, 1],
70 vendors[nvendors, 2]) > hfile
72 i = 3; f = 4;
74 # comments
75 ocomment = oparen = 0
76 if (f <= NF) {
77 printf("\t\t/* ") > hfile
78 ocomment = 1;
80 while (f <= NF) {
81 if ($f == "#") {
82 printf("(") > hfile
83 oparen = 1
84 f++
85 continue
87 if (oparen) {
88 printf("%s", $f) > hfile
89 if (f < NF)
90 printf(" ") > hfile
91 f++
92 continue
94 vendors[nvendors, i] = $f
95 if (words[$f, 1] == 0) {
96 l = length($f);
97 parts = split($f, junk, "\\");
98 l = l - (parts - 1);
99 nwords++;
100 words[$f, 1] = nwords;
101 words[$f, 2] = l;
102 wordlist[nwords, 1] = $f;
103 wordlist[nwords, 3] = nchars;
104 nchars = nchars + l + 1;
106 wordlist[words[$f, 1], 2]++;
107 vendors[nvendors, i] = words[$f, 1];
108 printf("%s", $f) > hfile
109 if (f < NF)
110 printf(" ") > hfile
111 i++; f++;
113 if (oparen)
114 printf(")") > hfile
115 if (ocomment)
116 printf(" */") > hfile
117 printf("\n") > hfile
119 next
121 NF > 0 && $1 == "product" {
122 nproducts++
124 products[nproducts, 1] = $2; # vendor name
125 products[nproducts, 2] = $3; # product id
126 products[nproducts, 3] = $4; # id
127 printf("#define\tPCI_PRODUCT_%s_%s\t%s", products[nproducts, 1],
128 products[nproducts, 2], products[nproducts, 3]) > hfile
130 i=4; f = 5;
132 # comments
133 ocomment = oparen = 0
134 if (f <= NF) {
135 printf("\t\t/* ") > hfile
136 ocomment = 1;
138 while (f <= NF) {
139 if ($f == "#") {
140 printf("(") > hfile
141 oparen = 1
143 continue
145 if (oparen) {
146 printf("%s", $f) > hfile
147 if (f < NF)
148 printf(" ") > hfile
150 continue
152 if (words[$f, 1] == 0) {
153 l = length($f);
154 parts = split($f, junk, "\\");
155 l = l - (parts - 1);
156 nwords++;
157 words[$f, 2] = l;
158 words[$f, 1] = nwords;
159 wordlist[nwords, 1] = $f;
160 wordlist[nwords, 3] = nchars;
161 nchars = nchars + l + 1;
163 wordlist[words[$f, 1], 2]++;
164 products[nproducts, i] = words[$f, 1];
165 printf("%s", $f) > hfile
166 if (f < NF)
167 printf(" ") > hfile
168 i++; f++;
170 if (oparen)
171 printf(")") > hfile
172 if (ocomment)
173 printf(" */") > hfile
174 printf("\n") > hfile
176 next
179 if ($0 == "")
180 blanklines++
181 print $0 > hfile
182 if (blanklines < 2)
183 print $0 > dfile
185 END {
186 # print out the match tables
188 printf("\n") > dfile
190 printf("static const uint16_t pci_vendors[] = {\n") > dfile
191 for (i = 1; i <= nvendors; i++) {
192 printf("\t PCI_VENDOR_%s", vendors[i, 1]) \
193 > dfile
195 j = 3;
196 while ((i, j) in vendors) {
197 printf(", %d",
198 wordlist[vendors[i, j], 3]) > dfile
199 # printf(", %d /* %s */",
200 # wordlist[vendors[i, j], 3],
201 # wordlist[vendors[i, j], 1]) > dfile
204 printf(", 0,\n", sep) > dfile
206 printf("};\n") > dfile
208 printf("\n") > dfile
210 printf("static const uint16_t pci_products[] = {\n") > dfile
211 for (i = 1; i <= nproducts; i++) {
212 printf("\t PCI_VENDOR_%s, PCI_PRODUCT_%s_%s, \n",
213 products[i, 1], products[i, 1], products[i, 2]) \
214 > dfile
216 printf("\t ") > dfile
217 j = 4
218 sep = ""
219 while ((i, j) in products) {
220 printf("%s%d", sep,
221 wordlist[products[i, j], 3]) > dfile
222 # printf("%s%d /* %s */", sep,
223 # wordlist[products[i, j], 3],
224 # wordlist[products[i, j], 1]) > dfile
225 sep = ", "
228 printf("%s0,\n", sep) > dfile
230 printf("};\n") > dfile
232 printf("static const char pci_words[] = { \".\" \n") > dfile
233 for (i = 1; i <= nwords; i++) {
234 printf("\t \"%s\\0\" /* %d refs @ %d */\n",
235 wordlist[i, 1], wordlist[i, 2], wordlist[i, 3]) > dfile
237 printf("};\n") > dfile
238 printf("const int pci_nwords = %d;\n", nwords) > dfile
240 printf("\n") > dfile
242 close(dfile)
243 close(hfile)