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
27 =item eliminate_macros
29 Expands MM[KS]/Make macros in a text string, using the contents of
30 identically named elements of C<%$self>, and returns the result
31 as a file specification in Unix syntax.
35 sub eliminate_macros {
37 return '' unless $path;
38 $self = {} unless ref $self;
39 my($npath) = unixify($path);
41 my($head,$macro,$tail);
43 # perform m##g in scalar context so it acts as an iterator
44 while ($npath =~ m#(.*?)\$\((\S+?)\)(.*)#g) {
46 ($head,$macro,$tail) = ($1,$2,$3);
47 if (ref $self->{$macro}) {
48 if (ref $self->{$macro} eq 'ARRAY') {
49 $macro = join ' ', @{$self->{$macro}};
52 print "Note: can't expand macro \$($macro) containing ",ref($self->{$macro}),
53 "\n\t(using MMK-specific deferred substitutuon; MMS will break)\n";
54 $macro = "\cB$macro\cB";
58 else { ($macro = unixify($self->{$macro})) =~ s#/$##; }
59 $npath = "$head$macro$tail";
62 if ($complex) { $npath =~ s#\cB(.*?)\cB#\${$1}#g; }
68 Catchall routine to clean up problem MM[SK]/Make macros. Expands macros
69 in any directory specification, in order to avoid juxtaposing two
70 VMS-syntax directories when MM[SK] is run. Also expands expressions which
71 are all macro, so that we can tell how long the expansion is, and avoid
72 overrunning DCL's command buffer when MM[KS] is running.
74 If optional second argument has a TRUE value, then the return string is
75 a VMS-syntax directory specification, if it is FALSE, the return string
76 is a VMS-syntax file specification, and if it is not specified, fixpath()
77 checks to see whether it matches the name of a directory in the current
78 default directory, and returns a directory or file specification accordingly.
83 my($self,$path,$force_path) = @_;
84 return '' unless $path;
85 $self = bless {} unless ref $self;
86 my($fixedpath,$prefix,$name);
88 if ($path =~ m#^\$\([^\)]+\)$# || $path =~ m#[/:>\]]#) {
89 if ($force_path or $path =~ /(?:DIR\)|\])$/) {
90 $fixedpath = vmspath($self->eliminate_macros($path));
93 $fixedpath = vmsify($self->eliminate_macros($path));
96 elsif ((($prefix,$name) = ($path =~ m#^\$\(([^\)]+)\)(.+)#)) && $self->{$prefix}) {
97 my($vmspre) = $self->eliminate_macros("\$($prefix)");
98 # is it a dir or just a name?
99 $vmspre = ($vmspre =~ m|/| or $prefix =~ /DIR$/) ? vmspath($vmspre) : '';
100 $fixedpath = ($vmspre ? $vmspre : $self->{$prefix}) . $name;
101 $fixedpath = vmspath($fixedpath) if $force_path;
105 $fixedpath = vmspath($fixedpath) if $force_path;
107 # No hints, so we try to guess
108 if (!defined($force_path) and $fixedpath !~ /[:>(.\]]/) {
109 $fixedpath = vmspath($fixedpath) if -d $fixedpath;
111 # Trim off root dirname if it's had other dirs inserted in front of it.
112 $fixedpath =~ s/\.000000([\]>])/$1/;
118 =head2 Methods always loaded
124 Concatenates a list of file specifications, and returns the result as a
125 VMS-syntax directory specification.
130 my ($self,@dirs) = @_;
132 @dirs = grep($_,@dirs);
135 my $path = (@dirs == 1 ? $dirs[0] : $self->catdir(@dirs));
136 my ($spath,$sdir) = ($path,$dir);
137 $spath =~ s/.dir$//; $sdir =~ s/.dir$//;
138 $sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+$/;
139 $rslt = $self->fixpath($self->eliminate_macros($spath)."/$sdir",1);
142 if ($dir =~ /^\$\([^\)]+\)$/) { $rslt = $dir; }
143 else { $rslt = vmspath($dir); }
150 Concatenates a list of file specifications, and returns the result as a
151 VMS-syntax directory specification.
156 my ($self,@files) = @_;
157 my $file = pop @files;
158 @files = grep($_,@files);
161 my $path = (@files == 1 ? $files[0] : $self->catdir(@files));
164 if ($spath =~ /^[^\)\]\/:>]+\)$/ && basename($file) eq $file) {
165 $rslt = "$spath$file";
168 $rslt = $self->eliminate_macros($spath);
169 $rslt = vmsify($rslt.($rslt ? '/' : '').unixify($file));
172 else { $rslt = vmsify($file); }
176 =item curdir (override)
178 Returns a string representation of the current directory: '[]'
186 =item devnull (override)
188 Returns a string representation of the null device: '_NLA0:'
196 =item rootdir (override)
198 Returns a string representation of the root directory: 'SYS$DISK:[000000]'
203 return 'SYS$DISK:[000000]';
206 =item tmpdir (override)
208 Returns a string representation of the first writable directory
209 from the following list or '' if none are writable:
218 return $tmpdir if defined $tmpdir;
219 foreach ('/sys$scratch', $ENV{TMPDIR}) {
220 next unless defined && -d && -w _;
224 $tmpdir = '' unless defined $tmpdir;
228 =item updir (override)
230 Returns a string representation of the parent directory: '[-]'
238 =item path (override)
240 Translate logical name DCL$PATH as a searchlist, rather than trying
241 to C<split> string value of C<$ENV{'PATH'}>.
247 while ($dir = $ENV{'DCL$PATH;' . $i++}) { push(@dirs,$dir); }
251 =item file_name_is_absolute (override)
253 Checks for VMS directory spec as well as Unix separators.
257 sub file_name_is_absolute {
258 my ($self,$file) = @_;
259 # If it's a logical name, expand it.
260 $file = $ENV{$file} while $file =~ /^[\w\$\-]+$/ && $ENV{$file};
261 return scalar($file =~ m!^/! ||
262 $file =~ m![<\[][^.\-\]>]! ||