keyboard/altgr/index: hide mode and identical keys in inventory
[sheet.git] / tools / mkdigraphs-xorg
index 32a5044150c62657d5ce214f5052560f87847c6a..90b0d8603ac9f1790eb46641288575eaf41b06af 100755 (executable)
@@ -2,34 +2,32 @@
 use 5.014;
 use warnings;
 use utf8;
-use open IO => ':utf8', ':std';
+use open IO => ':encoding(utf-8)', ':std';
+use re '/msx';
+use JSON 'decode_json';
 use Data::Dump 'pp';
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
-open my $keysymh, '<', '/usr/include/X11/keysymdef.h'
-       or die "Could not find keysym definitions: $!\n";
-
-my %keysym;
-while (readline $keysymh) {
-       m{
-               \A  [#]define[ ]XK_ (?<name>[a-zA-Z_0-9]+)
-               \h+ 0x(?<value>[0-9a-f]+)
-               \h* [/][*] [\h(] U[+] (?<unicode>[0-9A-F]{4,6})
-       }msx or next;
-       $keysym{ $+{name} } = chr hex $+{unicode};
-}
+my $symname = eval {
+       open my $keysymh, '<', 'data/keysymdef.json' or die $!;
+       local $/;
+       return decode_json(readline $keysymh);
+} or die "Could not read keysym definitions: $@\n";
 
 say "# automatically generated by $0";
 say '+{';
 
 while ($_ = readline) {
-       my ($mnem, $chr, $trail) = /^<Multi_key>\h(.*?)\h+:\h"([^"]+)"\h*(.*)/
+       my ($mnem, $chr, $trail) = m/\A <Multi_key> \h (.*?) \h+ : \h "([^"]+)" \h* (.*)/
                or next;
        $chr =~ s/\\(.)/$1/g;
-       $mnem !~ /<dead|<KP_|<U[0-9A-Fa-f]{4}/ or next;  # skip non-standard keys
-       $mnem =~ s{<([^>]+)> ?}{$keysym{$1} // die "reference to unknown keysym $1\n"}eg;
-       $mnem !~ /[^ -\x7F]/ or next;  # skip unicode
+       $mnem !~ m/<dead | <KP_ | <U[0-9A-Fa-f]{4}/ or next;  # skip non-standard keys
+       eval {
+               $mnem =~ s{<([^>]+)> \h?}{$symname->{$1} // die "reference to unknown keysym $1\n"}eg;
+               1;
+       } or warn($@), next;
+       $mnem !~ m/[^\x20-\x7F]/ or next;  # skip unicode
 #      (state $seen = {})->{$chr}++ and next;
        printf "%s => %s,\n", pp($mnem), pp($chr);
 }