# $filename = "./ipc/ipc1.htm"; # $file_dir = &dir($filename); $file_dir = "/usr1/www/pages/mhs/psychotherapy/ipc"; $href = "../progs/acroread.exe"; $dir = &expand_dir($file_dir,$href); print "file_dir = $file_dir, href = $href\n"; print " now dir = $dir\n"; sub dir { # returns the directory part of a filename # makes no attempt to check the filename othewise for legality local ($filename) = @_; local ($dir,$slash); $slash = rindex($filename,"/"); if ($slash > 0) { $dir = substr($filename,0,$slash); } else { $dir = "."; } $dir; } sub expand_dir { # expands a relative address supplied as $href # given the directory (".") in $file_dir # will not (at present) deal with a silly reference like "./../filename" # nor will it detect illegal forms like ".../filename" or ".././filename" local ($file_dir,$href) = @_; local ($filename,$dir,$slash); #### first return to calling routine if href is absolute if ($href =~ /^\//) { return ($www_offset.$href); } #### make sure $file_dir doesn't have a trailing slash if ($file_dir =~ m#/$#) { chop($file_dir); } if ($href =~ /\.\./) { @href = split(/\//,$href); @dir = reverse(split(/\//,$file_dir)); $filename = pop(@href); # shift the filename off the end of the href while (@href && ($href[0] eq "..")) { shift(@href); shift(@dir); } @dir = reverse(@dir); $dir = join('/',@dir); $href = join('/',@href); $href = $dir."/".$href."/".$filename; } elsif ($href =~ m#^(\.)/#) { #### is an explicit reference to current directory so replace "." with $file_dir $href =~ s#^.#$file_dir#; } else { #### must be just an implicit reference to current directory so just splice $href = $file_dir."/".$href; } $href; }