#!/usr/bin/env perl use 5.014; use warnings; use utf8; use open IO => ':encoding(utf-8)', ':std'; use re '/msx'; use JSON 'decode_json'; use Data::Dump 'pp'; our $VERSION = '1.01'; 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"; # 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) = m/\A \h (.*?) \h+ : \h "([^"]+)" \h* (.*)/ or next; $chr =~ s/\\(.)/$1/g; $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 ]; } print JSON->new->canonical->indent->encode(\%table); __END__ =head1 NAME mkdigraphs-xorg - Output Xorg compose sequences =head1 SYNOPSIS mkdigraphs-xorg /usr/share/X11/locale/en_US.UTF-8/Compose >digraphs-xorg.inc.pl perl -e'$di = do "digraphs-xorg.inc.pl"; print chr $di->{AT}' =head1 DESCRIPTION Extracts Multi_key definitions from X11/Xorg Compose.pre include file. If successful, Perl code is output resulting in a hash with Unicode code points keyed by mnemonics. Any errors and warnings are given at STDERR. =head1 AUTHOR Mischa POSLAWSKY =head1 LICENSE Licensed under the GNU Affero General Public License version 3.