5 use open IO => ':encoding(utf-8)', ':std';
7 use JSON 'decode_json';
9 use Shiar_Sheet::FormatChar;
11 our $VERSION = '1.01';
13 my $matchvim; # enable to prefer best compatibility
16 open my $keysymh, '<', 'data/keysymdef.json' or die $!;
18 return decode_json(readline $keysymh);
19 } or die "Could not read keysym definitions: $@\n";
22 open my $jsfh, '<', 'data/digraphs.json' or die $!;
24 return JSON->new->decode(readline $jsfh);
25 } or warn "Could not read comparison digraphs: $@\n";
28 while ($_ = readline) {
29 my ($mnem, $chr, $trail) = m/\A <Multi_key> \h (.*?) \h+ : \h "([^"]+)" \h* (.*)/
32 $mnem !~ m/<dead | <KP_ | <U[0-9A-Fa-f]{4}/ or next; # skip non-standard keys
34 $mnem =~ s{<([^>]+)> \h?}{$symname->{$1} // die "reference to unknown keysym $1\n"}eg;
37 $mnem =~ m/\A [\x20-\x7F]{2} \z/ or next; # only interested in two ascii
39 my $alias = \(state $seen = {})->{$chr}; # assume first is preferred
41 my ($class, $name, undef, undef, $string) = @{
42 Shiar_Sheet::FormatChar->glyph_info($cp)
45 !$vidi->{key}->{$mnem} ? 'l3' : # free
46 $vidi->{key}->{$mnem}->[0] != $cp ? 'l1' : # conflict
47 $vidi->{key}->{$mnem}->[2] eq 'l5' ? 'l5' : # rfc
52 # aliases an earlier occurrence
53 if ($matchvim and ${$alias}->[2] lt $comparison) {
54 # replace lower compatibility level
55 ${$alias}->[3] = 'l0';
56 ${$alias}->[2] .= ' u-' . ${$alias}->[2];
61 my $menm = substr($mnem, 1, 1).substr($mnem, 0, 1);
62 if ($table{$menm} && $table{$menm}[0] == $cp) {
63 # unannotated if identical to reversed input
72 $table{$mnem} = [ $cp, $name, $comparison, $class, $string // () ];
73 ${$alias} //= $table{$mnem};
76 print JSON->new->canonical->indent->encode({
80 'Character mnemonics following compose key ⎄:',
81 'in the X Window System (Shift+AltGr by default).',
82 'Differences from <a href="/digraphs">RFC-1345</a> are indicated.',
83 'Also see <a href="/unicode">common Unicode</a>.',
85 keywords => [qw( xorg x11 x )],
87 'l5' => "matching RFC-1345",
88 'l4' => "matching Vim extension",
89 'l3' => "unique to Xorg",
91 ('l0' => "Xorg preference") x !!$matchvim,
104 mkdigraphs-xorg - Output Xorg compose sequences
109 mkdigraphs-xorg /usr/share/X11/locale/en_US.UTF-8/Compose |
110 jq -r '.key."AT"[0]' | perl -nE 'say chr' # @
114 Extracts Multi_key definitions from X11/Xorg Compose.pre include file.
115 If successful, a JSON object is output containing a digraphs list in C<key>
116 with Unicode code points keyed by mnemonics.
117 Any errors and warnings are given at STDERR.
121 Mischa POSLAWSKY <perl@shiar.org>
125 Licensed under the GNU Affero General Public License version 3.