Split code from mkdigraphs-xorg into separate mkxkeysymdef for reuse by
upcoming mkkeyboard-xkb-symbols.
data/xorg-compose: $(download)
tools/wget-ifmodified http://cgit.freedesktop.org/xorg/lib/libX11/plain/nls/en_US.UTF-8/Compose.pre $@
data/xorg-compose: $(download)
tools/wget-ifmodified http://cgit.freedesktop.org/xorg/lib/libX11/plain/nls/en_US.UTF-8/Compose.pre $@
-data/digraphs-xorg.inc.pl: tools/mkdigraphs-xorg data/xorg-compose
+data/keysymdef.h: $(download)
+ tools/wget-ifmodified http://gitlab.freedesktop.org/xorg/proto/xorgproto/-/raw/master/include/X11/$(@F) $@
+data/keysymdef.json: tools/mkxkeysymdef data/keysymdef.h
+ $(call cmdsave,$^)
+data/digraphs-xorg.inc.pl: tools/mkdigraphs-xorg data/xorg-compose data/keysymdef.json
$(call cmdsave,$^)
data/digraphs-vim.inc.pl: tools/mkdigraphs-vim
$(call cmdsave,$^)
data/digraphs-vim.inc.pl: tools/mkdigraphs-vim
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 Data::Dump 'pp';
our $VERSION = '1.01';
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_ (?<name>[a-zA-Z_0-9]+)
- \h+ 0x(?<value>[0-9a-f]+)
- \h* [/][*] [\h(] U[+] (?<unicode>[0-9A-F]{4,6})
- } 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 '+{';
say "# automatically generated by $0";
say '+{';
or next;
$chr =~ s/\\(.)/$1/g;
$mnem !~ m/<dead | <KP_ | <U[0-9A-Fa-f]{4}/ or next; # skip non-standard keys
or next;
$chr =~ s/\\(.)/$1/g;
$mnem !~ m/<dead | <KP_ | <U[0-9A-Fa-f]{4}/ or next; # skip non-standard keys
- $mnem =~ s{<([^>]+)> \h?}{$keysym{$1} // die "reference to unknown keysym $1\n"}eg;
+ $mnem =~ s{<([^>]+)> \h?}{$symname->{$1} // die "reference to unknown keysym $1\n"}eg;
$mnem !~ m/[^\x20-\x7F]/ or next; # skip unicode
# (state $seen = {})->{$chr}++ and next;
printf "%s => %s,\n", pp($mnem), pp($chr);
$mnem !~ m/[^\x20-\x7F]/ or next; # skip unicode
# (state $seen = {})->{$chr}++ and next;
printf "%s => %s,\n", pp($mnem), pp($chr);
--- /dev/null
+#!/usr/bin/env perl
+use 5.014;
+use warnings;
+use utf8;
+use re '/msx';
+use JSON;
+
+our $VERSION = '1.00';
+
+my %keysym;
+while (readline) {
+ m{
+ \A [#]define[ ]XK_ (?<name>[a-zA-Z_0-9]+)
+ \h+ 0x(?<value>[0-9a-fA-F]+)
+ \h* [/][*] [\h(] U[+] (?<unicode>[0-9A-F]{4,6})
+ } or next;
+ $keysym{ $+{name} } = chr hex $+{unicode};
+}
+
+print JSON->new->ascii->canonical->indent->encode(\%keysym);
+
+__END__
+
+=head1 NAME
+
+mkxkeysymdef - Map Xorg key symbol names to Unicode characters
+
+=head1 SYNOPSIS
+
+ mkxkeysymdef /usr/incnlude/X11/keysymdef.h >keysymdef.json
+
+=head1 AUTHOR
+
+Mischa POSLAWSKY <perl@shiar.org>
+
+=head1 LICENSE
+
+Licensed under the GNU Affero General Public License version 3.
+