1278798Shselasky#! /usr/bin/awk -f
2278798Shselasky#	$NetBSD: devlist2h.awk,v 1.9 2005/12/11 12:21:20 christos Exp $
3278798Shselasky#	$FreeBSD: releng/11.0/sys/dev/videomode/devlist2h.awk 278798 2015-02-15 11:37:40Z hselasky $
4278798Shselasky#
5278798Shselasky# Copyright (c) 1995, 1996 Christopher G. Demetriou
6278798Shselasky# All rights reserved.
7278798Shselasky#
8278798Shselasky# Redistribution and use in source and binary forms, with or without
9278798Shselasky# modification, are permitted provided that the following conditions
10278798Shselasky# are met:
11278798Shselasky# 1. Redistributions of source code must retain the above copyright
12278798Shselasky#    notice, this list of conditions and the following disclaimer.
13278798Shselasky# 2. Redistributions in binary form must reproduce the above copyright
14278798Shselasky#    notice, this list of conditions and the following disclaimer in the
15278798Shselasky#    documentation and/or other materials provided with the distribution.
16278798Shselasky# 3. All advertising materials mentioning features or use of this software
17278798Shselasky#    must display the following acknowledgement:
18278798Shselasky#      This product includes software developed by Christopher G. Demetriou.
19278798Shselasky# 4. The name of the author may not be used to endorse or promote products
20278798Shselasky#    derived from this software without specific prior written permission
21278798Shselasky#
22278798Shselasky# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23278798Shselasky# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24278798Shselasky# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25278798Shselasky# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26278798Shselasky# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27278798Shselasky# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28278798Shselasky# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29278798Shselasky# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30278798Shselasky# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31278798Shselasky# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32278798Shselasky#
33278798ShselaskyBEGIN {
34278798Shselasky	nproducts = nvendors = blanklines = 0
35278798Shselasky	dfile="ediddevs_data.h"
36278798Shselasky	hfile="ediddevs.h"
37278798Shselasky}
38278798ShselaskyNR == 1 {
39278798Shselasky	VERSION = $0
40278798Shselasky	gsub("\\$", "", VERSION)
41278798Shselasky	gsub(/ $/, "", VERSION)
42278798Shselasky
43278798Shselasky	printf("/*\t$FreeBSD" "$\t*/\n\n") > dfile
44278798Shselasky	printf("/*\n") > dfile
45278798Shselasky	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
46278798Shselasky	    > dfile
47278798Shselasky	printf(" *\n") > dfile
48278798Shselasky	printf(" * generated from:\n") > dfile
49278798Shselasky	printf(" *\t%s\n", VERSION) > dfile
50278798Shselasky	printf(" */\n") > dfile
51278798Shselasky
52278798Shselasky	printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
53278798Shselasky	printf("/*\n") > hfile
54278798Shselasky	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
55278798Shselasky	    > hfile
56278798Shselasky	printf(" *\n") > hfile
57278798Shselasky	printf(" * generated from:\n") > hfile
58278798Shselasky	printf(" *\t%s\n", VERSION) > hfile
59278798Shselasky	printf(" */\n") > hfile
60278798Shselasky
61278798Shselasky	next
62278798Shselasky}
63278798Shselasky
64278798ShselaskyNF > 0 && $1 == "vendor" {
65278798Shselasky	nvendors++
66278798Shselasky
67278798Shselasky	vendorindex[$2] = nvendors;	# record index for this name, for later.
68278798Shselasky	vendors[nvendors, 1] = $2;	# name/ID
69278798Shselasky	i = 2; f = 3;
70278798Shselasky
71278798Shselasky	printf("#define\tEDID_VENDOR_%s\t\"", vendors[nvendors, 1]) > hfile
72278798Shselasky
73278798Shselasky	# comments
74278798Shselasky	oparen = 0
75278798Shselasky	while (f <= NF) {
76278798Shselasky		if ($f == "#") {
77278798Shselasky			printf("(") > hfile
78278798Shselasky			oparen = 1
79278798Shselasky			f++
80278798Shselasky			continue
81278798Shselasky		}
82278798Shselasky		if (oparen) {
83278798Shselasky			printf("%s", $f) > hfile
84278798Shselasky			f++
85278798Shselasky			continue
86278798Shselasky		}
87278798Shselasky		vendors[nvendors, i] = $f
88278798Shselasky		printf("%s", vendors[nvendors, i]) > hfile
89278798Shselasky		if (f < NF)
90278798Shselasky			printf(" ") > hfile
91278798Shselasky		i++; f++;
92278798Shselasky	}
93278798Shselasky	if (oparen)
94278798Shselasky		printf(")") > hfile
95278798Shselasky	printf("\"") > hfile
96278798Shselasky	printf("\n") > hfile
97278798Shselasky
98278798Shselasky	next
99278798Shselasky}
100278798Shselasky
101278798ShselaskyNF > 0 && $1 == "product" {
102278798Shselasky	nproducts++
103278798Shselasky
104278798Shselasky	products[nproducts, 1] = $2;		# vendor name
105278798Shselasky	products[nproducts, 2] = $3;		# product id
106278798Shselasky	products[nproducts, 3] = $4;		# id
107278798Shselasky	printf("#define\tEDID_PRODUCT_%s_%s\t%s", products[nproducts, 1],
108278798Shselasky	    products[nproducts, 2], products[nproducts, 3]) > hfile
109278798Shselasky
110278798Shselasky	i = 4; f = 5;
111278798Shselasky	
112278798Shselasky	ocomment = oparen = 0
113278798Shselasky	if (f <= NF) {
114278798Shselasky		printf("\t\t/* ") > hfile
115278798Shselasky		ocomment = 1;
116278798Shselasky	}
117278798Shselasky	while (f <= NF) {
118278798Shselasky		if ($f == "#") {
119278798Shselasky			printf("(") > hfile
120278798Shselasky			oparen = 1
121278798Shselasky			f++
122278798Shselasky			continue
123278798Shselasky		}
124278798Shselasky		if (oparen) {
125278798Shselasky			printf("%s", $f) > hfile
126278798Shselasky			if (f < NF)
127278798Shselasky				printf(" ") > hfile
128278798Shselasky			f++
129278798Shselasky			continue
130278798Shselasky		}
131278798Shselasky		products[nproducts, i] = $f
132278798Shselasky		printf("%s", products[nproducts, i]) > hfile
133278798Shselasky		if (f < NF)
134278798Shselasky			printf(" ") > hfile
135278798Shselasky		i++; f++;
136278798Shselasky	}
137278798Shselasky	if (oparen)
138278798Shselasky		printf(")") > hfile
139278798Shselasky	if (ocomment)
140278798Shselasky		printf(" */") > hfile
141278798Shselasky	printf("\n") > hfile
142278798Shselasky
143278798Shselasky	next
144278798Shselasky}
145278798Shselasky{
146278798Shselasky	if ($0 == "")
147278798Shselasky		blanklines++
148278798Shselasky	if (blanklines != 2 && blanklines != 3)
149278798Shselasky		print $0 > hfile
150278798Shselasky	if (blanklines < 2)
151278798Shselasky		print $0 > dfile
152278798Shselasky}
153278798ShselaskyEND {
154278798Shselasky	# print out the match tables
155278798Shselasky
156278798Shselasky	printf("\n") > dfile
157278798Shselasky	printf("const struct edid_vendor edid_vendors[] = {\n") > dfile
158278798Shselasky
159278798Shselasky	for (i = 1; i <= nvendors; i++) {
160278798Shselasky		printf("\t{") > dfile
161278798Shselasky		printf(" \"%s\", EDID_VENDOR_%s", vendors[i, 1], \
162278798Shselasky		    vendors[i, 1]) > dfile
163278798Shselasky		printf(" },\n") > dfile
164278798Shselasky	}
165278798Shselasky	printf("};\n") > dfile
166278798Shselasky	printf("const int edid_nvendors = %d;\n", nvendors) > dfile
167278798Shselasky
168278798Shselasky	printf("\n") > dfile
169278798Shselasky
170278798Shselasky	printf("const struct edid_product edid_products[] = {\n") > dfile
171278798Shselasky	for (i = 1; i <= nproducts; i++) {
172278798Shselasky		printf("\t{\n") > dfile
173278798Shselasky		printf("\t    \"%s\", EDID_PRODUCT_%s_%s,\n", \
174278798Shselasky		    products[i, 1], products[i, 1], products[i, 2]) > dfile
175278798Shselasky		printf("\t    \"") > dfile
176278798Shselasky		j = 4
177278798Shselasky		needspace = 0
178278798Shselasky		while ((i, j) in products) {
179278798Shselasky			if (needspace)
180278798Shselasky				printf(" ") > dfile
181278798Shselasky			printf("%s", products[i, j]) > dfile
182278798Shselasky			needspace = 1
183278798Shselasky			j++
184278798Shselasky		}
185278798Shselasky		printf("\",\n") > dfile
186278798Shselasky		printf("\t},\n") > dfile
187278798Shselasky	}
188278798Shselasky	printf("};\n") > dfile
189278798Shselasky	printf("const int edid_nproducts = %d;\n", nproducts) >dfile
190278798Shselasky
191278798Shselasky	close(dfile)
192278798Shselasky	close(hfile)
193278798Shselasky}
194