From c3d9bbfdd610d5ca8ac4ab785cc78ea5551ced09 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 30 Aug 2018 12:33:43 +0200 Subject: [PATCH] digraphs: parse plan9 keyboard combinations Import definitions for personal comparison and evaluation. --- tools/mkdigraphs-plan9 | 78 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 tools/mkdigraphs-plan9 diff --git a/tools/mkdigraphs-plan9 b/tools/mkdigraphs-plan9 new file mode 100755 index 0000000..54b8b3c --- /dev/null +++ b/tools/mkdigraphs-plan9 @@ -0,0 +1,78 @@ +#!/usr/bin/env perl +use 5.014; +use warnings; +use utf8; +use open IO => ':utf8', ':std'; +use Data::Dump 'pp'; + +our $VERSION = '1.00'; + +# translation table for deprecated code points +my %replace = ( + 0xF015 => '⎇', # alt + 0xF016 => '⇧', # shift + 0xF017 => '⎈', # control +); + +# expect input data source at command line +@ARGV or die "Specify input source file or - for STDIN\n"; + +# convert each character line to perl code +# (assume no backslashes or curlies, so we can just q{} w/o escaping) +say "# automatically generated by $0"; +say 'use utf8;'; +say '+{'; +while ($_ = readline) { + my ($chrhex, $mnems, $sample, $name) = m{\A([0-9A-F]{4}) (.{11}) (.)\t(.*)}i + or warn("syntax error on line $.: $_"), next; + my $chrnum = hex $chrhex; + my $chr = chr $chrnum; + $chr eq $sample + or warn("character mismatch on line $.: $_"), next; + $chr = $replace{$chrnum} or next if defined $replace{$chrnum}; + my $chrstr = pp($replace{$chrnum} // $chr); + for my $mnem (split / /, $mnems) { +# next if length $mnem != 2; + say "q{$mnem} => $chrstr, # $name"; + } +} +say '}'; + +__END__ + +=head1 NAME + +mkdigraphs-plan9 - Output digraph data from Plan9 keyboard data + +=head1 SYNOPSIS + +Extract digraphs from text specifications as a perl hash: + + mkdigraphs-plan9 keyboard >digraphs-plan9.inc.pl + +Input can be the literal RFC (or similar) document: + + curl https://9fans.github.io/usr/local/plan9/lib/keyboard | mkdigraphs-plan9 - + +Test by printing the character for DO (should be a dollar sign): + + perl -e'$di = do "digraphs-plan9.inc.pl"; print chr $di->{DO}' + +=head1 DESCRIPTION + +Parses the official RFC-1345 document, searching the +'character mnemonic table' for all digraph definitions. +If successful, Perl code is output resulting in a hash +with Unicode code points keyed by digraph. +Obsolete values (references to private use area) +are converted to modern alternatives. +Any errors and warnings are given at STDERR. + +=head1 AUTHOR + +Mischa POSLAWSKY + +=head1 LICENSE + +Licensed under the GNU Affero General Public License version 3. + -- 2.30.0