use vars
qw(@ISA $VERSION);
require File::Spec::Unix;
@ISA = qw(File::Spec::Unix);
File::Spec::VMS - methods for VMS file specs
require File::Spec::VMS; # Done internally by File::Spec if needed
See File::Spec::Unix for a documentation of the methods provided
there. This package overrides the implementation of these methods, not
Expands MM[KS]/Make macros in a text string, using the contents of
identically named elements of C<%$self>, and returns the result
as a file specification in Unix syntax.
$self = {} unless ref $self;
return join ' ', map { $self->eliminate_macros($_) } split /\s+/, $path;
my($npath) = unixify
($path);
# perform m##g in scalar context so it acts as an iterator
while ($npath =~ m
#(.*?)\$\((\S+?)\)(.*)#gs) {
($head,$macro,$tail) = ($1,$2,$3);
if (ref $self->{$macro}) {
if (ref $self->{$macro} eq 'ARRAY') {
$macro = join ' ', @
{$self->{$macro}};
print "Note: can't expand macro \$($macro) containing ",ref($self->{$macro}),
"\n\t(using MMK-specific deferred substitutuon; MMS will break)\n";
else { ($macro = unixify
($self->{$macro})) =~ s
#/\Z(?!\n)##; }
$npath = "$head$macro$tail";
if ($complex) { $npath =~ s
#\cB(.*?)\cB#\${$1}#gs; }
Catchall routine to clean up problem MM[SK]/Make macros. Expands macros
in any directory specification, in order to avoid juxtaposing two
VMS-syntax directories when MM[SK] is run. Also expands expressions which
are all macro, so that we can tell how long the expansion is, and avoid
overrunning DCL's command buffer when MM[KS] is running.
If optional second argument has a TRUE value, then the return string is
a VMS-syntax directory specification, if it is FALSE, the return string
is a VMS-syntax file specification, and if it is not specified, fixpath()
checks to see whether it matches the name of a directory in the current
default directory, and returns a directory or file specification accordingly.
my($self,$path,$force_path) = @_;
$self = bless {} unless ref $self;
my($fixedpath,$prefix,$name);
map { $self->fixpath($_,$force_path) }
if ($path =~ m
#^\$\([^\)]+\)\Z(?!\n)#s || $path =~ m#[/:>\]]#) {
if ($force_path or $path =~ /(?:DIR\)|\])\Z(?!\n)/) {
$fixedpath = vmspath
($self->eliminate_macros($path));
$fixedpath = vmsify
($self->eliminate_macros($path));
elsif ((($prefix,$name) = ($path =~ m
#^\$\(([^\)]+)\)(.+)#s)) && $self->{$prefix}) {
my($vmspre) = $self->eliminate_macros("\$($prefix)");
# is it a dir or just a name?
$vmspre = ($vmspre =~ m
|/| or $prefix =~ /DIR\Z
(?
!\n)/) ? vmspath
($vmspre) : '';
$fixedpath = ($vmspre ?
$vmspre : $self->{$prefix}) . $name;
$fixedpath = vmspath
($fixedpath) if $force_path;
$fixedpath = vmspath
($fixedpath) if $force_path;
# No hints, so we try to guess
if (!defined($force_path) and $fixedpath !~ /[:>(.\]]/) {
$fixedpath = vmspath
($fixedpath) if -d
$fixedpath;
# Trim off root dirname if it's had other dirs inserted in front of it.
$fixedpath =~ s/\.000000([\]>])/$1/;
# Special case for VMS absolute directory specs: these will have had device
# prepended during trip through Unix syntax in eliminate_macros(), since
# Unix syntax has no way to express "absolute from the top of this device's
if ($path =~ /^[\[>][^.\-]/) { $fixedpath =~ s/^[^\[<]+//; }
=head2 Methods always loaded
=item canonpath (override)
Removes redundant portions of file specifications according to VMS syntax.
if ($path =~ m
|/|) { # Fake Unix
my $pathify = $path =~ m
|/\Z
(?
!\n)|;
$path = $self->SUPER::canonpath
($path);
if ($pathify) { return vmspath
($path); }
else { return vmsify
($path); }
$path =~ s/([\[<])000000\./$1/g; # [000000.foo ==> [foo
$path =~ s/([^-]+)\.(\]\[|><)?000000([\]\>])/$1$3/g; # foo.000000] ==> foo]
$path =~ s
-\
]\
[--g
; $path =~ s/><//g; # foo.][bar ==> foo.bar
1 while $path =~ s{([\[<-])\.-}{$1-}; # [.-.- ==> [--
$path =~ s/\.[^\[<\.]+\.-([\]\>])/$1/; # bar.foo.-] ==> bar]
$path =~ s/([\[<])(-+)/$1 . "\cx" x length($2)/e; # encode leading '-'s
$path =~ s/([\[<\.])([^\[<\.\cx]+)\.-\.?/$1/g; # bar.-.foo ==> foo
$path =~ s/([\[<])(\cx+)/$1 . '-' x length($2)/e; # then decode
Concatenates a list of file specifications, and returns the result as a
VMS-syntax directory specification. No check is made for "impossible"
cases (e.g. elements other than the first being absolute filespecs).
my $path = (@dirs == 1 ?
$dirs[0] : $self->catdir(@dirs));
my ($spath,$sdir) = ($path,$dir);
$spath =~ s/\.dir\Z(?!\n)//; $sdir =~ s/\.dir\Z(?!\n)//;
$sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+\Z(?!\n)/s;
$rslt = $self->fixpath($self->eliminate_macros($spath)."/$sdir",1);
# Special case for VMS absolute directory specs: these will have had device
# prepended during trip through Unix syntax in eliminate_macros(), since
# Unix syntax has no way to express "absolute from the top of this device's
if ($spath =~ /^[\[<][^.\-]/s) { $rslt =~ s/^[^\[<]+//s; }
if (not defined $dir or not length $dir) { $rslt = ''; }
elsif ($dir =~ /^\$\([^\)]+\)\Z(?!\n)/s) { $rslt = $dir; }
else { $rslt = vmspath
($dir); }
return $self->canonpath($rslt);
Concatenates a list of file specifications, and returns the result as a
VMS-syntax file specification.
@files = grep($_,@files);
my $path = (@files == 1 ?
$files[0] : $self->catdir(@files));
$spath =~ s/\.dir\Z(?!\n)//;
if ($spath =~ /^[^\)\]\/:>]+\
)\Z
(?
!\n)/s
&& basename
($file) eq $file) {
$rslt = $self->eliminate_macros($spath);
$rslt = vmsify
($rslt.($rslt ?
'/' : '').unixify
($file));
else { $rslt = (defined($file) && length($file)) ? vmsify
($file) : ''; }
return $self->canonpath($rslt);
Returns a string representation of the current directory: '[]'
Returns a string representation of the null device: '_NLA0:'
Returns a string representation of the root directory: 'SYS$DISK:[000000]'
return 'SYS$DISK:[000000]';
Returns a string representation of the first writable directory
from the following list or '' if none are writable:
Since perl 5.8.0, if running under taint mode, and if $ENV{TMPDIR}
is tainted, it is not used.
return $tmpdir if defined $tmpdir;
my @dirlist = ('sys$scratch:', $ENV{TMPDIR
});
if (${"\cTAINT"}) { # Check for taint mode on perl >= 5.8.0
pop @dirlist if Scalar
::Util
::tainted
($ENV{TMPDIR
});
next unless defined && -d
&& -w _
;
$tmpdir = '' unless defined $tmpdir;
Returns a string representation of the parent directory: '[-]'
=item case_tolerant (override)
VMS file specification syntax is case-tolerant.
Translate logical name DCL$PATH as a searchlist, rather than trying
to C<split> string value of C<$ENV{'PATH'}>.
while ($dir = $ENV{'DCL$PATH;' . $i++}) { push(@dirs,$dir); }
=item file_name_is_absolute (override)
Checks for VMS directory spec as well as Unix separators.
sub file_name_is_absolute
{
# If it's a logical name, expand it.
$file = $ENV{$file} while $file =~ /^[\w\$\-]+\Z(?!\n)/s && $ENV{$file};
return scalar($file =~ m!^/!s ||
$file =~ m![<\[][^.\-\]>]! ||
=item splitpath (override)
my($dev,$dir,$file) = ('','','');
vmsify
($path) =~ /(.+:)?([\[<].*[\]>])?(.*)/s;
return ($1 || '',$2 || '',$3);
=item splitdir (override)
Split dirspec using VMS syntax.
$dirspec =~ s/\]\[//g; $dirspec =~ s/\-\-/-.-/g;
$dirspec = "[$dirspec]" unless $dirspec =~ /[\[<]/; # make legal
my(@dirs) = split('\.', vmspath
($dirspec));
$dirs[0] =~ s/^[\[<]//s; $dirs[-1] =~ s/[\]>]\Z(?!\n)//s;
Construct a complete filespec using VMS syntax
my($self,$dev,$dir,$file) = @_;
if ($dev =~ m
|^/+([^/]+)|) { $dev = "$1:"; }
else { $dev .= ':' unless $dev eq '' or $dev =~ /:\Z(?!\n)/; }
if (length($dev) or length($dir)) {
$dir = "[$dir]" unless $dir =~ /[\[<\/]/;
Use VMS syntax when converting filespecs.
return vmspath
(File
::Spec
::Unix
::abs2rel
( $self, @_ ))
if ( join( '', @_ ) =~ m{/} ) ;
# Note: we use '/' to glue things together here, then let canonpath()
# clean them up at the end.
if ( ! $self->file_name_is_absolute( $path ) ) {
$path = $self->rel2abs( $path ) ;
$path = $self->canonpath( $path ) ;
# Figure out the effective $base and clean it up.
if ( !defined( $base ) || $base eq '' ) {
$base = $self->canonpath( $base ) ;
elsif ( ! $self->file_name_is_absolute( $base ) ) {
$base = $self->rel2abs( $base ) ;
$base = $self->canonpath( $base ) ;
my ( $path_directories, $path_file ) =
($self->splitpath( $path, 1 ))[1,2] ;
if $path_directories =~ /^\[(.*)\]\Z(?!\n)/s ;
my $base_directories = ($self->splitpath( $base, 1 ))[1] ;
if $base_directories =~ /^\[(.*)\]\Z(?!\n)/s ;
# Now, remove all leading components that are the same
my @pathchunks = $self->splitdir( $path_directories );
unshift(@pathchunks,'000000') unless $pathchunks[0] eq '000000';
my @basechunks = $self->splitdir( $base_directories );
unshift(@basechunks,'000000') unless $basechunks[0] eq '000000';
lc( $pathchunks[0] ) eq lc( $basechunks[0] )
# @basechunks now contains the directories to climb out of,
# @pathchunks now has the directories to descend in to.
$path_directories = '-.' x
@basechunks . join( '.', @pathchunks ) ;
$path_directories =~ s{\.\Z(?!\n)}{} ;
return $self->canonpath( $self->catpath( '', $path_directories, $path_file ) ) ;
Use VMS syntax when converting filespecs.
return vmspath
(File
::Spec
::Unix
::rel2abs
( $self, @_ ))
if ( join( '', @_ ) =~ m{/} ) ;
# Clean up and split up $path
if ( ! $self->file_name_is_absolute( $path ) ) {
# Figure out the effective $base and clean it up.
if ( !defined( $base ) || $base eq '' ) {
elsif ( ! $self->file_name_is_absolute( $base ) ) {
$base = $self->rel2abs( $base ) ;
$base = $self->canonpath( $base ) ;
my ( $path_directories, $path_file ) =
($self->splitpath( $path ))[1,2] ;
my ( $base_volume, $base_directories ) =
$self->splitpath( $base ) ;
$path_directories = '' if $path_directories eq '[]' ||
$path_directories eq '<>';
if ( $base_directories =~ m{[^.\]>]\Z(?!\n)} &&
$path_directories =~ m{^[^.\[<]}s
$base_directories = "$base_directories$sep$path_directories";
$base_directories =~ s{\.?[\]>][\[<]\.?}{.};
$path = $self->catpath( $base_volume, $base_directories, $path_file );
return $self->canonpath( $path ) ;