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