Changeset 9967


Ignore:
Timestamp:
2005-05-26T13:25:28+12:00 (19 years ago)
Author:
jrm21
Message:

added extra error checking (eg if asked for an unsupported encoding)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/unicode.pm

    r9125 r9967  
    411411    return 1 if (defined $unicode::translations{$encoding});
    412412
     413    if (! -r $mapfile || -d $mapfile) {
     414    return 0;
     415    }
    413416    return 0 unless open (MAPFILE, $mapfile);
    414417    binmode (MAPFILE);
     
    418421
    419422    my ($in,$i,$j);
    420     while (read(MAPFILE, $in, 1) == 1) {
     423    while (1) {
     424    my $ret=read(MAPFILE, $in, 1);
     425    if (!defined($ret)) { # error
     426        print STDERR "unicode.pm: error reading mapfile: $!\n";
     427        last;
     428    }
     429    if ($ret != 1) { last }
    421430    $i = unpack ("C", $in);
    422431    $block->{'map'}->[$i] = [@unicode::array256];
     
    442451    my $outtext = "";
    443452    my $encodename = "unicode-$encoding";
    444     my $enc_info = $encodings::encodings->{"$encoding"};
     453
     454    if (!exists $encodings::encodings->{$encoding}) {
     455    print STDERR "unicode.pm: ERROR - unsupported encoding "
     456        . "'$encoding' requested\n";
     457    return "";
     458    }
     459
     460    my $enc_info = $encodings::encodings->{$encoding};
    445461    my $mapfile = &util::filename_cat($ENV{'GSDLHOME'}, "mappings",
    446462                      "from_uc", $enc_info->{'mapfile'});
Note: See TracChangeset for help on using the changeset viewer.