digraphs/xorg: json include with character info
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 21 Feb 2024 20:01:16 +0000 (21:01 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 6 Mar 2024 00:38:51 +0000 (01:38 +0100)
Similar to primary [vim] data so precedence can be preserved as alias class
(ignored for now).

Makefile
digraphs.plp
tools/mkdigraphs-xorg

index be94112d33871b845011b49999e24626872fa20a..df6cbe5bab35d15e5837a61ca3d67c2f711a6e59 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ word/put.js: $(download)
 word/%.min.js: word/%.js
        uglifyjs -m '' $< -o $@
 
-data: data/digraphs.json data/unicode-cover.inc.pl data/countries.inc.pl data/browser data/termcol-xcolor.inc.pl data/digraphs-xorg.inc.pl data/unicode-sampler word
+data: data/digraphs.json data/unicode-cover.inc.pl data/countries.inc.pl data/browser data/termcol-xcolor.inc.pl data/digraphs-xorg.json data/unicode-sampler word
 
 data/DerivedAge.txt: $(download)
        tools/wget-ifmodified http://www.unicode.org/Public/UNIDATA/$(@F) $@
@@ -53,7 +53,7 @@ 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
+data/digraphs-xorg.json: tools/mkdigraphs-xorg data/xorg-compose data/keysymdef.json
        $(call cmdsave,$^)
 
 data/digraphs-vim.inc.pl: tools/mkdigraphs-vim
index 4ee4d1f2bffce64addf1eaf31f2142b34be9d94a..6b1a5c21bc05371f6c51971a2003684be250ce44 100644 (file)
@@ -58,8 +58,8 @@ my @columns = !exists $get{split} ? \@chars2 :
        ([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
 
 if ($mode) {
-       my $xorg = Data('data/digraphs-xorg');
-       $_ = [ord $_] for values %{$xorg};
+       my $xorg = Data('digraphs-xorg');
+       $_->[3] = undef for values %{$xorg};  # reset alias classes
        $xorg->{$_}->[2] = # class = compatibility
                !$di->{key}->{$_} ? 'l2' :  # free
                $di->{key}->{$_}->[0] != $xorg->{$_}->[0] ? 'l1' :  # conflict
index 90b0d8603ac9f1790eb46641288575eaf41b06af..ec0e8626213c9054396f9f883c9f9ca63e9133fc 100755 (executable)
@@ -15,9 +15,11 @@ my $symname = eval {
        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) = m/\A <Multi_key> \h (.*?) \h+ : \h "([^"]+)" \h* (.*)/
                or next;
@@ -27,12 +29,19 @@ while ($_ = readline) {
                $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);
+       $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__