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