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