5 use open IO => ':encoding(utf-8)', ':std';
8 use JSON 'decode_json';
10 use Shiar_Sheet::FormatChar;
12 our $VERSION = '1.02';
14 my $matchvim; # enable to prefer best compatibility
17 open my $keysymh, '<', 'data/keysymdef.json' or die $!;
19 return decode_json(readline $keysymh);
20 } or die "Could not read keysym definitions: $@\n";
23 open my $jsfh, '<', 'data/digraphs.json' or die $!;
25 return JSON->new->decode(readline $jsfh);
26 } or warn "Could not read comparison digraphs: $@\n";
29 while ($_ = readline) {
30 my ($mnem, $chr, $trail) = m/\A <Multi_key> \h (.*?) \h+ : \h "([^"]+)" \h* (.*)/
33 $mnem !~ m/<dead | <KP_ | <U[0-9A-Fa-f]{4}/ or next; # skip non-standard keys
35 $mnem =~ s{<([^>]+)> \h?}{$symname->{$1} // die "reference to unknown keysym $1\n"}eg;
38 $mnem =~ m/\A [\x20-\x7F]{2} \z/ or next; # only interested in two ascii
40 my $alias = \(state $seen = {})->{$chr}; # assume first is preferred
42 my ($class, $name, undef, undef, $string) = @{
43 Shiar_Sheet::FormatChar->glyph_info($cp)
45 my $reverse = substr($mnem, 1, 1) . substr($mnem, 0, 1);
46 my $cmp = $vidi->{key}->{$mnem};
47 my $cmpalt = defined $cmp && !$cmp && $vidi->{key}->{$reverse};
50 $cmpalt && $cmpalt->[0] == $cp ? 'l4' : # matches alias
52 $cmp->[0] != $cp ? 'l1' : # conflict
53 $cmp->[2] eq 'l5' ? 'l5' : # rfc
58 # aliases an earlier occurrence
59 if ($matchvim and ${$alias}->[2] lt $comparison) {
60 # replace lower compatibility level
61 ${$alias}->[3] = 'l0';
62 ${$alias}->[2] .= ' u-' . ${$alias}->[2];
67 my $menm = substr($mnem, 1, 1).substr($mnem, 0, 1);
68 if ($table{$menm} && $table{$menm}[0] == $cp) {
69 # unannotated if identical to reversed input
78 $table{$mnem} = [ $cp, $name, $comparison, $class, $string // () ];
79 ${$alias} //= $table{$mnem};
82 print JSON->new->canonical->indent->encode({
86 'Character mnemonics following compose key ⎄',
87 'in the X Window System (Shift+AltGr by default).',
88 'Differences from <a href="/digraphs">RFC-1345</a> are indicated.',
89 'Also see <a href="/keyboard/altgr">monograph maps</a>',
90 'of alternative Xorg input modes with an AltGr modifier.</p>',
92 keywords => [qw( xorg x11 x )],
94 'l5' => "matching RFC-1345",
95 'l4' => "matching Vim extension or alternate",
96 'l3' => "unique to Xorg",
98 ('l0' => "Xorg preference") x !!$matchvim,
111 mkdigraphs-xorg - Output Xorg compose sequences
116 mkdigraphs-xorg /usr/share/X11/locale/en_US.UTF-8/Compose |
117 jq -r '.key."AT"[0]' | perl -nE 'say chr' # @
121 Extracts Multi_key definitions from X11/Xorg Compose.pre include file.
122 If successful, a JSON object is output containing a digraphs list in C<key>
123 with Unicode code points keyed by mnemonics.
124 Any errors and warnings are given at STDERR.
128 Mischa POSLAWSKY <perl@shiar.org>
132 Licensed under the GNU Affero General Public License version 3.