1*0Sstevel@tonic-gatepackage File::Spec::VMS; 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateuse strict; 4*0Sstevel@tonic-gateuse vars qw(@ISA $VERSION); 5*0Sstevel@tonic-gaterequire File::Spec::Unix; 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gate$VERSION = '1.4'; 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gate@ISA = qw(File::Spec::Unix); 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gateuse File::Basename; 12*0Sstevel@tonic-gateuse VMS::Filespec; 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate=head1 NAME 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gateFile::Spec::VMS - methods for VMS file specs 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate=head1 SYNOPSIS 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gate require File::Spec::VMS; # Done internally by File::Spec if needed 21*0Sstevel@tonic-gate 22*0Sstevel@tonic-gate=head1 DESCRIPTION 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gateSee File::Spec::Unix for a documentation of the methods provided 25*0Sstevel@tonic-gatethere. This package overrides the implementation of these methods, not 26*0Sstevel@tonic-gatethe semantics. 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate=over 4 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate=item eliminate_macros 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gateExpands MM[KS]/Make macros in a text string, using the contents of 33*0Sstevel@tonic-gateidentically named elements of C<%$self>, and returns the result 34*0Sstevel@tonic-gateas a file specification in Unix syntax. 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate=cut 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gatesub eliminate_macros { 39*0Sstevel@tonic-gate my($self,$path) = @_; 40*0Sstevel@tonic-gate return '' unless $path; 41*0Sstevel@tonic-gate $self = {} unless ref $self; 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate if ($path =~ /\s/) { 44*0Sstevel@tonic-gate return join ' ', map { $self->eliminate_macros($_) } split /\s+/, $path; 45*0Sstevel@tonic-gate } 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate my($npath) = unixify($path); 48*0Sstevel@tonic-gate my($complex) = 0; 49*0Sstevel@tonic-gate my($head,$macro,$tail); 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate # perform m##g in scalar context so it acts as an iterator 52*0Sstevel@tonic-gate while ($npath =~ m#(.*?)\$\((\S+?)\)(.*)#gs) { 53*0Sstevel@tonic-gate if ($self->{$2}) { 54*0Sstevel@tonic-gate ($head,$macro,$tail) = ($1,$2,$3); 55*0Sstevel@tonic-gate if (ref $self->{$macro}) { 56*0Sstevel@tonic-gate if (ref $self->{$macro} eq 'ARRAY') { 57*0Sstevel@tonic-gate $macro = join ' ', @{$self->{$macro}}; 58*0Sstevel@tonic-gate } 59*0Sstevel@tonic-gate else { 60*0Sstevel@tonic-gate print "Note: can't expand macro \$($macro) containing ",ref($self->{$macro}), 61*0Sstevel@tonic-gate "\n\t(using MMK-specific deferred substitutuon; MMS will break)\n"; 62*0Sstevel@tonic-gate $macro = "\cB$macro\cB"; 63*0Sstevel@tonic-gate $complex = 1; 64*0Sstevel@tonic-gate } 65*0Sstevel@tonic-gate } 66*0Sstevel@tonic-gate else { ($macro = unixify($self->{$macro})) =~ s#/\Z(?!\n)##; } 67*0Sstevel@tonic-gate $npath = "$head$macro$tail"; 68*0Sstevel@tonic-gate } 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate if ($complex) { $npath =~ s#\cB(.*?)\cB#\${$1}#gs; } 71*0Sstevel@tonic-gate $npath; 72*0Sstevel@tonic-gate} 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate=item fixpath 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gateCatchall routine to clean up problem MM[SK]/Make macros. Expands macros 77*0Sstevel@tonic-gatein any directory specification, in order to avoid juxtaposing two 78*0Sstevel@tonic-gateVMS-syntax directories when MM[SK] is run. Also expands expressions which 79*0Sstevel@tonic-gateare all macro, so that we can tell how long the expansion is, and avoid 80*0Sstevel@tonic-gateoverrunning DCL's command buffer when MM[KS] is running. 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gateIf optional second argument has a TRUE value, then the return string is 83*0Sstevel@tonic-gatea VMS-syntax directory specification, if it is FALSE, the return string 84*0Sstevel@tonic-gateis a VMS-syntax file specification, and if it is not specified, fixpath() 85*0Sstevel@tonic-gatechecks to see whether it matches the name of a directory in the current 86*0Sstevel@tonic-gatedefault directory, and returns a directory or file specification accordingly. 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate=cut 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gatesub fixpath { 91*0Sstevel@tonic-gate my($self,$path,$force_path) = @_; 92*0Sstevel@tonic-gate return '' unless $path; 93*0Sstevel@tonic-gate $self = bless {} unless ref $self; 94*0Sstevel@tonic-gate my($fixedpath,$prefix,$name); 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate if ($path =~ /\s/) { 97*0Sstevel@tonic-gate return join ' ', 98*0Sstevel@tonic-gate map { $self->fixpath($_,$force_path) } 99*0Sstevel@tonic-gate split /\s+/, $path; 100*0Sstevel@tonic-gate } 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate if ($path =~ m#^\$\([^\)]+\)\Z(?!\n)#s || $path =~ m#[/:>\]]#) { 103*0Sstevel@tonic-gate if ($force_path or $path =~ /(?:DIR\)|\])\Z(?!\n)/) { 104*0Sstevel@tonic-gate $fixedpath = vmspath($self->eliminate_macros($path)); 105*0Sstevel@tonic-gate } 106*0Sstevel@tonic-gate else { 107*0Sstevel@tonic-gate $fixedpath = vmsify($self->eliminate_macros($path)); 108*0Sstevel@tonic-gate } 109*0Sstevel@tonic-gate } 110*0Sstevel@tonic-gate elsif ((($prefix,$name) = ($path =~ m#^\$\(([^\)]+)\)(.+)#s)) && $self->{$prefix}) { 111*0Sstevel@tonic-gate my($vmspre) = $self->eliminate_macros("\$($prefix)"); 112*0Sstevel@tonic-gate # is it a dir or just a name? 113*0Sstevel@tonic-gate $vmspre = ($vmspre =~ m|/| or $prefix =~ /DIR\Z(?!\n)/) ? vmspath($vmspre) : ''; 114*0Sstevel@tonic-gate $fixedpath = ($vmspre ? $vmspre : $self->{$prefix}) . $name; 115*0Sstevel@tonic-gate $fixedpath = vmspath($fixedpath) if $force_path; 116*0Sstevel@tonic-gate } 117*0Sstevel@tonic-gate else { 118*0Sstevel@tonic-gate $fixedpath = $path; 119*0Sstevel@tonic-gate $fixedpath = vmspath($fixedpath) if $force_path; 120*0Sstevel@tonic-gate } 121*0Sstevel@tonic-gate # No hints, so we try to guess 122*0Sstevel@tonic-gate if (!defined($force_path) and $fixedpath !~ /[:>(.\]]/) { 123*0Sstevel@tonic-gate $fixedpath = vmspath($fixedpath) if -d $fixedpath; 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate # Trim off root dirname if it's had other dirs inserted in front of it. 127*0Sstevel@tonic-gate $fixedpath =~ s/\.000000([\]>])/$1/; 128*0Sstevel@tonic-gate # Special case for VMS absolute directory specs: these will have had device 129*0Sstevel@tonic-gate # prepended during trip through Unix syntax in eliminate_macros(), since 130*0Sstevel@tonic-gate # Unix syntax has no way to express "absolute from the top of this device's 131*0Sstevel@tonic-gate # directory tree". 132*0Sstevel@tonic-gate if ($path =~ /^[\[>][^.\-]/) { $fixedpath =~ s/^[^\[<]+//; } 133*0Sstevel@tonic-gate $fixedpath; 134*0Sstevel@tonic-gate} 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate=back 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate=head2 Methods always loaded 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate=over 4 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate=item canonpath (override) 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gateRemoves redundant portions of file specifications according to VMS syntax. 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate=cut 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gatesub canonpath { 149*0Sstevel@tonic-gate my($self,$path) = @_; 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate if ($path =~ m|/|) { # Fake Unix 152*0Sstevel@tonic-gate my $pathify = $path =~ m|/\Z(?!\n)|; 153*0Sstevel@tonic-gate $path = $self->SUPER::canonpath($path); 154*0Sstevel@tonic-gate if ($pathify) { return vmspath($path); } 155*0Sstevel@tonic-gate else { return vmsify($path); } 156*0Sstevel@tonic-gate } 157*0Sstevel@tonic-gate else { 158*0Sstevel@tonic-gate $path =~ s/([\[<])000000\./$1/g; # [000000.foo ==> [foo 159*0Sstevel@tonic-gate $path =~ s/([^-]+)\.(\]\[|><)?000000([\]\>])/$1$3/g; # foo.000000] ==> foo] 160*0Sstevel@tonic-gate $path =~ s-\]\[--g; $path =~ s/><//g; # foo.][bar ==> foo.bar 161*0Sstevel@tonic-gate 1 while $path =~ s{([\[<-])\.-}{$1-}; # [.-.- ==> [-- 162*0Sstevel@tonic-gate $path =~ s/\.[^\[<\.]+\.-([\]\>])/$1/; # bar.foo.-] ==> bar] 163*0Sstevel@tonic-gate $path =~ s/([\[<])(-+)/$1 . "\cx" x length($2)/e; # encode leading '-'s 164*0Sstevel@tonic-gate $path =~ s/([\[<\.])([^\[<\.\cx]+)\.-\.?/$1/g; # bar.-.foo ==> foo 165*0Sstevel@tonic-gate $path =~ s/([\[<])(\cx+)/$1 . '-' x length($2)/e; # then decode 166*0Sstevel@tonic-gate $path =~ s/^[\[<\]>]{2}//; # []foo ==> foo 167*0Sstevel@tonic-gate return $path; 168*0Sstevel@tonic-gate } 169*0Sstevel@tonic-gate} 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate=item catdir 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gateConcatenates a list of file specifications, and returns the result as a 174*0Sstevel@tonic-gateVMS-syntax directory specification. No check is made for "impossible" 175*0Sstevel@tonic-gatecases (e.g. elements other than the first being absolute filespecs). 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate=cut 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gatesub catdir { 180*0Sstevel@tonic-gate my ($self,@dirs) = @_; 181*0Sstevel@tonic-gate my $dir = pop @dirs; 182*0Sstevel@tonic-gate @dirs = grep($_,@dirs); 183*0Sstevel@tonic-gate my $rslt; 184*0Sstevel@tonic-gate if (@dirs) { 185*0Sstevel@tonic-gate my $path = (@dirs == 1 ? $dirs[0] : $self->catdir(@dirs)); 186*0Sstevel@tonic-gate my ($spath,$sdir) = ($path,$dir); 187*0Sstevel@tonic-gate $spath =~ s/\.dir\Z(?!\n)//; $sdir =~ s/\.dir\Z(?!\n)//; 188*0Sstevel@tonic-gate $sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+\Z(?!\n)/s; 189*0Sstevel@tonic-gate $rslt = $self->fixpath($self->eliminate_macros($spath)."/$sdir",1); 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate # Special case for VMS absolute directory specs: these will have had device 192*0Sstevel@tonic-gate # prepended during trip through Unix syntax in eliminate_macros(), since 193*0Sstevel@tonic-gate # Unix syntax has no way to express "absolute from the top of this device's 194*0Sstevel@tonic-gate # directory tree". 195*0Sstevel@tonic-gate if ($spath =~ /^[\[<][^.\-]/s) { $rslt =~ s/^[^\[<]+//s; } 196*0Sstevel@tonic-gate } 197*0Sstevel@tonic-gate else { 198*0Sstevel@tonic-gate if (not defined $dir or not length $dir) { $rslt = ''; } 199*0Sstevel@tonic-gate elsif ($dir =~ /^\$\([^\)]+\)\Z(?!\n)/s) { $rslt = $dir; } 200*0Sstevel@tonic-gate else { $rslt = vmspath($dir); } 201*0Sstevel@tonic-gate } 202*0Sstevel@tonic-gate return $self->canonpath($rslt); 203*0Sstevel@tonic-gate} 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate=item catfile 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gateConcatenates a list of file specifications, and returns the result as a 208*0Sstevel@tonic-gateVMS-syntax file specification. 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate=cut 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gatesub catfile { 213*0Sstevel@tonic-gate my ($self,@files) = @_; 214*0Sstevel@tonic-gate my $file = $self->canonpath(pop @files); 215*0Sstevel@tonic-gate @files = grep($_,@files); 216*0Sstevel@tonic-gate my $rslt; 217*0Sstevel@tonic-gate if (@files) { 218*0Sstevel@tonic-gate my $path = (@files == 1 ? $files[0] : $self->catdir(@files)); 219*0Sstevel@tonic-gate my $spath = $path; 220*0Sstevel@tonic-gate $spath =~ s/\.dir\Z(?!\n)//; 221*0Sstevel@tonic-gate if ($spath =~ /^[^\)\]\/:>]+\)\Z(?!\n)/s && basename($file) eq $file) { 222*0Sstevel@tonic-gate $rslt = "$spath$file"; 223*0Sstevel@tonic-gate } 224*0Sstevel@tonic-gate else { 225*0Sstevel@tonic-gate $rslt = $self->eliminate_macros($spath); 226*0Sstevel@tonic-gate $rslt = vmsify($rslt.($rslt ? '/' : '').unixify($file)); 227*0Sstevel@tonic-gate } 228*0Sstevel@tonic-gate } 229*0Sstevel@tonic-gate else { $rslt = (defined($file) && length($file)) ? vmsify($file) : ''; } 230*0Sstevel@tonic-gate return $self->canonpath($rslt); 231*0Sstevel@tonic-gate} 232*0Sstevel@tonic-gate 233*0Sstevel@tonic-gate 234*0Sstevel@tonic-gate=item curdir (override) 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gateReturns a string representation of the current directory: '[]' 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gate=cut 239*0Sstevel@tonic-gate 240*0Sstevel@tonic-gatesub curdir { 241*0Sstevel@tonic-gate return '[]'; 242*0Sstevel@tonic-gate} 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate=item devnull (override) 245*0Sstevel@tonic-gate 246*0Sstevel@tonic-gateReturns a string representation of the null device: '_NLA0:' 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gate=cut 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gatesub devnull { 251*0Sstevel@tonic-gate return "_NLA0:"; 252*0Sstevel@tonic-gate} 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate=item rootdir (override) 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gateReturns a string representation of the root directory: 'SYS$DISK:[000000]' 257*0Sstevel@tonic-gate 258*0Sstevel@tonic-gate=cut 259*0Sstevel@tonic-gate 260*0Sstevel@tonic-gatesub rootdir { 261*0Sstevel@tonic-gate return 'SYS$DISK:[000000]'; 262*0Sstevel@tonic-gate} 263*0Sstevel@tonic-gate 264*0Sstevel@tonic-gate=item tmpdir (override) 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gateReturns a string representation of the first writable directory 267*0Sstevel@tonic-gatefrom the following list or '' if none are writable: 268*0Sstevel@tonic-gate 269*0Sstevel@tonic-gate sys$scratch: 270*0Sstevel@tonic-gate $ENV{TMPDIR} 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gateSince perl 5.8.0, if running under taint mode, and if $ENV{TMPDIR} 273*0Sstevel@tonic-gateis tainted, it is not used. 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate=cut 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gatemy $tmpdir; 278*0Sstevel@tonic-gatesub tmpdir { 279*0Sstevel@tonic-gate return $tmpdir if defined $tmpdir; 280*0Sstevel@tonic-gate my $self = shift; 281*0Sstevel@tonic-gate $tmpdir = $self->_tmpdir( 'sys$scratch:', $ENV{TMPDIR} ); 282*0Sstevel@tonic-gate} 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gate=item updir (override) 285*0Sstevel@tonic-gate 286*0Sstevel@tonic-gateReturns a string representation of the parent directory: '[-]' 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate=cut 289*0Sstevel@tonic-gate 290*0Sstevel@tonic-gatesub updir { 291*0Sstevel@tonic-gate return '[-]'; 292*0Sstevel@tonic-gate} 293*0Sstevel@tonic-gate 294*0Sstevel@tonic-gate=item case_tolerant (override) 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gateVMS file specification syntax is case-tolerant. 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gate=cut 299*0Sstevel@tonic-gate 300*0Sstevel@tonic-gatesub case_tolerant { 301*0Sstevel@tonic-gate return 1; 302*0Sstevel@tonic-gate} 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate=item path (override) 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gateTranslate logical name DCL$PATH as a searchlist, rather than trying 307*0Sstevel@tonic-gateto C<split> string value of C<$ENV{'PATH'}>. 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate=cut 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gatesub path { 312*0Sstevel@tonic-gate my (@dirs,$dir,$i); 313*0Sstevel@tonic-gate while ($dir = $ENV{'DCL$PATH;' . $i++}) { push(@dirs,$dir); } 314*0Sstevel@tonic-gate return @dirs; 315*0Sstevel@tonic-gate} 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gate=item file_name_is_absolute (override) 318*0Sstevel@tonic-gate 319*0Sstevel@tonic-gateChecks for VMS directory spec as well as Unix separators. 320*0Sstevel@tonic-gate 321*0Sstevel@tonic-gate=cut 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gatesub file_name_is_absolute { 324*0Sstevel@tonic-gate my ($self,$file) = @_; 325*0Sstevel@tonic-gate # If it's a logical name, expand it. 326*0Sstevel@tonic-gate $file = $ENV{$file} while $file =~ /^[\w\$\-]+\Z(?!\n)/s && $ENV{$file}; 327*0Sstevel@tonic-gate return scalar($file =~ m!^/!s || 328*0Sstevel@tonic-gate $file =~ m![<\[][^.\-\]>]! || 329*0Sstevel@tonic-gate $file =~ /:[^<\[]/); 330*0Sstevel@tonic-gate} 331*0Sstevel@tonic-gate 332*0Sstevel@tonic-gate=item splitpath (override) 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gateSplits using VMS syntax. 335*0Sstevel@tonic-gate 336*0Sstevel@tonic-gate=cut 337*0Sstevel@tonic-gate 338*0Sstevel@tonic-gatesub splitpath { 339*0Sstevel@tonic-gate my($self,$path) = @_; 340*0Sstevel@tonic-gate my($dev,$dir,$file) = ('','',''); 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate vmsify($path) =~ /(.+:)?([\[<].*[\]>])?(.*)/s; 343*0Sstevel@tonic-gate return ($1 || '',$2 || '',$3); 344*0Sstevel@tonic-gate} 345*0Sstevel@tonic-gate 346*0Sstevel@tonic-gate=item splitdir (override) 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gateSplit dirspec using VMS syntax. 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gate=cut 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gatesub splitdir { 353*0Sstevel@tonic-gate my($self,$dirspec) = @_; 354*0Sstevel@tonic-gate $dirspec =~ s/\]\[//g; $dirspec =~ s/\-\-/-.-/g; 355*0Sstevel@tonic-gate $dirspec = "[$dirspec]" unless $dirspec =~ /[\[<]/; # make legal 356*0Sstevel@tonic-gate my(@dirs) = split('\.', vmspath($dirspec)); 357*0Sstevel@tonic-gate $dirs[0] =~ s/^[\[<]//s; $dirs[-1] =~ s/[\]>]\Z(?!\n)//s; 358*0Sstevel@tonic-gate @dirs; 359*0Sstevel@tonic-gate} 360*0Sstevel@tonic-gate 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate=item catpath (override) 363*0Sstevel@tonic-gate 364*0Sstevel@tonic-gateConstruct a complete filespec using VMS syntax 365*0Sstevel@tonic-gate 366*0Sstevel@tonic-gate=cut 367*0Sstevel@tonic-gate 368*0Sstevel@tonic-gatesub catpath { 369*0Sstevel@tonic-gate my($self,$dev,$dir,$file) = @_; 370*0Sstevel@tonic-gate 371*0Sstevel@tonic-gate # We look for a volume in $dev, then in $dir, but not both 372*0Sstevel@tonic-gate my ($dir_volume, $dir_dir, $dir_file) = $self->splitpath($dir); 373*0Sstevel@tonic-gate $dev = $dir_volume unless length $dev; 374*0Sstevel@tonic-gate $dir = length $dir_file ? $self->catfile($dir_dir, $dir_file) : $dir_dir; 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate if ($dev =~ m|^/+([^/]+)|) { $dev = "$1:"; } 377*0Sstevel@tonic-gate else { $dev .= ':' unless $dev eq '' or $dev =~ /:\Z(?!\n)/; } 378*0Sstevel@tonic-gate if (length($dev) or length($dir)) { 379*0Sstevel@tonic-gate $dir = "[$dir]" unless $dir =~ /[\[<\/]/; 380*0Sstevel@tonic-gate $dir = vmspath($dir); 381*0Sstevel@tonic-gate } 382*0Sstevel@tonic-gate "$dev$dir$file"; 383*0Sstevel@tonic-gate} 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate=item abs2rel (override) 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gateUse VMS syntax when converting filespecs. 388*0Sstevel@tonic-gate 389*0Sstevel@tonic-gate=cut 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gatesub abs2rel { 392*0Sstevel@tonic-gate my $self = shift; 393*0Sstevel@tonic-gate return vmspath(File::Spec::Unix::abs2rel( $self, @_ )) 394*0Sstevel@tonic-gate if grep m{/}, @_; 395*0Sstevel@tonic-gate 396*0Sstevel@tonic-gate my($path,$base) = @_; 397*0Sstevel@tonic-gate $base = $self->_cwd() unless defined $base and length $base; 398*0Sstevel@tonic-gate 399*0Sstevel@tonic-gate for ($path, $base) { $_ = $self->canonpath($_) } 400*0Sstevel@tonic-gate 401*0Sstevel@tonic-gate # Are we even starting $path on the same (node::)device as $base? Note that 402*0Sstevel@tonic-gate # logical paths or nodename differences may be on the "same device" 403*0Sstevel@tonic-gate # but the comparison that ignores device differences so as to concatenate 404*0Sstevel@tonic-gate # [---] up directory specs is not even a good idea in cases where there is 405*0Sstevel@tonic-gate # a logical path difference between $path and $base nodename and/or device. 406*0Sstevel@tonic-gate # Hence we fall back to returning the absolute $path spec 407*0Sstevel@tonic-gate # if there is a case blind device (or node) difference of any sort 408*0Sstevel@tonic-gate # and we do not even try to call $parse() or consult %ENV for $trnlnm() 409*0Sstevel@tonic-gate # (this module needs to run on non VMS platforms after all). 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gate my ($path_volume, $path_directories, $path_file) = $self->splitpath($path); 412*0Sstevel@tonic-gate my ($base_volume, $base_directories, $base_file) = $self->splitpath($base); 413*0Sstevel@tonic-gate return $path unless lc($path_volume) eq lc($base_volume); 414*0Sstevel@tonic-gate 415*0Sstevel@tonic-gate for ($path, $base) { $_ = $self->rel2abs($_) } 416*0Sstevel@tonic-gate 417*0Sstevel@tonic-gate # Now, remove all leading components that are the same 418*0Sstevel@tonic-gate my @pathchunks = $self->splitdir( $path_directories ); 419*0Sstevel@tonic-gate unshift(@pathchunks,'000000') unless $pathchunks[0] eq '000000'; 420*0Sstevel@tonic-gate my @basechunks = $self->splitdir( $base_directories ); 421*0Sstevel@tonic-gate unshift(@basechunks,'000000') unless $basechunks[0] eq '000000'; 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate while ( @pathchunks && 424*0Sstevel@tonic-gate @basechunks && 425*0Sstevel@tonic-gate lc( $pathchunks[0] ) eq lc( $basechunks[0] ) 426*0Sstevel@tonic-gate ) { 427*0Sstevel@tonic-gate shift @pathchunks ; 428*0Sstevel@tonic-gate shift @basechunks ; 429*0Sstevel@tonic-gate } 430*0Sstevel@tonic-gate 431*0Sstevel@tonic-gate # @basechunks now contains the directories to climb out of, 432*0Sstevel@tonic-gate # @pathchunks now has the directories to descend in to. 433*0Sstevel@tonic-gate $path_directories = join '.', ('-' x @basechunks, @pathchunks) ; 434*0Sstevel@tonic-gate return $self->canonpath( $self->catpath( '', $path_directories, $path_file ) ) ; 435*0Sstevel@tonic-gate} 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate 438*0Sstevel@tonic-gate=item rel2abs (override) 439*0Sstevel@tonic-gate 440*0Sstevel@tonic-gateUse VMS syntax when converting filespecs. 441*0Sstevel@tonic-gate 442*0Sstevel@tonic-gate=cut 443*0Sstevel@tonic-gate 444*0Sstevel@tonic-gatesub rel2abs { 445*0Sstevel@tonic-gate my $self = shift ; 446*0Sstevel@tonic-gate return vmspath(File::Spec::Unix::rel2abs( $self, @_ )) 447*0Sstevel@tonic-gate if ( join( '', @_ ) =~ m{/} ) ; 448*0Sstevel@tonic-gate 449*0Sstevel@tonic-gate my ($path,$base ) = @_; 450*0Sstevel@tonic-gate # Clean up and split up $path 451*0Sstevel@tonic-gate if ( ! $self->file_name_is_absolute( $path ) ) { 452*0Sstevel@tonic-gate # Figure out the effective $base and clean it up. 453*0Sstevel@tonic-gate if ( !defined( $base ) || $base eq '' ) { 454*0Sstevel@tonic-gate $base = $self->_cwd; 455*0Sstevel@tonic-gate } 456*0Sstevel@tonic-gate elsif ( ! $self->file_name_is_absolute( $base ) ) { 457*0Sstevel@tonic-gate $base = $self->rel2abs( $base ) ; 458*0Sstevel@tonic-gate } 459*0Sstevel@tonic-gate else { 460*0Sstevel@tonic-gate $base = $self->canonpath( $base ) ; 461*0Sstevel@tonic-gate } 462*0Sstevel@tonic-gate 463*0Sstevel@tonic-gate # Split up paths 464*0Sstevel@tonic-gate my ( $path_directories, $path_file ) = 465*0Sstevel@tonic-gate ($self->splitpath( $path ))[1,2] ; 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate my ( $base_volume, $base_directories ) = 468*0Sstevel@tonic-gate $self->splitpath( $base ) ; 469*0Sstevel@tonic-gate 470*0Sstevel@tonic-gate $path_directories = '' if $path_directories eq '[]' || 471*0Sstevel@tonic-gate $path_directories eq '<>'; 472*0Sstevel@tonic-gate my $sep = '' ; 473*0Sstevel@tonic-gate $sep = '.' 474*0Sstevel@tonic-gate if ( $base_directories =~ m{[^.\]>]\Z(?!\n)} && 475*0Sstevel@tonic-gate $path_directories =~ m{^[^.\[<]}s 476*0Sstevel@tonic-gate ) ; 477*0Sstevel@tonic-gate $base_directories = "$base_directories$sep$path_directories"; 478*0Sstevel@tonic-gate $base_directories =~ s{\.?[\]>][\[<]\.?}{.}; 479*0Sstevel@tonic-gate 480*0Sstevel@tonic-gate $path = $self->catpath( $base_volume, $base_directories, $path_file ); 481*0Sstevel@tonic-gate } 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate return $self->canonpath( $path ) ; 484*0Sstevel@tonic-gate} 485*0Sstevel@tonic-gate 486*0Sstevel@tonic-gate 487*0Sstevel@tonic-gate=back 488*0Sstevel@tonic-gate 489*0Sstevel@tonic-gate=head1 SEE ALSO 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gateSee L<File::Spec> and L<File::Spec::Unix>. This package overrides the 492*0Sstevel@tonic-gateimplementation of these methods, not the semantics. 493*0Sstevel@tonic-gate 494*0Sstevel@tonic-gateAn explanation of VMS file specs can be found at 495*0Sstevel@tonic-gateL<"http://h71000.www7.hp.com/doc/731FINAL/4506/4506pro_014.html#apps_locating_naming_files">. 496*0Sstevel@tonic-gate 497*0Sstevel@tonic-gate=cut 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gate1; 500