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