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;
41 $tmpdir = $self->_tmpdir( @ENV{qw(TMPDIR TEMP TMP)},
47 my ($self,$path) = @_;
48 $path =~ s/^([a-z]:)/\l$1/s;
50 $path =~ s|([^/])/+|$1/|g; # xx////xx -> xx/xx
51 $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
52 $path =~ s|^(\./)+(?=[^/])||s; # ./xx -> xx
53 $path =~ s|/\Z(?!\n)||
54 unless $path =~ m#^([a-z]:)?/\Z(?!\n)#si;# xx/ -> xx
60 my ($self,$path, $nofile) = @_;
61 my ($volume,$directory,$file) = ('','','');
64 m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? )
73 (?:\\\\|//)[^\\/]+[\\/][^\\/]+
76 ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? )
84 return ($volume,$directory,$file);
89 my ($self,$directories) = @_ ;
90 split m|[\\/]|, $directories, -1;
95 my ($self,$volume,$directory,$file) = @_;
97 # If it's UNC, make sure the glue separator is there, reusing
98 # whatever separator is first in the $volume
100 if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s &&
101 $directory =~ m@^[^\\/]@s
104 $volume .= $directory ;
106 # If the volume is not just A:, make sure the glue separator is
107 # there, reusing whatever separator is first in the $volume if possible.
108 if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s &&
109 $volume =~ m@[^\\/]\Z(?!\n)@ &&
112 $volume =~ m@([\\/])@ ;
113 my $sep = $1 ? $1 : '/' ;
124 my($self,$path,$base) = @_;
127 if ( ! $self->file_name_is_absolute( $path ) ) {
128 $path = $self->rel2abs( $path ) ;
130 $path = $self->canonpath( $path ) ;
133 # Figure out the effective $base and clean it up.
134 if ( !defined( $base ) || $base eq '' ) {
135 $base = $self->_cwd();
136 } elsif ( ! $self->file_name_is_absolute( $base ) ) {
137 $base = $self->rel2abs( $base ) ;
139 $base = $self->canonpath( $base ) ;
143 my ( undef, $path_directories, $path_file ) =
144 $self->splitpath( $path, 1 ) ;
146 my $base_directories = ($self->splitpath( $base, 1 ))[1] ;
148 # Now, remove all leading components that are the same
149 my @pathchunks = $self->splitdir( $path_directories );
150 my @basechunks = $self->splitdir( $base_directories );
152 while ( @pathchunks &&
154 lc( $pathchunks[0] ) eq lc( $basechunks[0] )
160 # No need to catdir, we know these are well formed.
161 $path_directories = CORE::join( '/', @pathchunks );
162 $base_directories = CORE::join( '/', @basechunks );
164 # $base_directories now contains the directories the resulting relative
165 # path must ascend out of before it can descend to $path_directory. So,
166 # replace all names with $parentDir
168 #FA Need to replace between backslashes...
169 $base_directories =~ s|[^\\/]+|..|g ;
171 # Glue the two together, using a separator if necessary, and preventing an
174 #FA Must check that new directories are not empty.
175 if ( $path_directories ne '' && $base_directories ne '' ) {
176 $path_directories = "$base_directories/$path_directories" ;
178 $path_directories = "$base_directories$path_directories" ;
181 return $self->canonpath(
182 $self->catpath( "", $path_directories, $path_file )
188 my ($self,$path,$base ) = @_;
190 if ( ! $self->file_name_is_absolute( $path ) ) {
192 if ( !defined( $base ) || $base eq '' ) {
193 $base = $self->_cwd();
195 elsif ( ! $self->file_name_is_absolute( $base ) ) {
196 $base = $self->rel2abs( $base ) ;
199 $base = $self->canonpath( $base ) ;
202 my ( $path_directories, $path_file ) =
203 ($self->splitpath( $path, 1 ))[1,2] ;
205 my ( $base_volume, $base_directories ) =
206 $self->splitpath( $base, 1 ) ;
208 $path = $self->catpath(
210 $self->catdir( $base_directories, $path_directories ),
215 return $self->canonpath( $path ) ;
223 File::Spec::OS2 - methods for OS/2 file specs
227 require File::Spec::OS2; # Done internally by File::Spec if needed
231 See L<File::Spec> and L<File::Spec::Unix>. This package overrides the
232 implementation of these methods, not the semantics.
234 Amongst the changes made for OS/2 are...
240 Modifies the list of places temp directory information is looked for.
250 Volumes can be drive letters or UNC sharenames (\\server\share).