5 use open IO => ':encoding(utf-8)', ':std';
8 use JSON 'decode_json';
10 use Shiar_Sheet::FormatChar;
12 our $VERSION = '1.01';
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)
46 !$vidi->{key}->{$mnem} ? 'l3' : # free
47 $vidi->{key}->{$mnem}->[0] != $cp ? 'l1' : # conflict
48 $vidi->{key}->{$mnem}->[2] eq 'l5' ? 'l5' : # rfc
53 # aliases an earlier occurrence
54 if ($matchvim and ${$alias}->[2] lt $comparison) {
55 # replace lower compatibility level
56 ${$alias}->[3] = 'l0';
57 ${$alias}->[2] .= ' u-' . ${$alias}->[2];
62 my $menm = substr($mnem, 1, 1).substr($mnem, 0, 1);
63 if ($table{$menm} && $table{$menm}[0] == $cp) {
64 # unannotated if identical to reversed input
73 $table{$mnem} = [ $cp, $name, $comparison, $class, $string // () ];
74 ${$alias} //= $table{$mnem};
77 print JSON->new->canonical->indent->encode({
81 'Character mnemonics following compose key ⎄:',
82 'in the X Window System (Shift+AltGr by default).',
83 'Differences from <a href="/digraphs">RFC-1345</a> are indicated.',
84 'Also see <a href="/keyboard/altgr">monograph maps</a>',
85 'of alternative Xorg input modes with an AltGr modifier.</p>',
87 keywords => [qw( xorg x11 x )],
89 'l5' => "matching RFC-1345",
90 'l4' => "matching Vim extension",
91 'l3' => "unique to Xorg",
93 ('l0' => "Xorg preference") x !!$matchvim,
106 mkdigraphs-xorg - Output Xorg compose sequences
111 mkdigraphs-xorg /usr/share/X11/locale/en_US.UTF-8/Compose |
112 jq -r '.key."AT"[0]' | perl -nE 'say chr' # @
116 Extracts Multi_key definitions from X11/Xorg Compose.pre include file.
117 If successful, a JSON object is output containing a digraphs list in C<key>
118 with Unicode code points keyed by mnemonics.
119 Any errors and warnings are given at STDERR.
123 Mischa POSLAWSKY <perl@shiar.org>
127 Licensed under the GNU Affero General Public License version 3.