gale client

root / gen_keyhelp.prl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl -w

use strict;
use Getopt::Std;
use IO::File;
use Data::Dumper;

my %o;
my %cm;
my @hs;
getopts('hc:',\%o) || die "bad options";

$o{c} ||= "ginsu.config.sample";

sub newsection ($) {
    if ($o{h}) {
        push @hs, "Left \"$_[0]\"";
    } else {
        print "|||||| <b><i>$_[0]</i></b> ||\n";
    }
}

sub key ($$) {
    my $d = $_[1] || $_[0];
    $d =~ tr/_/ /;
    if ($o{h}) {
        push @hs, "Right (gk \"$_[0]\", \"$d\")"
    } else {
        my $dk = join ", ", @{$cm{$_[0]}};
        print "||$_[0]|| $dk ||$d||\n";
    }
}

sub spkey ($$$) {
    my $d = $_[2] || $_[0];
    $d =~ tr/_/ /;
    my $dk = $_[1];
    if ($o{h}) {
        push @hs, "Right (\"$_[1]\", \"$d\")"
    } else {
        print "||$_[0]|| $dk ||$d||\n";
    }
}

if (!$o{h}) {

    my $cfd = new IO::File "<$o{c}" || die "open: $!";

    while (<$cfd>) {
        next unless /^bind\s+(\S+)\s+(\w+)\s*$/;
        push @{$cm{$2}}, $1;
    }

}



print "|| <b>Action Name</b> || <b>Default Key</b> || <b>Description</b> ||\n" unless $o{h};

print "module KeyHelpTable(keyHelpTable) where\n\n" if $o{h};
print "keyHelpTable gk = [\n" if $o{h};

while (<>) {
    next if /^\s*(\#.*)?\s*$/;
    newsection($1),next if /^\@(.*?)\s*$/;
    spkey($1, $2, $3),next if /^\%(\w*)\s+(\S+)\s*(.+?)?\s*$/;
    key($1, $2),next if /^(\w*)\s*(.+?)?\s*$/;
}

print "         ", join("\n        ,", @hs), "\n";

print "        ]\n" if $o{h};