digraphs/xorg: json include with character info
[sheet.git] / tools / mkdigraphs-xorg
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__