1 package File::Spec::VMS;
5 require File::Spec::Unix;
6 @ISA = qw(File::Spec::Unix);
13 File::Spec::VMS - methods for VMS file specs
17 require File::Spec::VMS; # Done internally by File::Spec if needed
21 See File::Spec::Unix for a documentation of the methods provided
22 there. This package overrides the implementation of these methods, not
25 =item eliminate_macros
27 Expands MM[KS]/Make macros in a text string, using the contents of
28 identically named elements of C<%$self>, and returns the result
29 as a file specification in Unix syntax.
33 sub eliminate_macros {
35 return '' unless $path;
36 $self = {} unless ref $self;
37 my($npath) = unixify($path);
39 my($head,$macro,$tail);
41 # perform m##g in scalar context so it acts as an iterator
42 while ($npath =~ m#(.*?)\$\((\S+?)\)(.*)#g) {
44 ($head,$macro,$tail) = ($1,$2,$3);
45 if (ref $self->{$macro}) {
46 if (ref $self->{$macro} eq 'ARRAY') {
47 $macro = join ' ', @{$self->{$macro}};
50 print "Note: can't expand macro \$($macro) containing ",ref($self->{$macro}),
51 "\n\t(using MMK-specific deferred substitutuon; MMS will break)\n";
52 $macro = "\cB$macro\cB";
56 else { ($macro = unixify($self->{$macro})) =~ s#/$##; }
57 $npath = "$head$macro$tail";
60 if ($complex) { $npath =~ s#\cB(.*?)\cB#\${$1}#g; }
66 Catchall routine to clean up problem MM[SK]/Make macros. Expands macros
67 in any directory specification, in order to avoid juxtaposing two
68 VMS-syntax directories when MM[SK] is run. Also expands expressions which
69 are all macro, so that we can tell how long the expansion is, and avoid
70 overrunning DCL's command buffer when MM[KS] is running.
72 If optional second argument has a TRUE value, then the return string is
73 a VMS-syntax directory specification, if it is FALSE, the return string
74 is a VMS-syntax file specification, and if it is not specified, fixpath()
75 checks to see whether it matches the name of a directory in the current
76 default directory, and returns a directory or file specification accordingly.
81 my($self,$path,$force_path) = @_;
82 return '' unless $path;
83 $self = bless {} unless ref $self;
84 my($fixedpath,$prefix,$name);
86 if ($path =~ m#^\$\([^\)]+\)$# || $path =~ m#[/:>\]]#) {
87 if ($force_path or $path =~ /(?:DIR\)|\])$/) {
88 $fixedpath = vmspath($self->eliminate_macros($path));
91 $fixedpath = vmsify($self->eliminate_macros($path));
94 elsif ((($prefix,$name) = ($path =~ m#^\$\(([^\)]+)\)(.+)#)) && $self->{$prefix}) {
95 my($vmspre) = $self->eliminate_macros("\$($prefix)");
96 # is it a dir or just a name?
97 $vmspre = ($vmspre =~ m|/| or $prefix =~ /DIR$/) ? vmspath($vmspre) : '';
98 $fixedpath = ($vmspre ? $vmspre : $self->{$prefix}) . $name;
99 $fixedpath = vmspath($fixedpath) if $force_path;
103 $fixedpath = vmspath($fixedpath) if $force_path;
105 # No hints, so we try to guess
106 if (!defined($force_path) and $fixedpath !~ /[:>(.\]]/) {
107 $fixedpath = vmspath($fixedpath) if -d $fixedpath;
109 # Trim off root dirname if it's had other dirs inserted in front of it.
110 $fixedpath =~ s/\.000000([\]>])/$1/;
115 =head2 Methods always loaded
121 Concatenates a list of file specifications, and returns the result as a
122 VMS-syntax directory specification.
127 my ($self,@dirs) = @_;
129 @dirs = grep($_,@dirs);
132 my $path = (@dirs == 1 ? $dirs[0] : $self->catdir(@dirs));
133 my ($spath,$sdir) = ($path,$dir);
134 $spath =~ s/.dir$//; $sdir =~ s/.dir$//;
135 $sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+$/;
136 $rslt = $self->fixpath($self->eliminate_macros($spath)."/$sdir",1);
139 if ($dir =~ /^\$\([^\)]+\)$/) { $rslt = $dir; }
140 else { $rslt = vmspath($dir); }
147 Concatenates a list of file specifications, and returns the result as a
148 VMS-syntax directory specification.
153 my ($self,@files) = @_;
154 my $file = pop @files;
155 @files = grep($_,@files);
158 my $path = (@files == 1 ? $files[0] : $self->catdir(@files));
161 if ($spath =~ /^[^\)\]\/:>]+\)$/ && basename($file) eq $file) {
162 $rslt = "$spath$file";
165 $rslt = $self->eliminate_macros($spath);
166 $rslt = vmsify($rslt.($rslt ? '/' : '').unixify($file));
169 else { $rslt = vmsify($file); }
173 =item curdir (override)
175 Returns a string representation of the current directory: '[]'
183 =item devnull (override)
185 Returns a string representation of the null device: '_NLA0:'
193 =item rootdir (override)
195 Returns a string representation of the root directory: 'SYS$DISK:[000000]'
200 return 'SYS$DISK:[000000]';
203 =item tmpdir (override)
205 Returns a string representation of the first writable directory
206 from the following list or '' if none are writable:
215 return $tmpdir if defined $tmpdir;
216 foreach ('/sys$scratch', $ENV{TMPDIR}) {
217 next unless defined && -d && -w _;
221 $tmpdir = '' unless defined $tmpdir;
225 =item updir (override)
227 Returns a string representation of the parent directory: '[-]'
235 =item path (override)
237 Translate logical name DCL$PATH as a searchlist, rather than trying
238 to C<split> string value of C<$ENV{'PATH'}>.
244 while ($dir = $ENV{'DCL$PATH;' . $i++}) { push(@dirs,$dir); }
248 =item file_name_is_absolute (override)
250 Checks for VMS directory spec as well as Unix separators.
254 sub file_name_is_absolute {
255 my ($self,$file) = @_;
256 # If it's a logical name, expand it.
257 $file = $ENV{$file} while $file =~ /^[\w\$\-]+$/ && $ENV{$file};
258 return scalar($file =~ m!^/! ||
259 $file =~ m![<\[][^.\-\]>]! ||