1 package File::Spec::OS2;
4 use vars qw(@ISA $VERSION);
5 require File::Spec::Unix;
9 @ISA = qw(File::Spec::Unix);
19 sub file_name_is_absolute {
20 my ($self,$file) = @_;
21 return scalar($file =~ m{^([a-z]:)?[\\/]}is);
25 my $path = $ENV{PATH};
27 my @path = split(';',$path);
28 foreach (@path) { $_ = '.' if $_ eq '' }
33 # In OS/2 the "require Cwd" is unnecessary bloat.
34 return Cwd::sys_cwd();
39 return $tmpdir if defined $tmpdir;
40 my @d = @ENV{qw(TMPDIR TEMP TMP)}; # function call could autovivivy
41 $tmpdir = $_[0]->_tmpdir( @d, '/tmp', '/' );
49 # append a backslash to each argument unless it has one there
50 $_ .= "/" unless m{/$};
52 return $self->canonpath(join('', @args));
56 my ($self,$path) = @_;
57 $path =~ s/^([a-z]:)/\l$1/s;
59 $path =~ s|([^/])/+|$1/|g; # xx////xx -> xx/xx
60 $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
61 $path =~ s|^(\./)+(?=[^/])||s; # ./xx -> xx
62 $path =~ s|/\Z(?!\n)||
63 unless $path =~ m#^([a-z]:)?/\Z(?!\n)#si;# xx/ -> xx
64 $path =~ s{^/\.\.$}{/}; # /.. -> /
65 1 while $path =~ s{^/\.\.}{}; # /../xx -> /xx
71 my ($self,$path, $nofile) = @_;
72 my ($volume,$directory,$file) = ('','','');
75 m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? )
84 (?:\\\\|//)[^\\/]+[\\/][^\\/]+
87 ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? )
95 return ($volume,$directory,$file);
100 my ($self,$directories) = @_ ;
101 split m|[\\/]|, $directories, -1;
106 my ($self,$volume,$directory,$file) = @_;
108 # If it's UNC, make sure the glue separator is there, reusing
109 # whatever separator is first in the $volume
111 if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s &&
112 $directory =~ m@^[^\\/]@s
115 $volume .= $directory ;
117 # If the volume is not just A:, make sure the glue separator is
118 # there, reusing whatever separator is first in the $volume if possible.
119 if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s &&
120 $volume =~ m@[^\\/]\Z(?!\n)@ &&
123 $volume =~ m@([\\/])@ ;
124 my $sep = $1 ? $1 : '/' ;
135 my($self,$path,$base) = @_;
138 if ( ! $self->file_name_is_absolute( $path ) ) {
139 $path = $self->rel2abs( $path ) ;
141 $path = $self->canonpath( $path ) ;
144 # Figure out the effective $base and clean it up.
145 if ( !defined( $base ) || $base eq '' ) {
146 $base = $self->_cwd();
147 } elsif ( ! $self->file_name_is_absolute( $base ) ) {
148 $base = $self->rel2abs( $base ) ;
150 $base = $self->canonpath( $base ) ;
154 my ( $path_volume, $path_directories, $path_file ) = $self->splitpath( $path, 1 ) ;
155 my ( $base_volume, $base_directories ) = $self->splitpath( $base, 1 ) ;
156 return $path unless $path_volume eq $base_volume;
158 # Now, remove all leading components that are the same
159 my @pathchunks = $self->splitdir( $path_directories );
160 my @basechunks = $self->splitdir( $base_directories );
162 while ( @pathchunks &&
164 lc( $pathchunks[0] ) eq lc( $basechunks[0] )
170 # No need to catdir, we know these are well formed.
171 $path_directories = CORE::join( '/', @pathchunks );
172 $base_directories = CORE::join( '/', @basechunks );
174 # $base_directories now contains the directories the resulting relative
175 # path must ascend out of before it can descend to $path_directory. So,
176 # replace all names with $parentDir
178 #FA Need to replace between backslashes...
179 $base_directories =~ s|[^\\/]+|..|g ;
181 # Glue the two together, using a separator if necessary, and preventing an
184 #FA Must check that new directories are not empty.
185 if ( $path_directories ne '' && $base_directories ne '' ) {
186 $path_directories = "$base_directories/$path_directories" ;
188 $path_directories = "$base_directories$path_directories" ;
191 return $self->canonpath(
192 $self->catpath( "", $path_directories, $path_file )
198 my ($self,$path,$base ) = @_;
200 if ( ! $self->file_name_is_absolute( $path ) ) {
202 if ( !defined( $base ) || $base eq '' ) {
203 $base = $self->_cwd();
205 elsif ( ! $self->file_name_is_absolute( $base ) ) {
206 $base = $self->rel2abs( $base ) ;
209 $base = $self->canonpath( $base ) ;
212 my ( $path_directories, $path_file ) =
213 ($self->splitpath( $path, 1 ))[1,2] ;
215 my ( $base_volume, $base_directories ) =
216 $self->splitpath( $base, 1 ) ;
218 $path = $self->catpath(
220 $self->catdir( $base_directories, $path_directories ),
225 return $self->canonpath( $path ) ;
233 File::Spec::OS2 - methods for OS/2 file specs
237 require File::Spec::OS2; # Done internally by File::Spec if needed
241 See L<File::Spec> and L<File::Spec::Unix>. This package overrides the
242 implementation of these methods, not the semantics.
244 Amongst the changes made for OS/2 are...
250 Modifies the list of places temp directory information is looked for.
260 Volumes can be drive letters or UNC sharenames (\\server\share).
266 Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.
268 This program is free software; you can redistribute it and/or modify
269 it under the same terms as Perl itself.