VMS::Filespec - convert between VMS and Unix file specification syntax
use VMS::Filespec; $fullspec = rmsexpand('[.VMS]file.specification'[, 'default:[file.spec]']); $vmsspec = vmsify('/my/Unix/file/specification'); $unixspec = unixify('my:[VMS]file.specification'); $path = pathify('my:[VMS.or.Unix.directory]specification.dir'); $dirfile = fileify('my:[VMS.or.Unix.directory.specification]'); $vmsdir = vmspath('my/VMS/or/Unix/directory/specification.dir'); $unixdir = unixpath('my:[VMS.or.Unix.directory]specification.dir'); candelete('my:[VMS.or.Unix]file.specification'); $case_tolerant = case_tolerant_process; $unixspec = unixrealpath('file_specification'); $vmsspec = vmsrealpath('file_specification');
This package provides routines to simplify conversion between VMS and Unix syntax when processing file specifications. This is useful when porting scripts designed to run under either OS, and also allows you to take advantage of conveniences provided by either syntax (e.g. ability to easily concatenate Unix-style specifications). In addition, it provides an additional file test routine,
candelete, which determines whether you have delete access to a file.
If you're running under VMS, the routines in this package are special, in that they're automatically made available to any Perl script, whether you're running miniperl or the full perl. The
use VMS::Filespec or
require VMS::Filespec; import VMS::Filespec ... statement can be used to import the function names into the current package, but they're always available if you use the fully qualified name, whether or not you've mentioned the .pm file in your script. If you're running under another OS and have installed this package, it behaves like a normal Perl extension (in fact, you're using Perl substitutes to emulate the necessary VMS system calls).
Each of these routines accepts a file specification in either VMS or Unix syntax, and returns the converted file specification, or
undef if an error occurs. The conversions are, for the most part, simply string manipulations; the routines do not check the details of syntax (e.g. that only legal characters are used). There is one exception: when running under VMS, conversions from VMS syntax use the $PARSE service to expand specifications, so illegal syntax, or a relative directory specification which extends above the tope of the current directory path (e.g [---.foo] when in dev:[dir.sub]) will cause errors. In general, any legal file specification will be converted properly, but garbage input tends to produce garbage output.
Each of these routines is prototyped as taking a single scalar argument, so you can use them as unary operators in complex expressions (as long as you don't use the
& form of subroutine call, which bypasses prototype checking).
The routines provided are:
Uses the RMS $PARSE and $SEARCH services to expand the input specification to its fully qualified form, except that a null type or version is not added unless it was present in either the original file specification or the default specification passed to
rmsexpand. (If the file does not exist, the input specification is expanded as much as possible.) If an error occurs, returns
undef and sets
rmsexpand on success will produce a name that fits in a 255 byte buffer, which is required for parameters passed to the DCL interpreter.
Converts a file specification to VMS syntax. If the file specification cannot be converted to or is already in VMS syntax, it will be passed through unchanged.
The file specifications of
.. will be converted to
If the file specification is already in a valid VMS syntax, it will be passed through unchanged, except that the UTF-8 flag will be cleared since VMS format file specifications are never in UTF-8.
When Perl is running on an OpenVMS system, if the
DECC$EFS_CHARSET feature is not enabled, extra dots in the file specification will be converted to underscore characters, and the
? character will be converted to a
% character, if a conversion is done.
When Perl is running on an OpenVMS system, if the
DECC$EFS_CHARSET feature is enabled, this implies that the Unix pathname cannot have a version, and that a path consisting of three dots,
./.../, will be converted to
Unix style shell macros like
$(abcd) are passed through instead of being converted to
$^(abcd^) independent of the
DECC$EFS_CHARSET feature setting. Unix style shell macros should not use characters that are not in the ASCII character set, as the resulting specification may or may not be still in UTF8 format.
The feature logical name
PERL_VMS_VTF7_FILENAMES controls if UNICODE characters in Unix filenames are encoded in VTF-7 notation in the resulting OpenVMS file specification. [Currently under development]
unixify on the resulting file specification may not result in the original Unix file specification, so programs should not plan to convert a file specification from Unix to VMS and then back to Unix again after modification of the components.
Converts a file specification to Unix syntax. If the file specification cannot be converted to or is already in Unix syntax, it will be passed through unchanged.
When Perl is running on an OpenVMS system, the following
DECC$ feature settings will control how the filename is converted:
C<decc$disable_to_vms_logname_translation:> default = C<ENABLE> C<decc$disable_posix_root:> default = C<ENABLE> C<decc$efs_charset:> default = C<DISABLE> C<decc$filename_unix_no_version:> default = C<DISABLE> C<decc$readdir_dropdotnotype:> default = C<ENABLE>
When Perl is being run under a Unix shell on OpenVMS, the defaults at a future time may be more appropriate for it.
When Perl is running on an OpenVMS system with
DECC$EFS_CHARSET enabled, a wild card directory name of
[...] cannot be translated to a valid Unix file specification. Also, directory file specifications will have their implied ".dir;1" removed, and a trailing
. character indicating a null extension will be removed.
DECC$FILENAME_UNIX_NO_VERSION because the conversion routine cannot differentiate whether the last
. of a Unix specification is delimiting a version, or is just part of a file specification.
vmsify on the resulting file specification may not result in the original VMS file specification, so programs should not plan to convert a file specification from VMS to Unix and then back to VMS again after modification.
Converts a directory specification to a path - that is, a string you can prepend to a file name to form a valid file specification. If the input file specification uses VMS syntax, the returned path does, too; likewise for Unix syntax (Unix paths are guaranteed to end with '/'). Note that this routine will insist that the input be a legal directory file specification; the file type and version, if specified, must be .DIR;1. For compatibility with Unix usage, the type and version may also be omitted.
Converts a directory specification to the file specification of the directory file - that is, a string you can pass to functions like
rmdir to manipulate the directory file. If the input directory specification uses VMS syntax, the returned file specification does, too; likewise for Unix syntax. As with
pathify, the input file specification must have a type and version of .DIR;1, or the type and version must be omitted.
pathify, but insures the returned path uses VMS syntax.
pathify, but insures the returned path uses Unix syntax.
Determines whether you have delete access to a file. If you do,
candelete returns true. If you don't, or its argument isn't a legal file specification,
candelete returns FALSE. Unlike other file tests, the argument to
candelete must be a file name (not a FileHandle), and, since it's an XSUB, it's a list operator, so you need to be careful about parentheses. Both of these restrictions may be removed in the future if the functionality of
candelete becomes part of the Perl core.
This reports whether the VMS process has been set to a case tolerant state, and returns true when the process is in the traditional case tolerant mode and false when case sensitivity has been enabled for the process. It is intended for use by the File::Spec::VMS->case_tolerant method only, and it is recommended that you only use File::Spec->case_tolerant.
This exposes the VMS C library
realpath function where available. It will always return a Unix format specification.
realpath function is not available, or is unable to return the real path of the file,
unixrealpath will use the same internal procedure as the
vmsrealpath function and convert the output to a Unix format specification. It is not available on non-VMS systems.
This uses the
LIB$FID_TO_NAME run-time library call to find the name of the primary link to a file, and returns the filename in VMS format. This function is not available on non-VMS systems.
This document was last revised 8-DEC-2007, for Perl 5.10.0