charset: move encoding-specific setup code to include
[sheet.git] / charset.plp
index 49ee3eba48dafc17365a6216e7253d0c1f1755bc..ed495fe2ae89352fa10641847cd2d19d3436378c 100644 (file)
@@ -84,7 +84,7 @@ sub tabinput {
        # generate character table(s)
        my $input = shift or return;
        my $params = $input =~ s/[+](.*)\z// ? $1 : undef;
-       my $charset = $charsets->{$input} || {};
+       my $charset = $charsets->{lc $input} || {};
 
        if (ref $charset ne 'HASH') {
                $params and Alert("Parameters ignored for $input",
@@ -143,50 +143,12 @@ sub tabinput {
                }
        }
 
-       if ($input =~ m{ \A (?:wing|web)dings \d* \z }ix) {
-               eval "require Encode::\u$input";
+       if ($charset->{setup}) {
+               eval { $charset->{setup}->(\%row) }
+                       or Alert("Incomplete setup of $input", $@);
        }
 
-       if ($input eq '') {
-               $row{offset} = delete $row{startpoint};
-               $row{set} = 'Unicode characters';
-               my $block = $row{offset} >> 8;
-               $row{endpoint} ||= ($block + 1 << 8) - 1;
-               $block == ($row{endpoint} >> 8) or undef $block;
-
-               $row{table} = join '', map { chr } $row{offset} .. $row{endpoint};
-               utf8::upgrade($row{table});  # prevent latin1 output
-
-               $row{endpoint} -= $row{offset};
-
-               if (defined $block) {
-                       $row{set} = sprintf 'Unicode block U+%02Xxx', $block;
-                       $row{offset} %= 0x100;
-               }
-       }
-       elsif (lc $input eq 'uu') {
-               $row{cell} = do 'charset-ucplanes.inc.pl'
-                       or Alert('Table data could not be read', $@ || $!);
-               $row{endpoint} ||= 0x3FF;
-               $row{set} = 'Unicode planes';
-       }
-       elsif (lc $input eq 'u') {
-               $row{cell} = do 'charset-unicode.inc.pl'
-                       or Alert('Table data could not be read', $@ || $!);
-
-               $row{endpoint} ||= 0x1FFF;
-               $row{set} = 'Unicode ' . (
-                       $row{startpoint} <  0x1000 && $row{endpoint} < 0x1000 ? 'BMP' :
-                       $row{startpoint} >= 0x1000 && $row{endpoint} < 0x2000 ? 'SMP' :
-                       'allocations'
-               );
-       }
-       elsif ($input =~ m/^utf-*8$/i) {
-               $row{set} = 'UTF-8';
-               $row{cell} = do 'charset-utf8.inc.pl'
-                       or Alert('Table data could not be read', $@ || $!);
-               $row{endpoint} = 0xFF;
-       }
+       if ($row{set}) {}
        elsif ($row{set} = Encode::resolve_alias($input)) {
                $row{offset} = delete $row{startpoint};
                $row{endpoint} ||= 0xFF;