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)},
51 # append a backslash to each argument unless it has one there
52 $_ .= "/" unless m{/$};
54 return $self->canonpath(join('', @args));
58 my ($self,$path) = @_;
59 $path =~ s/^([a-z]:)/\l$1/s;
61 $path =~ s|([^/])/+|$1/|g; # xx////xx -> xx/xx
62 $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
63 $path =~ s|^(\./)+(?=[^/])||s; # ./xx -> xx
64 $path =~ s|/\Z(?!\n)||
65 unless $path =~ m#^([a-z]:)?/\Z(?!\n)#si;# xx/ -> xx
66 $path =~ s{^/\.\.$}{/}; # /.. -> /
67 1 while $path =~ s{^/\.\.}{}; # /../xx -> /xx
73 my ($self,$path, $nofile) = @_;
74 my ($volume,$directory,$file) = ('','','');
77 m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? )
86 (?:\\\\|//)[^\\/]+[\\/][^\\/]+
89 ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? )
97 return ($volume,$directory,$file);
102 my ($self,$directories) = @_ ;
103 split m|[\\/]|, $directories, -1;
108 my ($self,$volume,$directory,$file) = @_;
110 # If it's UNC, make sure the glue separator is there, reusing
111 # whatever separator is first in the $volume
113 if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s &&
114 $directory =~ m@^[^\\/]@s
117 $volume .= $directory ;
119 # If the volume is not just A:, make sure the glue separator is
120 # there, reusing whatever separator is first in the $volume if possible.
121 if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s &&
122 $volume =~ m@[^\\/]\Z(?!\n)@ &&
125 $volume =~ m@([\\/])@ ;
126 my $sep = $1 ? $1 : '/' ;
137 my($self,$path,$base) = @_;
140 if ( ! $self->file_name_is_absolute( $path ) ) {
141 $path = $self->rel2abs( $path ) ;
143 $path = $self->canonpath( $path ) ;
146 # Figure out the effective $base and clean it up.
147 if ( !defined( $base ) || $base eq '' ) {
148 $base = $self->_cwd();
149 } elsif ( ! $self->file_name_is_absolute( $base ) ) {
150 $base = $self->rel2abs( $base ) ;
152 $base = $self->canonpath( $base ) ;
156 my ( $path_volume, $path_directories, $path_file ) = $self->splitpath( $path, 1 ) ;
157 my ( $base_volume, $base_directories ) = $self->splitpath( $base, 1 ) ;
158 return $path unless $path_volume eq $base_volume;
160 # Now, remove all leading components that are the same
161 my @pathchunks = $self->splitdir( $path_directories );
162 my @basechunks = $self->splitdir( $base_directories );
164 while ( @pathchunks &&
166 lc( $pathchunks[0] ) eq lc( $basechunks[0] )
172 # No need to catdir, we know these are well formed.
173 $path_directories = CORE::join( '/', @pathchunks );
174 $base_directories = CORE::join( '/', @basechunks );
176 # $base_directories now contains the directories the resulting relative
177 # path must ascend out of before it can descend to $path_directory. So,
178 # replace all names with $parentDir
180 #FA Need to replace between backslashes...
181 $base_directories =~ s|[^\\/]+|..|g ;
183 # Glue the two together, using a separator if necessary, and preventing an
186 #FA Must check that new directories are not empty.
187 if ( $path_directories ne '' && $base_directories ne '' ) {
188 $path_directories = "$base_directories/$path_directories" ;
190 $path_directories = "$base_directories$path_directories" ;
193 return $self->canonpath(
194 $self->catpath( "", $path_directories, $path_file )
200 my ($self,$path,$base ) = @_;
202 if ( ! $self->file_name_is_absolute( $path ) ) {
204 if ( !defined( $base ) || $base eq '' ) {
205 $base = $self->_cwd();
207 elsif ( ! $self->file_name_is_absolute( $base ) ) {
208 $base = $self->rel2abs( $base ) ;
211 $base = $self->canonpath( $base ) ;
214 my ( $path_directories, $path_file ) =
215 ($self->splitpath( $path, 1 ))[1,2] ;
217 my ( $base_volume, $base_directories ) =
218 $self->splitpath( $base, 1 ) ;
220 $path = $self->catpath(
222 $self->catdir( $base_directories, $path_directories ),
227 return $self->canonpath( $path ) ;
235 File::Spec::OS2 - methods for OS/2 file specs
239 require File::Spec::OS2; # Done internally by File::Spec if needed
243 See L<File::Spec> and L<File::Spec::Unix>. This package overrides the
244 implementation of these methods, not the semantics.
246 Amongst the changes made for OS/2 are...
252 Modifies the list of places temp directory information is looked for.
262 Volumes can be drive letters or UNC sharenames (\\server\share).