xref: /freebsd/sys/dev/videomode/devlist2h.awk (revision 4f8f43b06ed07e96a250855488cc531799d5b78f)
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("/*\n") > dfile
43	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
44	    > dfile
45	printf(" *\n") > dfile
46	printf(" * generated from:\n") > dfile
47	printf(" *\t%s\n", VERSION) > dfile
48	printf(" */\n") > dfile
49
50	printf("/*\n") > hfile
51	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
52	    > hfile
53	printf(" *\n") > hfile
54	printf(" * generated from:\n") > hfile
55	printf(" *\t%s\n", VERSION) > hfile
56	printf(" */\n") > hfile
57
58	next
59}
60
61NF > 0 && $1 == "vendor" {
62	nvendors++
63
64	vendorindex[$2] = nvendors;	# record index for this name, for later.
65	vendors[nvendors, 1] = $2;	# name/ID
66	i = 2; f = 3;
67
68	printf("#define\tEDID_VENDOR_%s\t\"", vendors[nvendors, 1]) > hfile
69
70	# comments
71	oparen = 0
72	while (f <= NF) {
73		if ($f == "#") {
74			printf("(") > hfile
75			oparen = 1
76			f++
77			continue
78		}
79		if (oparen) {
80			printf("%s", $f) > hfile
81			f++
82			continue
83		}
84		vendors[nvendors, i] = $f
85		printf("%s", vendors[nvendors, i]) > hfile
86		if (f < NF)
87			printf(" ") > hfile
88		i++; f++;
89	}
90	if (oparen)
91		printf(")") > hfile
92	printf("\"") > hfile
93	printf("\n") > hfile
94
95	next
96}
97
98NF > 0 && $1 == "product" {
99	nproducts++
100
101	products[nproducts, 1] = $2;		# vendor name
102	products[nproducts, 2] = $3;		# product id
103	products[nproducts, 3] = $4;		# id
104	printf("#define\tEDID_PRODUCT_%s_%s\t%s", products[nproducts, 1],
105	    products[nproducts, 2], products[nproducts, 3]) > hfile
106
107	i = 4; f = 5;
108
109	ocomment = oparen = 0
110	if (f <= NF) {
111		printf("\t\t/* ") > hfile
112		ocomment = 1;
113	}
114	while (f <= NF) {
115		if ($f == "#") {
116			printf("(") > hfile
117			oparen = 1
118			f++
119			continue
120		}
121		if (oparen) {
122			printf("%s", $f) > hfile
123			if (f < NF)
124				printf(" ") > hfile
125			f++
126			continue
127		}
128		products[nproducts, i] = $f
129		printf("%s", products[nproducts, i]) > hfile
130		if (f < NF)
131			printf(" ") > hfile
132		i++; f++;
133	}
134	if (oparen)
135		printf(")") > hfile
136	if (ocomment)
137		printf(" */") > hfile
138	printf("\n") > hfile
139
140	next
141}
142{
143	if ($0 == "")
144		blanklines++
145	if (blanklines != 2 && blanklines != 3)
146		print $0 > hfile
147	if (blanklines < 2)
148		print $0 > dfile
149}
150END {
151	# print out the match tables
152
153	printf("\n") > dfile
154	printf("const struct edid_vendor edid_vendors[] = {\n") > dfile
155
156	for (i = 1; i <= nvendors; i++) {
157		printf("\t{") > dfile
158		printf(" \"%s\", EDID_VENDOR_%s", vendors[i, 1], \
159		    vendors[i, 1]) > dfile
160		printf(" },\n") > dfile
161	}
162	printf("};\n") > dfile
163	printf("const int edid_nvendors = %d;\n", nvendors) > dfile
164
165	printf("\n") > dfile
166
167	printf("const struct edid_product edid_products[] = {\n") > dfile
168	for (i = 1; i <= nproducts; i++) {
169		printf("\t{\n") > dfile
170		printf("\t    \"%s\", EDID_PRODUCT_%s_%s,\n", \
171		    products[i, 1], products[i, 1], products[i, 2]) > dfile
172		printf("\t    \"") > dfile
173		j = 4
174		needspace = 0
175		while ((i, j) in products) {
176			if (needspace)
177				printf(" ") > dfile
178			printf("%s", products[i, j]) > dfile
179			needspace = 1
180			j++
181		}
182		printf("\",\n") > dfile
183		printf("\t},\n") > dfile
184	}
185	printf("};\n") > dfile
186	printf("const int edid_nproducts = %d;\n", nproducts) >dfile
187
188	close(dfile)
189	close(hfile)
190}
191