1706f2543Smrg#!/usr/bin/awk -f
2706f2543Smrg#
3706f2543Smrg# Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
4706f2543Smrg# All rights reserved.
5706f2543Smrg#
6706f2543Smrg# Based on Perl script by Dirk Hohndel.
7706f2543Smrg#
8706f2543Smrg# Redistribution and use in source and binary forms, with or without
9706f2543Smrg# modification, are permitted provided that the following conditions
10706f2543Smrg# are met:
11706f2543Smrg#
12706f2543Smrg# 1. Redistributions of source code must retain the above copyright
13706f2543Smrg#    notice, this list of conditions and the following disclaimer.
14706f2543Smrg# 2. Redistributions in binary form must reproduce the above copyright
15706f2543Smrg#    notice, this list of conditions and the following disclaimer in
16706f2543Smrg#    the documentation and/or other materials provided with the
17706f2543Smrg#    distribution.
18706f2543Smrg#
19706f2543Smrg# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20706f2543Smrg# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21706f2543Smrg# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22706f2543Smrg# FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
23706f2543Smrg# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24706f2543Smrg# INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
25706f2543Smrg# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26706f2543Smrg# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27706f2543Smrg# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28706f2543Smrg# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29706f2543Smrg# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30706f2543Smrg# SUCH DAMAGE.
31706f2543Smrg#
32706f2543Smrg# Usage: modeline2c.awk < modefile > xf86DefModeSet.c
33706f2543Smrg#
34706f2543Smrg
35706f2543SmrgBEGIN {
36706f2543Smrg	flagsdict[""] = "0"
37706f2543Smrg
38706f2543Smrg	flagsdict["+hsync +vsync"] = "V_PHSYNC | V_PVSYNC"
39706f2543Smrg	flagsdict["+hsync -vsync"] = "V_PHSYNC | V_NVSYNC"
40706f2543Smrg	flagsdict["-hsync +vsync"] = "V_NHSYNC | V_PVSYNC"
41706f2543Smrg	flagsdict["-hsync -vsync"] = "V_NHSYNC | V_NVSYNC"
42706f2543Smrg	flagsdict["+hsync +vsync interlace"] = "V_PHSYNC | V_PVSYNC | V_INTERLACE"
43706f2543Smrg	flagsdict["+hsync -vsync interlace"] = "V_PHSYNC | V_NVSYNC | V_INTERLACE"
44706f2543Smrg	flagsdict["-hsync +vsync interlace"] = "V_NHSYNC | V_PVSYNC | V_INTERLACE"
45706f2543Smrg	flagsdict["-hsync -vsync interlace"] = "V_NHSYNC | V_NVSYNC | V_INTERLACE"
46706f2543Smrg
47706f2543Smrg	print "/* THIS FILE IS AUTOMATICALLY GENERATED -- DO NOT EDIT -- LOOK at"
48706f2543Smrg	print " * modeline2c.awk */"
49706f2543Smrg	print ""
50706f2543Smrg	print "/*"
51706f2543Smrg	print " * Author: Joerg Sonnenberger <joerg@NetBSD.org>"
52706f2543Smrg	print " * Based on Perl script from Dirk Hohndel <hohndel@XFree86.Org>"
53706f2543Smrg	print " */"
54706f2543Smrg	print ""
55706f2543Smrg	print "#ifdef HAVE_XORG_CONFIG_H"
56706f2543Smrg	print "#include <xorg-config.h>"
57706f2543Smrg	print "#endif"
58706f2543Smrg	print ""
59706f2543Smrg	print "#include \"xf86.h\""
60706f2543Smrg	print "#include \"xf86Config.h\""
61706f2543Smrg	print "#include \"xf86Priv.h\""
62706f2543Smrg	print "#include \"xf86_OSlib.h\""
63706f2543Smrg	print ""
64706f2543Smrg	print "#include \"globals.h\""
65706f2543Smrg	print ""
66706f2543Smrg	print "#define MODEPREFIX NULL, NULL, NULL, MODE_OK, M_T_DEFAULT"
67706f2543Smrg	print "#define MODESUFFIX 0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0"
68706f2543Smrg	print ""
69706f2543Smrg	print "const DisplayModeRec xf86DefaultModes [] = {"
70706f2543Smrg
71706f2543Smrg	modeline = "\t{MODEPREFIX,%d, %d,%d,%d,%d,0, %d,%d,%d,%d,0, %s, MODESUFFIX},\n"
72706f2543Smrg	modeline_data = "^[a-zA-Z]+[ \t]+[^ \t]+[ \t0-9.]+"
73706f2543Smrg}
74706f2543Smrg
75706f2543Smrg/^[mM][oO][dD][eE][lL][iI][nN][eE]/ {
76706f2543Smrg	flags = $0
77706f2543Smrg	gsub(modeline_data, "", flags)
78706f2543Smrg	flags = tolower(flags)
79706f2543Smrg	printf(modeline, $3 * 1000, $4, $5, $6, $7,
80706f2543Smrg	       $8, $9, $10, $11, flagsdict[flags])
81706f2543Smrg	# Half-width double scanned modes
82706f2543Smrg	printf(modeline, $3 * 500, $4/2, $5/2, $6/2, $7/2,
83706f2543Smrg	       $8/2, $9/2, $10/2, $11/2, flagsdict[flags] " | V_DBLSCAN")
84706f2543Smrg}
85706f2543Smrg
86706f2543Smrg/^#/ {
87706f2543Smrg	print "/*" substr($0, 2) " */"
88706f2543Smrg}
89706f2543Smrg
90706f2543SmrgEND {
91706f2543Smrg	print "};"
92706f2543Smrg	printf "const int xf86NumDefaultModes = sizeof(xf86DefaultModes) / sizeof(DisplayModeRec);"
93706f2543Smrg}
94