1N/Apackage File::Spec::OS2;
1N/A
1N/Ause strict;
1N/Ause vars qw(@ISA $VERSION);
1N/Arequire File::Spec::Unix;
1N/A
1N/A$VERSION = '1.2';
1N/A
1N/A@ISA = qw(File::Spec::Unix);
1N/A
1N/Asub devnull {
1N/A return "/dev/nul";
1N/A}
1N/A
1N/Asub case_tolerant {
1N/A return 1;
1N/A}
1N/A
1N/Asub file_name_is_absolute {
1N/A my ($self,$file) = @_;
1N/A return scalar($file =~ m{^([a-z]:)?[\\/]}is);
1N/A}
1N/A
1N/Asub path {
1N/A my $path = $ENV{PATH};
1N/A $path =~ s:\\:/:g;
1N/A my @path = split(';',$path);
1N/A foreach (@path) { $_ = '.' if $_ eq '' }
1N/A return @path;
1N/A}
1N/A
1N/Asub _cwd {
1N/A # In OS/2 the "require Cwd" is unnecessary bloat.
1N/A return Cwd::sys_cwd();
1N/A}
1N/A
1N/Amy $tmpdir;
1N/Asub tmpdir {
1N/A return $tmpdir if defined $tmpdir;
1N/A my $self = shift;
1N/A $tmpdir = $self->_tmpdir( @ENV{qw(TMPDIR TEMP TMP)},
1N/A '/tmp',
1N/A '/' );
1N/A}
1N/A
1N/Asub catdir {
1N/A my $self = shift;
1N/A my @args = @_;
1N/A foreach (@args) {
1N/A tr[\\][/];
1N/A # append a backslash to each argument unless it has one there
1N/A $_ .= "/" unless m{/$};
1N/A }
1N/A return $self->canonpath(join('', @args));
1N/A}
1N/A
1N/Asub canonpath {
1N/A my ($self,$path) = @_;
1N/A $path =~ s/^([a-z]:)/\l$1/s;
1N/A $path =~ s|\\|/|g;
1N/A $path =~ s|([^/])/+|$1/|g; # xx////xx -> xx/xx
1N/A $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
1N/A $path =~ s|^(\./)+(?=[^/])||s; # ./xx -> xx
1N/A $path =~ s|/\Z(?!\n)||
1N/A unless $path =~ m#^([a-z]:)?/\Z(?!\n)#si;# xx/ -> xx
1N/A $path =~ s{^/\.\.$}{/}; # /.. -> /
1N/A 1 while $path =~ s{^/\.\.}{}; # /../xx -> /xx
1N/A return $path;
1N/A}
1N/A
1N/A
1N/Asub splitpath {
1N/A my ($self,$path, $nofile) = @_;
1N/A my ($volume,$directory,$file) = ('','','');
1N/A if ( $nofile ) {
1N/A $path =~
1N/A m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? )
1N/A (.*)
1N/A }xs;
1N/A $volume = $1;
1N/A $directory = $2;
1N/A }
1N/A else {
1N/A $path =~
1N/A m{^ ( (?: [a-zA-Z]: |
1N/A (?:\\\\|//)[^\\/]+[\\/][^\\/]+
1N/A )?
1N/A )
1N/A ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? )
1N/A (.*)
1N/A }xs;
1N/A $volume = $1;
1N/A $directory = $2;
1N/A $file = $3;
1N/A }
1N/A
1N/A return ($volume,$directory,$file);
1N/A}
1N/A
1N/A
1N/Asub splitdir {
1N/A my ($self,$directories) = @_ ;
1N/A split m|[\\/]|, $directories, -1;
1N/A}
1N/A
1N/A
1N/Asub catpath {
1N/A my ($self,$volume,$directory,$file) = @_;
1N/A
1N/A # If it's UNC, make sure the glue separator is there, reusing
1N/A # whatever separator is first in the $volume
1N/A $volume .= $1
1N/A if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s &&
1N/A $directory =~ m@^[^\\/]@s
1N/A ) ;
1N/A
1N/A $volume .= $directory ;
1N/A
1N/A # If the volume is not just A:, make sure the glue separator is
1N/A # there, reusing whatever separator is first in the $volume if possible.
1N/A if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s &&
1N/A $volume =~ m@[^\\/]\Z(?!\n)@ &&
1N/A $file =~ m@[^\\/]@
1N/A ) {
1N/A $volume =~ m@([\\/])@ ;
1N/A my $sep = $1 ? $1 : '/' ;
1N/A $volume .= $sep ;
1N/A }
1N/A
1N/A $volume .= $file ;
1N/A
1N/A return $volume ;
1N/A}
1N/A
1N/A
1N/Asub abs2rel {
1N/A my($self,$path,$base) = @_;
1N/A
1N/A # Clean up $path
1N/A if ( ! $self->file_name_is_absolute( $path ) ) {
1N/A $path = $self->rel2abs( $path ) ;
1N/A } else {
1N/A $path = $self->canonpath( $path ) ;
1N/A }
1N/A
1N/A # Figure out the effective $base and clean it up.
1N/A if ( !defined( $base ) || $base eq '' ) {
1N/A $base = $self->_cwd();
1N/A } elsif ( ! $self->file_name_is_absolute( $base ) ) {
1N/A $base = $self->rel2abs( $base ) ;
1N/A } else {
1N/A $base = $self->canonpath( $base ) ;
1N/A }
1N/A
1N/A # Split up paths
1N/A my ( $path_volume, $path_directories, $path_file ) = $self->splitpath( $path, 1 ) ;
1N/A my ( $base_volume, $base_directories ) = $self->splitpath( $base, 1 ) ;
1N/A return $path unless $path_volume eq $base_volume;
1N/A
1N/A # Now, remove all leading components that are the same
1N/A my @pathchunks = $self->splitdir( $path_directories );
1N/A my @basechunks = $self->splitdir( $base_directories );
1N/A
1N/A while ( @pathchunks &&
1N/A @basechunks &&
1N/A lc( $pathchunks[0] ) eq lc( $basechunks[0] )
1N/A ) {
1N/A shift @pathchunks ;
1N/A shift @basechunks ;
1N/A }
1N/A
1N/A # No need to catdir, we know these are well formed.
1N/A $path_directories = CORE::join( '/', @pathchunks );
1N/A $base_directories = CORE::join( '/', @basechunks );
1N/A
1N/A # $base_directories now contains the directories the resulting relative
1N/A # path must ascend out of before it can descend to $path_directory. So,
1N/A # replace all names with $parentDir
1N/A
1N/A #FA Need to replace between backslashes...
1N/A $base_directories =~ s|[^\\/]+|..|g ;
1N/A
1N/A # Glue the two together, using a separator if necessary, and preventing an
1N/A # empty result.
1N/A
1N/A #FA Must check that new directories are not empty.
1N/A if ( $path_directories ne '' && $base_directories ne '' ) {
1N/A $path_directories = "$base_directories/$path_directories" ;
1N/A } else {
1N/A $path_directories = "$base_directories$path_directories" ;
1N/A }
1N/A
1N/A return $self->canonpath(
1N/A $self->catpath( "", $path_directories, $path_file )
1N/A ) ;
1N/A}
1N/A
1N/A
1N/Asub rel2abs {
1N/A my ($self,$path,$base ) = @_;
1N/A
1N/A if ( ! $self->file_name_is_absolute( $path ) ) {
1N/A
1N/A if ( !defined( $base ) || $base eq '' ) {
1N/A $base = $self->_cwd();
1N/A }
1N/A elsif ( ! $self->file_name_is_absolute( $base ) ) {
1N/A $base = $self->rel2abs( $base ) ;
1N/A }
1N/A else {
1N/A $base = $self->canonpath( $base ) ;
1N/A }
1N/A
1N/A my ( $path_directories, $path_file ) =
1N/A ($self->splitpath( $path, 1 ))[1,2] ;
1N/A
1N/A my ( $base_volume, $base_directories ) =
1N/A $self->splitpath( $base, 1 ) ;
1N/A
1N/A $path = $self->catpath(
1N/A $base_volume,
1N/A $self->catdir( $base_directories, $path_directories ),
1N/A $path_file
1N/A ) ;
1N/A }
1N/A
1N/A return $self->canonpath( $path ) ;
1N/A}
1N/A
1N/A1;
1N/A__END__
1N/A
1N/A=head1 NAME
1N/A
1N/AFile::Spec::OS2 - methods for OS/2 file specs
1N/A
1N/A=head1 SYNOPSIS
1N/A
1N/A require File::Spec::OS2; # Done internally by File::Spec if needed
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/ASee L<File::Spec> and L<File::Spec::Unix>. This package overrides the
1N/Aimplementation of these methods, not the semantics.
1N/A
1N/AAmongst the changes made for OS/2 are...
1N/A
1N/A=over 4
1N/A
1N/A=item tmpdir
1N/A
1N/AModifies the list of places temp directory information is looked for.
1N/A
1N/A $ENV{TMPDIR}
1N/A $ENV{TEMP}
1N/A $ENV{TMP}
1N/A /tmp
1N/A /
1N/A
1N/A=item splitpath
1N/A
1N/AVolumes can be drive letters or UNC sharenames (\\server\share).
1N/A
1N/A=back
1N/A
1N/A=cut