-my @nibble = (0..9, 'A'..'F');
-my $nibsize = 1;
-
-# generate character table(s)
-# (~16x faster than decoding in loop;
-# substr strings is twice as fast as splitting to an array)
-my %ALIAS = (
-# default => [qw(unicode utf-8 iso-8859-1 cp437 -cp1252- --iso-8859-15- -koi8-f)],
- default => [qw(unicode- utf-8 iso-8859-1 -cp1252- --iso-8859-15- cp437 -cp850)],
- 0 => [qw(cp437 -cp863)],
- 1 => [qw(iso-8859-1 -cp1252 -MacRoman -cp850)],
- 2 => [qw(iso-8859-2 -cp1250 -cp852 -MacCentralEurRoman -MacCroatian -MacRumanian)],
- 5 => [qw(koi8-f -iso-8859-5 -cp1251 -MacCyrillic -cp855 -cp866)],
- 7 => [qw(iso-8859-7 -cp1253 -MacGreek -cp737 -cp869)],
- 8 => [qw(iso-8859-8 -cp1255 -MacHebrew -cp862)],
-);
-my @request = map {
- if (my $input = $_) {
- my %row = (offset => 0);
- my $endpoint = 255;
- if ($input =~ s/^--//) {
- $row{offset} = $endpoint > 160 ? 160 : 48;
- }
- elsif ($input =~ s/^-//) {
- $row{offset} = $endpoint > 128 ? 128 : 32;
- }
- if ($input =~ s/-$//) {
- $endpoint = $row{offset} ? $row{offset} < 160 ? 159 : 191 : 127;
- }
- if ($row{offset}) {
- $row{setnote} = 'over cp437' if $input eq 'cp850';
- $row{setnote} = 'over iso-8859-1' if $input =~ /^iso-8859-|^cp125/;
- }
-
- if ($input =~ /^U([0-9a-f]+)(?:-([0-9a-f]+))?/) {
- my $start = hex($1) << ($2 ? 4 : 8);
- my $end = $2 ? hex($2) << 4 : $start + 240;
- $row{table} = join '', map { chr } $start .. $end+15;
- utf8::upgrade($row{table}); # prevent latin1 output
- $row{set} = sprintf 'Unicode block U+%02Xxx', $start >> 8;
- }
- elsif ($input eq 'U') {
- $row{table} = ' ' x 1024;
- $row{set} = 'Unicode planes';
- $row{cell} = do 'charset-ucplanes.inc.pl'
- or Alert('Table data could not be read', $@ || $!);
- @nibble = (map { $_.0, $_.8 } 0 .. 7);
- $nibsize = 8;
- }
- elsif ($row{set} = Encode::resolve_alias($input)) {
- if ($row{set} eq 'Internal') {
- $row{table} = ' ' x ($endpoint < 255 ? 640 : 8192);
- $row{set} = 'Unicode BMP';
- $row{cell} = do 'charset-unicode.inc.pl'
- or Alert('Table data could not be read', $@ || $!);
- }
- elsif ($row{set} eq 'utf-8-strict') {
- $row{table} = undef;
- $row{set} = 'UTF-8';
- $row{cell} = do 'charset-utf8.inc.pl'
- or Alert('Table data could not be read', $@ || $!);
+my @request;
+
+my $charsets = Data('charset');
+
+sub tabinput {
+ # generate character table(s)
+ my $input = shift or return;
+ my $params = $input =~ s/[+](.*)\z// ? $1 : undef;
+ my $charset = $charsets->{lc $input} || {};
+
+ if (ref $charset ne 'HASH') {
+ $params and Alert("Parameters ignored for $input",
+ "Cannot apply <q>$params</q> to multiple charsets.",
+ );
+ tabinput($_) for ref $charset ? @{$charset} : $charset;
+ return;
+ }
+
+ state $visible = {'' => 1}; # all present tables
+ my %row = (offset => 0, cols => 16);
+ $row{$_} = $charset->{$_} for qw( note table ); # copy metadata
+
+ if (not defined $params) {
+ my @parents = @{ $charset->{inherit} || [] };
+
+ if (my ($parent, $part) = pairfirst { defined $visible->{$a} } @parents) {
+ $row{parent} = $parent;
+ $params = $part;
+ $params = 80 unless $visible->{$parent}
+ or ($input eq 'MacCroatian' and defined $visible->{MacRomanian});
+ }
+ elsif (defined $visible->{ascii}) {
+ $row{parent} = $parents[0];
+ $params = $parents[1] // 80;
+ $params = 80 if hex $params >= 0x80; # ascii offset at most
+ }
+ elsif (@parents) {
+ $row{parent} = $parents[0];
+ $params = $parents[1] if hex $parents[1] == 0; # apply ascii end
+ }
+ $visible->{$_} //= 0 for $row{parent} || ();
+ }
+
+ for my $param (split /[+]+/, $params // '') {
+ if ($param eq 'realsize') {
+ $row{realsize}++;
+ }
+ elsif ($param =~ m{ \A cols = (\d+) \z }x) {
+ $row{cols} = $1;
+ }
+ elsif ($param =~ m{ \A (?<start> \p{AHex}+) (?: [-] (?<end> \p{AHex}+) )? \z }x) {
+ if (defined $row{endpoint}) {
+ # extend earlier range
+ my $skip = int(($row{endpoint} || $row{startpoint}) / $row{cols});
+ for ($skip + 1 .. (hex($+{start}) / $row{cols}) - 1) {
+ $row{skip}->{ $_ * $row{cols} }++;
+ }