X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/704d23fffba840c4d0ab3e3dc7e0d580b00b3ed2..9445c538bedc82733b7b1c6eb9df7bf9cb54ed64:/tools/mkdigraphs-xorg diff --git a/tools/mkdigraphs-xorg b/tools/mkdigraphs-xorg index 1ce8c69..ec0e862 100755 --- a/tools/mkdigraphs-xorg +++ b/tools/mkdigraphs-xorg @@ -2,41 +2,46 @@ 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.01'; -my $keysymh; -open $keysymh, '<', 'data/keysymdef.h' - or open $keysymh, '<', '/usr/include/X11/keysymdef.h' - or die "Could not find keysym definitions: $!\n"; - -my %keysym; -while (readline $keysymh) { - m{ - \A [#]define[ ]XK_ (?[a-zA-Z_0-9]+) - \h+ 0x(?[0-9a-f]+) - \h* [/][*] [\h(] U[+] (?[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 '+{'; +# optionally get unicode character information +my $uninfo = do './data/unicode-char.inc.pl' + or warn "could not include unicode details: ", $@ // $!; +my %table; while ($_ = readline) { - my ($mnem, $chr, $trail) = /^\h(.*?)\h+:\h"([^"]+)"\h*(.*)/ + my ($mnem, $chr, $trail) = m/\A \h (.*?) \h+ : \h "([^"]+)" \h* (.*)/ or next; $chr =~ s/\\(.)/$1/g; - $mnem !~ /]+)> ?}{$keysym{$1} // die "reference to unknown keysym $1\n"}eg; - $mnem !~ /[^ -\x7F]/ or next; # skip unicode -# (state $seen = {})->{$chr}++ and next; - printf "%s => %s,\n", pp($mnem), pp($chr); + $mnem !~ m/]+)> \h?}{$symname->{$1} // die "reference to unknown keysym $1\n"}eg; + 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 + $table{$mnem} = [ + ord $chr, + $uninfo->{$chr}->[1] // '', # name + 0, # comparison + $alias ? 'l0 ex' : + ($uninfo->{$chr}->[0] // '') =~ s/ u-di| u-prop| ex//gr, # class + $uninfo->{$chr}->[4] // (), # string + ]; } -say '}'; +print JSON->new->canonical->indent->encode(\%table); __END__