perl: mention breaking changes and feature removals
[sheet.git] / tools / mkdigraphs-xorg
index edef62de6ef24110d4aeca26733abf5c68335702..ec88309500c97ddb2c714f6df6cd149baef5c9b5 100755 (executable)
@@ -4,11 +4,14 @@ use warnings;
 use utf8;
 use open IO => ':encoding(utf-8)', ':std';
 use re '/msx';
 use utf8;
 use open IO => ':encoding(utf-8)', ':std';
 use re '/msx';
+use lib '.';
 use JSON 'decode_json';
 use Data::Dump 'pp';
 use Shiar_Sheet::FormatChar;
 
 use JSON 'decode_json';
 use Data::Dump 'pp';
 use Shiar_Sheet::FormatChar;
 
-our $VERSION = '1.01';
+our $VERSION = '1.02';
+
+my $matchvim;  # enable to prefer best compatibility
 
 my $symname = eval {
        open my $keysymh, '<', 'data/keysymdef.json' or die $!;
 
 my $symname = eval {
        open my $keysymh, '<', 'data/keysymdef.json' or die $!;
@@ -33,40 +36,71 @@ while ($_ = readline) {
                1;
        } or warn($@), next;
        $mnem =~ m/\A [\x20-\x7F]{2} \z/ or next;  # only interested in two ascii
                1;
        } or warn($@), next;
        $mnem =~ m/\A [\x20-\x7F]{2} \z/ or next;  # only interested in two ascii
-       my $alias = (state $seen = {})->{$chr}++;  # assume first is preferred
+
+       my $alias = \(state $seen = {})->{$chr};  # assume first is preferred
        my $cp = ord $chr;
        my $cp = ord $chr;
-       my $uninfo = Shiar_Sheet::FormatChar->glyph_info($cp);
+       my ($class, $name, undef, undef, $string) = @{
+               Shiar_Sheet::FormatChar->glyph_info($cp)
+       };
+       my $reverse = substr($mnem, 1, 1) . substr($mnem, 0, 1);
+       my $cmp = $vidi->{key}->{$mnem};
+       my $cmpalt = defined $cmp && !$cmp && $vidi->{key}->{$reverse};
        my $comparison = (
        my $comparison = (
-               !$vidi->{key}->{$mnem} ? 'l3' :  # free
-               $vidi->{key}->{$mnem}->[0] != $cp ? 'l1' :  # conflict
-               $vidi->{key}->{$mnem}->[2] eq 'l4' ? 'l5' :  # rfc
+               !$cmp ?
+                       $cmpalt && $cmpalt->[0] == $cp ? 'l4' :  # matches alias
+                       'l3' :  # free
+               $cmp->[0] != $cp ? 'l1' :  # conflict
+               $cmp->[2] eq 'l5' ? 'l5' :  # rfc
                'l4'  # any
        );
                'l4'  # any
        );
-       $table{$mnem} = [
-               $cp,
-               $uninfo->[1] // '',  # name
-               $comparison,
-               $alias ? 'l0 ex' : $uninfo->[0] // '',  # class
-               $uninfo->[4] // (),  # string
-       ];
+
+       if (${$alias}) {
+               # aliases an earlier occurrence
+               if ($matchvim and ${$alias}->[2] lt $comparison) {
+                       # replace lower compatibility level
+                       ${$alias}->[3] = 'l0';
+                       ${$alias}->[2] .=  ' u-' . ${$alias}->[2];
+                       ${$alias} = undef;
+               }
+               else {
+                       $class = 'l0';
+                       my $menm = substr($mnem, 1, 1).substr($mnem, 0, 1);
+                       if ($table{$menm} && $table{$menm}[0] == $cp) {
+                               # unannotated if identical to reversed input
+                               $cp = 0;
+                       }
+                       else {
+                               $class .= ' ex';
+                       }
+               }
+       }
+
+       $table{$mnem} = [ $cp, $name, $comparison, $class, $string // () ];
+       ${$alias} //= $table{$mnem};
 }
 
 print JSON->new->canonical->indent->encode({
        title => 'X.Org',
        key   => \%table,
        intro => join("\n",
 }
 
 print JSON->new->canonical->indent->encode({
        title => 'X.Org',
        key   => \%table,
        intro => join("\n",
-               'Character mnemonics following compose key ⎄:',
+               'Character mnemonics following compose key ⎄',
                'in the X Window System (Shift+AltGr by default).',
                'Differences from <a href="/digraphs">RFC-1345</a> are indicated.',
                'in the X Window System (Shift+AltGr by default).',
                'Differences from <a href="/digraphs">RFC-1345</a> are indicated.',
-               'Also see <a href="/unicode">common Unicode</a>.',
+               'Also see <a href="/keyboard/altgr">monograph maps</a>',
+               'of alternative Xorg input modes with an AltGr modifier.</p>',
        ),
        keywords => [qw( xorg x11 x )],
        flag  => {
                'l5' => "matching RFC-1345",
        ),
        keywords => [qw( xorg x11 x )],
        flag  => {
                'l5' => "matching RFC-1345",
-               'l4' => "matching proposal",
+               'l4' => "matching Vim extension or alternate",
                'l3' => "unique to Xorg",
                'l1' => "conflict",
                'l3' => "unique to Xorg",
                'l1' => "conflict",
-               'l0 ex' => "duplicate",
+               ('l0' => "Xorg preference") x !!$matchvim,
+               'l0 ex' => "alias",
+       },
+       flagclass => {
+               l5 => 'u-l4',
+               l4 => 'u-l5',
        },
 });
 
        },
 });