📄 vms.pm
字号:
package File::Spec::VMS;use strict;use vars qw(@ISA $VERSION);require File::Spec::Unix;$VERSION = '3.2501';@ISA = qw(File::Spec::Unix);use File::Basename;use VMS::Filespec;=head1 NAMEFile::Spec::VMS - methods for VMS file specs=head1 SYNOPSIS require File::Spec::VMS; # Done internally by File::Spec if needed=head1 DESCRIPTIONSee File::Spec::Unix for a documentation of the methods providedthere. This package overrides the implementation of these methods, notthe semantics.=over 4=item canonpath (override)Removes redundant portions of file specifications according to VMS syntax.=cutsub canonpath { my($self,$path) = @_; return undef unless defined $path; 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); } } else { $path =~ tr/<>/[]/; # < and > ==> [ and ] $path =~ s/\]\[\./\.\]\[/g; # ][. ==> .][ $path =~ s/\[000000\.\]\[/\[/g; # [000000.][ ==> [ $path =~ s/\[000000\./\[/g; # [000000. ==> [ $path =~ s/\.\]\[000000\]/\]/g; # .][000000] ==> ] $path =~ s/\.\]\[/\./g; # foo.][bar ==> foo.bar 1 while ($path =~ s/([\[\.])(-+)\.(-+)([\.\]])/$1$2$3$4/); # That loop does the following # with any amount of dashes: # .-.-. ==> .--. # [-.-. ==> [--. # .-.-] ==> .--] # [-.-] ==> [--] 1 while ($path =~ s/([\[\.])[^\]\.]+\.-(-+)([\]\.])/$1$2$3/); # That loop does the following # with any amount (minimum 2) # of dashes: # .foo.--. ==> .-. # .foo.--] ==> .-] # [foo.--. ==> [-. # [foo.--] ==> [-] # # And then, the remaining cases $path =~ s/\[\.-/[-/; # [.- ==> [- $path =~ s/\.[^\]\.]+\.-\./\./g; # .foo.-. ==> . $path =~ s/\[[^\]\.]+\.-\./\[/g; # [foo.-. ==> [ $path =~ s/\.[^\]\.]+\.-\]/\]/g; # .foo.-] ==> ] $path =~ s/\[[^\]\.]+\.-\]/\[000000\]/g;# [foo.-] ==> [000000] $path =~ s/\[\]// unless $path eq '[]'; # [] ==> return $path; }}=item catdir (override)Concatenates a list of file specifications, and returns the result as aVMS-syntax directory specification. No check is made for "impossible"cases (e.g. elements other than the first being absolute filespecs).=cutsub catdir { my $self = shift; my $dir = pop; my @dirs = grep {defined() && length()} @_; my $rslt; if (@dirs) { 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 # directory tree". if ($spath =~ /^[\[<][^.\-]/s) { $rslt =~ s/^[^\[<]+//s; } } else { if (not defined $dir or not length $dir) { $rslt = ''; } elsif ($dir =~ /^\$\([^\)]+\)\Z(?!\n)/s) { $rslt = $dir; } else { $rslt = vmspath($dir); } } return $self->canonpath($rslt);}=item catfile (override)Concatenates a list of file specifications, and returns the result as aVMS-syntax file specification.=cutsub catfile { my $self = shift; my $file = $self->canonpath(pop()); my @files = grep {defined() && length()} @_; my $rslt; if (@files) { my $path = (@files == 1 ? $files[0] : $self->catdir(@files)); my $spath = $path; $spath =~ s/\.dir\Z(?!\n)//; if ($spath =~ /^[^\)\]\/:>]+\)\Z(?!\n)/s && basename($file) eq $file) { $rslt = "$spath$file"; } else { $rslt = $self->eliminate_macros($spath); $rslt = vmsify($rslt.((defined $rslt) && ($rslt ne '') ? '/' : '').unixify($file)); } } else { $rslt = (defined($file) && length($file)) ? vmsify($file) : ''; } return $self->canonpath($rslt);}=item curdir (override)Returns a string representation of the current directory: '[]'=cutsub curdir { return '[]';}=item devnull (override)Returns a string representation of the null device: '_NLA0:'=cutsub devnull { return "_NLA0:";}=item rootdir (override)Returns a string representation of the root directory: 'SYS$DISK:[000000]'=cutsub rootdir { return 'SYS$DISK:[000000]';}=item tmpdir (override)Returns a string representation of the first writable directoryfrom the following list or '' if none are writable: sys$scratch: $ENV{TMPDIR}Since perl 5.8.0, if running under taint mode, and if $ENV{TMPDIR}is tainted, it is not used.=cutmy $tmpdir;sub tmpdir { return $tmpdir if defined $tmpdir; $tmpdir = $_[0]->_tmpdir( 'sys$scratch:', $ENV{TMPDIR} );}=item updir (override)Returns a string representation of the parent directory: '[-]'=cutsub updir { return '[-]';}=item case_tolerant (override)VMS file specification syntax is case-tolerant.=cutsub case_tolerant { return 1;}=item path (override)Translate logical name DCL$PATH as a searchlist, rather than tryingto C<split> string value of C<$ENV{'PATH'}>.=cutsub path { my (@dirs,$dir,$i); while ($dir = $ENV{'DCL$PATH;' . $i++}) { push(@dirs,$dir); } return @dirs;}=item file_name_is_absolute (override)Checks for VMS directory spec as well as Unix separators.=cutsub file_name_is_absolute { my ($self,$file) = @_; # 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![<\[][^.\-\]>]! || $file =~ /:[^<\[]/);}=item splitpath (override)Splits using VMS syntax.=cutsub splitpath { my($self,$path) = @_; my($dev,$dir,$file) = ('','',''); vmsify($path) =~ /(.+:)?([\[<].*[\]>])?(.*)/s; return ($1 || '',$2 || '',$3);}=item splitdir (override)Split dirspec using VMS syntax.=cutsub splitdir { my($self,$dirspec) = @_; my @dirs = (); return @dirs if ( (!defined $dirspec) || ('' eq $dirspec) ); $dirspec =~ tr/<>/[]/; # < and > ==> [ and ] $dirspec =~ s/\]\[\./\.\]\[/g; # ][. ==> .][ $dirspec =~ s/\[000000\.\]\[/\[/g; # [000000.][ ==> [
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -