1 #! /usr/bin/awk -f
2 # $NetBSD: devlist2h.awk,v 1.9 2005/12/11 12:21:20 christos Exp $
3 # $FreeBSD$
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="ediddevs_data.h"
36 hfile="ediddevs.h"
37 }
38 NR == 1 {
39 VERSION = $0
40 gsub("\\$", "", VERSION)
41 gsub(/ $/, "", VERSION)
42
43 printf("/*\t$FreeBSD" "$\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
51
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
60
61 next
62 }
63
64 NF > 0 && $1 == "vendor" {
65 nvendors++
66
67 vendorindex[$2] = nvendors; # record index for this name, for later.
68 vendors[nvendors, 1] = $2; # name/ID
69 i = 2; f = 3;
70
71 printf("#define\tEDID_VENDOR_%s\t\"", vendors[nvendors, 1]) > hfile
72
73 # comments
74 oparen = 0
75 while (f <= NF) {
76 if ($f == "#") {
77 printf("(") > hfile
78 oparen = 1
79 f++
80 continue
81 }
82 if (oparen) {
83 printf("%s", $f) > hfile
84 f++
85 continue
86 }
87 vendors[nvendors, i] = $f
88 printf("%s", vendors[nvendors, i]) > hfile
89 if (f < NF)
90 printf(" ") > hfile
91 i++; f++;
92 }
93 if (oparen)
94 printf(")") > hfile
95 printf("\"") > hfile
96 printf("\n") > hfile
97
98 next
99 }
100
101 NF > 0 && $1 == "product" {
102 nproducts++
103
104 products[nproducts, 1] = $2; # vendor name
105 products[nproducts, 2] = $3; # product id
106 products[nproducts, 3] = $4; # id
107 printf("#define\tEDID_PRODUCT_%s_%s\t%s", products[nproducts, 1],
108 products[nproducts, 2], products[nproducts, 3]) > hfile
109
110 i = 4; f = 5;
111
112 ocomment = oparen = 0
113 if (f <= NF) {
114 printf("\t\t/* ") > hfile
115 ocomment = 1;
116 }
117 while (f <= NF) {
118 if ($f == "#") {
119 printf("(") > hfile
120 oparen = 1
121 f++
122 continue
123 }
124 if (oparen) {
125 printf("%s", $f) > hfile
126 if (f < NF)
127 printf(" ") > hfile
128 f++
129 continue
130 }
131 products[nproducts, i] = $f
132 printf("%s", products[nproducts, i]) > hfile
133 if (f < NF)
134 printf(" ") > hfile
135 i++; f++;
136 }
137 if (oparen)
138 printf(")") > hfile
139 if (ocomment)
140 printf(" */") > hfile
141 printf("\n") > hfile
142
143 next
144 }
145 {
146 if ($0 == "")
147 blanklines++
148 if (blanklines != 2 && blanklines != 3)
149 print $0 > hfile
150 if (blanklines < 2)
151 print $0 > dfile
152 }
153 END {
154 # print out the match tables
155
156 printf("\n") > dfile
157 printf("const struct edid_vendor edid_vendors[] = {\n") > dfile
158
159 for (i = 1; i <= nvendors; i++) {
160 printf("\t{") > dfile
161 printf(" \"%s\", EDID_VENDOR_%s", vendors[i, 1], \
162 vendors[i, 1]) > dfile
163 printf(" },\n") > dfile
164 }
165 printf("};\n") > dfile
166 printf("const int edid_nvendors = %d;\n", nvendors) > dfile
167
168 printf("\n") > dfile
169
170 printf("const struct edid_product edid_products[] = {\n") > dfile
171 for (i = 1; i <= nproducts; i++) {
172 printf("\t{\n") > dfile
173 printf("\t \"%s\", EDID_PRODUCT_%s_%s,\n", \
174 products[i, 1], products[i, 1], products[i, 2]) > dfile
175 printf("\t \"") > dfile
176 j = 4
177 needspace = 0
178 while ((i, j) in products) {
179 if (needspace)
180 printf(" ") > dfile
181 printf("%s", products[i, j]) > dfile
182 needspace = 1
183 j++
184 }
185 printf("\",\n") > dfile
186 printf("\t},\n") > dfile
187 }
188 printf("};\n") > dfile
189 printf("const int edid_nproducts = %d;\n", nproducts) >dfile
190
191 close(dfile)
192 close(hfile)
193 }
Cache object: 02ea4bef3fcafcd6e2946191d044c186
|