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