#!/usr/bin/perl

# Frank Gruellich <frank@der-frank.org>

# filters fvwm2rc.keys2nd to HTML

use warnings;
use strict;

my $file	= shift || die "Keine Datei angegeben.";
open(my $fh, "<$file") or die "Kann Datei nicht oeffnen.";
my @lines	= <$fh>;
my $output	= '';
print <<EOF;
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<meta name="generator" content="perl" />
		<title>Fvwm2 Key Help</title>
	</head>
	<body>
		<h1>General Keys</h1>
		<kbd>Escape</kbd>: Cancel<br />
		<kbd>?</kbd>: Show this help screen<br />
EOF

for my $line (@lines)
{
	if( $line =~ /^#### (.*)$/ )
	{
		$output = "<h1>$1</h1>\n";
	} elsif( $line =~ /^### (.*)$/ )
	{
		$output = "<h2>$1</h2>\n";
	} elsif( $line =~ /^(\S+)\s+(\S+)\s+\S+\s+(\S+)\s+.*##\s+(.*)$/ )
	{
		if ( $3 eq "N" )
		{
			$output = "<kbd>$2</kbd>: $4<br />\n";
		} else
		{
			$output = "<kbd>$3-$2</kbd>: $4<br />\n";
		}
	}
	print $output; $output='';
}

print "	</body>\n</html>\n";
