Changeset 3019


Ignore:
Timestamp:
2002-02-27T18:57:30+13:00 (22 years ago)
Author:
jrm21
Message:

Fixes for when on windows - it was having a lot of trouble sorting out links
that were to dos-style filenames, so we convert '\' chars into '/' so we can
remove the directory prefix, otherwise the links were broken...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/HTMLPlug.pm

    r2995 r3019  
    141141    my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
    142142    my $outhandle = $self->{'outhandle'};
    143 
    144143    print $outhandle "HTMLPlug: processing $file\n"
    145144    if $self->{'verbosity'} > 1;
    146145
     146    if ($ENV{'GSDLOS'} =~ /^windows/i) {
     147      # this makes life so much easier... perl can cope with unix-style '/'s.
     148      $base_dir =~ s@(\\)+@/@g;
     149      $file =~ s@(\\)+@/@g;
     150    }
    147151    my $cursection = $doc_obj->get_top_section();
    148152
     
    155159    # like when w3mir is used to download a website).
    156160    my $web_url = "http://$file";
    157     $web_url =~ s/\\/\//g; # for windows
    158161    $doc_obj->add_utf8_metadata($cursection, "URL", $web_url);
    159162
     
    258261    my $self = shift (@_);
    259262    my ($textref, $base_dir, $file, $doc_obj, $cursection) = @_;
    260 
    261263    # trap links
    262264    if (!$self->{'nolinks'}) {
     
    277279
    278280    # add text to document object
     281    # turn \ into \\ so that the rest of greenstone doesn't think there
     282    # is an escape code following. (Macro parsing loses them...)
     283    $$textref =~ s/\\/\\\\/go;
    279284    $doc_obj->add_utf8_text($cursection, $$textref);
    280285}
     
    350355    $filename =~ s/^[^:]*:\/\///;
    351356    $filename = &util::filename_cat($base_dir, $filename);
    352     
     357   
    353358    my ($ext) = $filename =~ /(\.[^\.]*)$/;
    354359
     
    391396    }
    392397   
    393     if ($before_hash =~ s/^((?:http|ftp|file):\/\/)//i) {
     398    if ($before_hash =~ s@^((?:http|ftp|file)://)@@i) {
    394399    my $type = $1;
    395400
     
    415420   
    416421    } elsif ($link !~ /^(mailto|news|gopher|nntp|telnet|javascript):/i) {
    417     if ($before_hash =~ s/^\/// || $before_hash =~ /\\/) {
     422    if ($before_hash =~ s@^/@@ || $before_hash =~ /\\/) {
    418423
    419424        # the first directory will be the domain name if file_is_url
    420425        # to generate archives, otherwise we'll assume all files are
    421426        # from the same site and base_dir is the root
    422             # This is not called in Windows
     427
    423428        if ($self->{'file_is_url'}) {
    424429        my @dirs = split /[\/\\]/, $file;
    425430        my $domname = shift (@dirs);
    426431        $before_hash = &util::filename_cat($domname, $before_hash);
    427         $before_hash =~ s/\\/\//g; # for windows
     432        $before_hash =~ s@\\@/@g; # for windows
    428433        }
    429434        else
     
    431436        # see if link shares directory with source document
    432437        # => turn into relative link if this is so!
    433         my $before_hash_fix = "";
    434438       
    435         # filename_cat appends / or \ to the beginning of the
    436         # file pathname but in Windows we don't want to do that
    437439        if ($ENV{'GSDLOS'} =~ /^windows/i) {
    438             $before_hash_fix = $before_hash;
     440            # too difficult doing a pattern match with embedded '\'s...
     441            my $win_before_hash=$before_hash;
     442            $win_before_hash =~ s@(\\)+@/@g;
     443            # $base_dir is already similarly "converted" on windows.
     444            if ($win_before_hash =~ s@^$base_dir/@@o) {
     445              # if this is true, we removed a prefix
     446              $before_hash=$win_before_hash;
     447            }
     448
    439449        }
    440450        else {
    441             $before_hash_fix = &util::filename_cat("",$before_hash);
    442         }
    443 
    444         my $base_dir_win_match = $base_dir;
    445         $base_dir_win_match =~ s/\\/\\\\/g;
    446 
    447         $before_hash_fix =~ s/^$base_dir_win_match(\\|\/)//;
    448         $before_hash = $before_hash_fix;
     451            $before_hash = &util::filename_cat("",$before_hash);
     452            $before_hash =~ s@^$base_dir/@@;
     453        }
    449454
    450455        }
     
    665670    &BasPlug::read_file($self, $filename, $encoding, $language, $textref);
    666671
    667     # turn \ into \\ so that the rest of greenstone doesn't think there
    668     # is an escape code following.
    669     $$textref =~ s/\\/\\\\/go;
    670672
    671673    # Convert things like é to their UTF8 equivalents
Note: See TracChangeset for help on using the changeset viewer.