summaryrefslogtreecommitdiffstats
path: root/doc/gen-map-doc
blob: 2c424943d753c7d0433024e0b05aecf95e215c3b (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/perl -w

use strict;

my (%OPS, %MAP, %DOC, $map);

my $xml = shift @ARGV;

open F, "cat @ARGV |" or die "OPS*: $!";
while (<F>) {
  next if /^\/\*/;
  /(\w+) "(.+)"/ or die "$.: parse error";
  $OPS{$1} = $2;
}
close F;

while (<STDIN>) {
  if (/^const struct binding_t Op.*{ \/\* map: (.*) \*\//) {
    $map = $1;
    $DOC{$map} = "";
  }
  if ($map and /^\s*\*\*\s*(.*)/) {
    $DOC{$map} .= "$1\n";
  }
  if ($map and /{\s*"(.+)"\s*,\s*(\w+)\s*,\s*(?:"([^"]+)"|(\w+))\s*}/) {
    my ($function, $op, $binding) = ($1, $2, $3 || $4);
    $binding =~ s/&/&amp;/;
    # for <key>, try CamelCasing into <Key>
    $binding =~ s/<(.)(.+)>/&lt;\U$1\E$2&gt;/;
    $binding =~ s/</&lt;/;
    $binding =~ s/>/&gt;/;
    $binding =~ s/ /&lt;Space&gt;/;
    $binding =~ s/^\\033/Esc /;
    $binding =~ s/^\\010/&lt;Backspace&gt;/;
    $binding =~ s/^\\(0\d+)$/'^'.chr(64+oct($1))/e;
    $binding =~ s/^\\(0\d+)(.)/'^'.chr(64+oct($1)) ." $2"/e;
    $binding =~ s/\\t/&lt;Tab&gt;/;
    $binding =~ s/M_ENTER_S/&lt;Return&gt;/;
    $binding =~ s/NULL//;
    die "unknown key $binding" if $binding =~ /\\[^\\]|<|>/;
    die "unknown OP $op" unless $OPS{$op};
    $MAP{$map} .= "<row><entry><literal>&lt;$function&gt;</literal></entry><entry>$binding</entry><entry>$OPS{$op}</entry></row>\n";
  }
  if ($map and /^}/) {
    undef $map;
  }
}

open XML, $xml or die "$xml: $!";
while (<XML>) {
  if (/__print_map\((.*)\)/) {
    my $map = $1;
    my $mapid = $1;
    my $maptitle = $1;
    $mapid =~ s/\s+/-/g;
    $maptitle =~ s/\b(\w)/\u$1/g;
    unless ($MAP{$map}) {
      warn "map $map undefined";
      next;
    }
    print <<EOT;
<sect2 id="${mapid}-map">
<title>$maptitle Menu</title>
$DOC{$map}

<table id="tab-${mapid}-bindings">
<title>Default $maptitle Menu Bindings</title>
<tgroup cols="3">
<thead>
<row><entry>Function</entry><entry>Default key</entry><entry>Description</entry></row>
</thead>
<tbody>
$MAP{$map}
</tbody>
</tgroup>
</table>

</sect2>

EOT
    delete $MAP{$map};
  } else {
    print;
  }
}
close XML;

warn "unprinted maps: ". join(" ", keys %MAP) if %MAP;