1 package File::Spec::OS2;
4 use vars qw(@ISA $VERSION);
5 require File::Spec::Unix;
10 @ISA = qw(File::Spec::Unix);
20 sub file_name_is_absolute {
21 my ($self,$file) = @_;
22 return scalar($file =~ m{^([a-z]:)?[\\/]}is);
26 my $path = $ENV{PATH};
28 my @path = split(';',$path);
29 foreach (@path) { $_ = '.' if $_ eq '' }
34 # In OS/2 the "require Cwd" is unnecessary bloat.
35 return Cwd::sys_cwd();
39 my $cached = $_[0]->_cached_tmpdir(qw 'TMPDIR TEMP TMP');
40 return $cached if defined $cached;
41 my @d = @ENV{qw(TMPDIR TEMP TMP)}; # function call could autovivivy
43 $_[0]->_tmpdir( @d, '/tmp', '/' ), qw 'TMPDIR TEMP TMP'
52 # append a backslash to each argument unless it has one there
53 $_ .= "/" unless m{/$};
55 return $self->canonpath(join('', @args));
59 my ($self,$path) = @_;
60 return unless defined $path;
62 $path =~ s/^([a-z]:)/\l$1/s;
64 $path =~ s|([^/])/+|$1/|g; # xx////xx -> xx/xx
65 $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
66 $path =~ s|^(\./)+(?=[^/])||s; # ./xx -> xx
67 $path =~ s|/\Z(?!\n)||
68 unless $path =~ m#^([a-z]:)?/\Z(?!\n)#si;# xx/ -> xx
69 $path =~ s{^/\.\.$}{/}; # /.. -> /
70 1 while $path =~ s{^/\.\.}{}; # /../xx -> /xx
76 my ($self,$path, $nofile) = @_;
77 my ($volume,$directory,$file) = ('','','');
80 m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? )
89 (?:\\\\|//)[^\\/]+[\\/][^\\/]+
92 ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? )
100 return ($volume,$directory,$file);
105 my ($self,$directories) = @_ ;
106 split m|[\\/]|, $directories, -1;
111 my ($self,$volume,$directory,$file) = @_;
113 # If it's UNC, make sure the glue separator is there, reusing
114 # whatever separator is first in the $volume
116 if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s &&
117 $directory =~ m@^[^\\/]@s
120 $volume .= $directory ;
122 # If the volume is not just A:, make sure the glue separator is
123 # there, reusing whatever separator is first in the $volume if possible.
124 if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s &&
125 $volume =~ m@[^\\/]\Z(?!\n)@ &&
128 $volume =~ m@([\\/])@ ;
129 my $sep = $1 ? $1 : '/' ;
140 my($self,$path,$base) = @_;
143 if ( ! $self->file_name_is_absolute( $path ) ) {
144 $path = $self->rel2abs( $path ) ;
146 $path = $self->canonpath( $path ) ;
149 # Figure out the effective $base and clean it up.
150 if ( !defined( $base ) || $base eq '' ) {
151 $base = $self->_cwd();
152 } elsif ( ! $self->file_name_is_absolute( $base ) ) {
153 $base = $self->rel2abs( $base ) ;
155 $base = $self->canonpath( $base ) ;
159 my ( $path_volume, $path_directories, $path_file ) = $self->splitpath( $path, 1 ) ;
160 my ( $base_volume, $base_directories ) = $self->splitpath( $base, 1 ) ;
161 return $path unless $path_volume eq $base_volume;
163 # Now, remove all leading components that are the same
164 my @pathchunks = $self->splitdir( $path_directories );
165 my @basechunks = $self->splitdir( $base_directories );
167 while ( @pathchunks &&
169 lc( $pathchunks[0] ) eq lc( $basechunks[0] )
175 # No need to catdir, we know these are well formed.
176 $path_directories = CORE::join( '/', @pathchunks );
177 $base_directories = CORE::join( '/', @basechunks );
179 # $base_directories now contains the directories the resulting relative
180 # path must ascend out of before it can descend to $path_directory. So,
181 # replace all names with $parentDir
183 #FA Need to replace between backslashes...
184 $base_directories =~ s|[^\\/]+|..|g ;
186 # Glue the two together, using a separator if necessary, and preventing an
189 #FA Must check that new directories are not empty.
190 if ( $path_directories ne '' && $base_directories ne '' ) {
191 $path_directories = "$base_directories/$path_directories" ;
193 $path_directories = "$base_directories$path_directories" ;
196 return $self->canonpath(
197 $self->catpath( "", $path_directories, $path_file )
203 my ($self,$path,$base ) = @_;
205 if ( ! $self->file_name_is_absolute( $path ) ) {
207 if ( !defined( $base ) || $base eq '' ) {
208 $base = $self->_cwd();
210 elsif ( ! $self->file_name_is_absolute( $base ) ) {
211 $base = $self->rel2abs( $base ) ;
214 $base = $self->canonpath( $base ) ;
217 my ( $path_directories, $path_file ) =
218 ($self->splitpath( $path, 1 ))[1,2] ;
220 my ( $base_volume, $base_directories ) =
221 $self->splitpath( $base, 1 ) ;
223 $path = $self->catpath(
225 $self->catdir( $base_directories, $path_directories ),
230 return $self->canonpath( $path ) ;
238 File::Spec::OS2 - methods for OS/2 file specs
242 require File::Spec::OS2; # Done internally by File::Spec if needed
246 See L<File::Spec> and L<File::Spec::Unix>. This package overrides the
247 implementation of these methods, not the semantics.
249 Amongst the changes made for OS/2 are...
255 Modifies the list of places temp directory information is looked for.
265 Volumes can be drive letters or UNC sharenames (\\server\share).
271 Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.
273 This program is free software; you can redistribute it and/or modify
274 it under the same terms as Perl itself.