emoji: silence unused argument warnings
[sheet.git] / tools / mkdigraphs-plan9
1 #!/usr/bin/env perl
2 use 5.014;
3 use warnings;
4 use utf8;
5 use open IO => ':utf8', ':std';
6 use Data::Dump 'pp';
7
8 our $VERSION = '1.00';
9
10 # translation table for deprecated code points
11 my %replace = (
12         0xF015 => '⎇',  # alt
13         0xF016 => '⇧',  # shift
14         0xF017 => '⎈',  # control
15 );
16
17 # expect input data source at command line
18 @ARGV or die "Specify input source file or - for STDIN\n";
19
20 # convert each character line to perl code
21 # (assume no backslashes or curlies, so we can just q{} w/o escaping)
22 say "# automatically generated by $0";
23 say 'use utf8;';
24 say '+{';
25 while ($_ = readline) {
26         my ($chrhex, $mnems, $sample, $name) = m{\A([0-9A-F]{4})  (.{11}) (.)\t(.*)}i
27                 or warn("syntax error on line $.: $_"), next;
28         my $chrnum = hex $chrhex;
29         my $chr = chr $chrnum;
30         $chr eq $sample
31                 or warn("character mismatch on line $.: $_"), next;
32         $chr = $replace{$chrnum} or next if defined $replace{$chrnum};
33         my $chrstr = pp($replace{$chrnum} // $chr);
34         for my $mnem (split / /, $mnems) {
35 #               next if length $mnem != 2;
36                 say "q{$mnem} => $chrstr, # $name";
37         }
38 }
39 say '}';
40
41 __END__
42
43 =head1 NAME
44
45 mkdigraphs-plan9 - Output digraph data from Plan9 keyboard data
46
47 =head1 SYNOPSIS
48
49 Extract digraphs from text specifications as a perl hash:
50
51     mkdigraphs-plan9 keyboard >digraphs-plan9.inc.pl
52
53 Input can be the literal RFC (or similar) document:
54
55     curl https://9fans.github.io/usr/local/plan9/lib/keyboard | mkdigraphs-plan9 -
56
57 Test by printing the character for DO (should be a dollar sign):
58
59     perl -e'$di = do "digraphs-plan9.inc.pl"; print chr $di->{DO}'
60
61 =head1 DESCRIPTION
62
63 Parses the official RFC-1345 document, searching the
64 'character mnemonic table' for all digraph definitions.
65 If successful, Perl code is output resulting in a hash
66 with Unicode code points keyed by digraph.
67 Obsolete values (references to private use area)
68 are converted to modern alternatives.
69 Any errors and warnings are given at STDERR.
70
71 =head1 AUTHOR
72
73 Mischa POSLAWSKY <perl@shiar.org>
74
75 =head1 LICENSE
76
77 Licensed under the GNU Affero General Public License version 3.
78