#!/usr/bin/perl -l

print  q{<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="./docbook-complete.css" type="text/css"?>

<article><title>Speedly Keymap</title><table><title>Key bindings</title><tgroup  cols="4"><thead><row><entry>Action</entry><entry>Keycombo</entry><entry>Action</entry><entry>Keycombo</entry></row></thead>
<tbody>
};


$doublecol = $ARGV[0] || 0;

sub convertKeybindName {
    my ($name) = @_;
    return $name;
}

sub convertKeybind {
    my ($bind) = @_;
    return $bind;
}

while (<STDIN>) {
s|^\s*(\w+)\s*|| and $keybindName = convertKeybindName($1);
while (s/(\w+(\(\d+\))?)//) {
    $keybind .= convertKeybind($1) . " ";
}

chop($keybind);
if ($doublecol and not defined $firstcol) {
    $firstcol = "<entry>$keybindName</entry>" . 
	"<entry>$keybind</entry>";
    next;
}

print "<row>";
print "\t$firstcol<entry>$keybindName</entry><entry>$keybind</entry>";
print "</row>";

undef $keybind;
undef $keybindName;
undef $firstcol;
}

print q{</tbody></tgroup> </table>
</article>
};


