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 $tmpdir = $_[0]->_tmpdir( @ENV{qw(TMPDIR TEMP TMP)},
50 # append a backslash to each argument unless it has one there
51 $_ .= "/" unless m{/$};
53 return $self->canonpath(join('', @args));
57 my ($self,$path) = @_;
58 $path =~ s/^([a-z]:)/\l$1/s;
60 $path =~ s|([^/])/+|$1/|g; # xx////xx -> xx/xx
61 $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx
62 $path =~ s|^(\./)+(?=[^/])||s; # ./xx -> xx
63 $path =~ s|/\Z(?!\n)||
64 unless $path =~ m#^([a-z]:)?/\Z(?!\n)#si;# xx/ -> xx
65 $path =~ s{^/\.\.$}{/}; # /.. -> /
66 1 while $path =~ s{^/\.\.}{}; # /../xx -> /xx
72 my ($self,$path, $nofile) = @_;
73 my ($volume,$directory,$file) = ('','','');
76 m{^( (?:[a-zA-Z]:|(?:\\\\|//)[^\\/]+[\\/][^\\/]+)? )
85 (?:\\\\|//)[^\\/]+[\\/][^\\/]+
88 ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? )
96 return ($volume,$directory,$file);
101 my ($self,$directories) = @_ ;
102 split m|[\\/]|, $directories, -1;
107 my ($self,$volume,$directory,$file) = @_;
109 # If it's UNC, make sure the glue separator is there, reusing
110 # whatever separator is first in the $volume
112 if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s &&
113 $directory =~ m@^[^\\/]@s
116 $volume .= $directory ;
118 # If the volume is not just A:, make sure the glue separator is
119 # there, reusing whatever separator is first in the $volume if possible.
120 if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s &&
121 $volume =~ m@[^\\/]\Z(?!\n)@ &&
124 $volume =~ m@([\\/])@ ;
125 my $sep = $1 ? $1 : '/' ;
136 my($self,$path,$base) = @_;
139 if ( ! $self->file_name_is_absolute( $path ) ) {
140 $path = $self->rel2abs( $path ) ;
142 $path = $self->canonpath( $path ) ;
145 # Figure out the effective $base and clean it up.
146 if ( !defined( $base ) || $base eq '' ) {
147 $base = $self->_cwd();
148 } elsif ( ! $self->file_name_is_absolute( $base ) ) {
149 $base = $self->rel2abs( $base ) ;
151 $base = $self->canonpath( $base ) ;
155 my ( $path_volume, $path_directories, $path_file ) = $self->splitpath( $path, 1 ) ;
156 my ( $base_volume, $base_directories ) = $self->splitpath( $base, 1 ) ;
157 return $path unless $path_volume eq $base_volume;
159 # Now, remove all leading components that are the same
160 my @pathchunks = $self->splitdir( $path_directories );
161 my @basechunks = $self->splitdir( $base_directories );
163 while ( @pathchunks &&
165 lc( $pathchunks[0] ) eq lc( $basechunks[0] )
171 # No need to catdir, we know these are well formed.
172 $path_directories = CORE::join( '/', @pathchunks );
173 $base_directories = CORE::join( '/', @basechunks );
175 # $base_directories now contains the directories the resulting relative
176 # path must ascend out of before it can descend to $path_directory. So,
177 # replace all names with $parentDir
179 #FA Need to replace between backslashes...
180 $base_directories =~ s|[^\\/]+|..|g ;
182 # Glue the two together, using a separator if necessary, and preventing an
185 #FA Must check that new directories are not empty.
186 if ( $path_directories ne '' && $base_directories ne '' ) {
187 $path_directories = "$base_directories/$path_directories" ;
189 $path_directories = "$base_directories$path_directories" ;
192 return $self->canonpath(
193 $self->catpath( "", $path_directories, $path_file )
199 my ($self,$path,$base ) = @_;
201 if ( ! $self->file_name_is_absolute( $path ) ) {
203 if ( !defined( $base ) || $base eq '' ) {
204 $base = $self->_cwd();
206 elsif ( ! $self->file_name_is_absolute( $base ) ) {
207 $base = $self->rel2abs( $base ) ;
210 $base = $self->canonpath( $base ) ;
213 my ( $path_directories, $path_file ) =
214 ($self->splitpath( $path, 1 ))[1,2] ;
216 my ( $base_volume, $base_directories ) =
217 $self->splitpath( $base, 1 ) ;
219 $path = $self->catpath(
221 $self->catdir( $base_directories, $path_directories ),
226 return $self->canonpath( $path ) ;
234 File::Spec::OS2 - methods for OS/2 file specs
238 require File::Spec::OS2; # Done internally by File::Spec if needed
242 See L<File::Spec> and L<File::Spec::Unix>. This package overrides the
243 implementation of these methods, not the semantics.
245 Amongst the changes made for OS/2 are...
251 Modifies the list of places temp directory information is looked for.
261 Volumes can be drive letters or UNC sharenames (\\server\share).
267 Copyright (c) 2004 by the Perl 5 Porters. All rights reserved.
269 This program is free software; you can redistribute it and/or modify
270 it under the same terms as Perl itself.