digraphs/xorg: intermediate map of keysymdef.h names
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 21 Feb 2024 19:20:17 +0000 (20:20 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 25 Feb 2024 15:03:30 +0000 (16:03 +0100)
Split code from mkdigraphs-xorg into separate mkxkeysymdef for reuse by
upcoming mkkeyboard-xkb-symbols.

Makefile
tools/mkdigraphs-xorg
tools/mkxkeysymdef [new file with mode: 0755]

index 806e5be18c1cc0cfde73473b31ae3f23ebc923cd..cccaebf9d233f47a8de6a0b9c501e2d8ffeb828b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -49,7 +49,11 @@ data/digraphs-shiar.inc.pl: tools/mkdigraphs-shiar shiar.inc.txt
 
 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
index c2dd4414f55685e2635924ead388968ba86fe6e3..b34bef562dda161cd54e51b751b69cb7fc5805df 100755 (executable)
@@ -4,24 +4,16 @@ 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 $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 '+{';
@@ -31,7 +23,7 @@ while ($_ = readline) {
                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);
diff --git a/tools/mkxkeysymdef b/tools/mkxkeysymdef
new file mode 100755 (executable)
index 0000000..e7d7690
--- /dev/null
@@ -0,0 +1,39 @@
+#!/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.
+