index: release v1.18 with only altgr index linked
[sheet.git] / tools / mkdigraphs-shiar
1 #!/usr/bin/env perl
2 use 5.014;
3 use warnings;
4 use open IN => ':encoding(utf-8)', ':std';
5
6 our $VERSION = '1.03';
7
8 my $di = do "./data/digraphs-rfc.inc.pl"
9         or warn "official digraphs not included for comparison: ", $@ // $!;
10
11 say "# automatically generated by $0";
12 say '+{';
13 for (readline) {
14         my ($mnem, $cp, $chr) = m{^([!"%'-Z_a-z]{2}) (?:\\(\d+)|(.))} or next;
15         warn("$mnem already defined"), next if defined $di->{$mnem};
16         my $chrstr = sprintf '"\x{%x}"', $cp // ord $chr;
17         say "q{$mnem} => $chrstr,";
18 }
19 say '}';
20
21 __END__
22
23 =head1 NAME
24
25 mkdigraphs-shiar - Output digraph data from proposal text
26
27 =head1 SYNOPSIS
28
29     mkdigraphs-shiar shiar.inc.txt >digraphs-shiar.inc.pl
30     perl -e'$di = do "digraphs-shiar.inc.pl"; print chr $di->{":)"}'
31
32 =head1 DESCRIPTION
33
34 Parses a text file containing digraphs followed by
35 the literal unicode character and optional comments.
36 If successful, Perl code is output resulting in a hash
37 with Unicode code points keyed by digraph.
38 Any errors and warnings are given at STDERR.
39
40 =head1 AUTHOR
41
42 Mischa POSLAWSKY <perl@shiar.org>
43
44 =head1 LICENSE
45
46 Licensed under the GNU Affero General Public License version 3.
47