tools: fix includes from relative paths for perl v5.26
[sheet.git] / tools / mkdigraphlist
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use utf8;
6
7 use open OUT => ':utf8', ':std';
8
9 our $VERSION = '1.06';
10
11 # import and combine various digraph data
12 push @INC, 'data';
13 my $rfc = do 'digraphs-rfc.inc.pl'
14         or die "error reading digraphs include: ", $@ // $!;
15 my $extra = do 'digraphs-shiar.inc.pl'
16         or warn "could not include shiar proposals: ", $@ // $!;
17 my $vim = do 'digraphs-vim.inc.pl'
18         or warn "could not include vim extensions ", $@ // $!;
19 my $vimold = do 'digraphs-vim-74.inc.pl'
20         or warn "could not include vim compatibility ", $@ // $!;
21 my $di = { %{$vim // {}}, %{$rfc}, %{$extra // {}} };
22
23 # optionally get unicode character information
24 my $uninfo = do 'unicode-char.inc.pl'
25         or warn "could not include unicode details: ", $@ // $!;
26
27 # output perl code of hash
28 # (assume no backslashes or curlies, so we can just q{} w/o escaping)
29 print "# automatically generated by $0\n";
30 print "use utf8;\n";
31 print "+{\n";
32 printf '(map {$_=>0} qw{%s}),'."\n", join(' ',
33         grep { !defined $di->{$_} }
34         map { substr($_, 1, 1).substr($_, 0, 1) } sort keys %{$di}
35 );
36 printf "q{%s}=>[%s],\n", s/(?=[\\}])/\\/gr, join(',',
37         ord $di->{$_},   # original code point
38         map {"'$_'"}
39         $uninfo->{ $di->{$_} }->[1] // '',  # name
40         join(' ',
41                 $rfc->{$_}
42                         ? $vim->{$_} ? 'l4' : 'l1'  # vim+rfc or rfc only
43                         : $vim->{$_} ? 'l3' : 'l2', # vim only or neither
44                 $vimold && $vim->{$_} && !$vimold->{$_} ? 'ex' : (), # new vim feature
45         ),
46         ($uninfo->{ $di->{$_} }->[0] // '') =~ s/ u-di| u-prop| ex//gr,  # class
47         $uninfo->{ $di->{$_} }->[4] // (),  # string
48 ) for sort keys %{$di};
49 print "}\n";
50
51 __END__
52
53 =head1 NAME
54
55 mkdigraphlist - Output character list of combined digraph data
56
57 =head1 SYNOPSIS
58
59     mkdigraphlist >digraphs.inc.pl
60     perl -e'$di = do "digraphs.inc.pl"; print chr $di->{DO}->[0]'
61
62 =head1 DESCRIPTION
63
64 Combines precompiled digraph includes of rfc (1345), vim, and shiar
65 and outputs a complete map including character details and usage classes.
66
67 The value can either be a scalar string containing another
68 digraph which can be considered identical (usually inverted),
69 or an array ref containing at least the resulting character's
70 Unicode code point value.  If available, the following UCD data
71 is appended: character name, usage classes, unicode classes,
72 and replacement output string.
73 For example:
74
75  +{
76    AE => [198, 'LATIN CAPITAL LETTER AE', 'u-di', 'Latin Lu Xl u-v11'],
77    EA => 'AE',
78   }
79
80 =head1 AUTHOR
81
82 Mischa POSLAWSKY <perl@shiar.org>
83
84 =head1 LICENSE
85
86 Licensed under the GNU Affero General Public License version 3.
87