# Perl hooks into the routines in vms.c for interconversion
# of VMS and Unix file specification syntax.
#
-# Version: 1.1
-# Author: Charles Bailey bailey@genetics.upenn.edu
+# Version: see $VERSION below
+# Author: Charles Bailey bailey@newman.upenn.edu
# Revised: 08-Mar-1995
=head1 NAME
=head1 SYNOPSIS
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');
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.
+to take advantage of conveniences provided by either syntax (I<e.g.>
ability to easily concatenate Unix-style specifications). In
addition, it provides an additional file test routine, C<candelete>,
which determines whether you have delete access to a file.
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, ir undef if
-an error occurs. The conversions are, for the most part, simply
+Unix syntax, and returns the converted file specification, or C<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
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 C<&> form of
+subroutine call, which bypasses prototype checking).
+
+
The routines provided are:
+=head2 rmsexpand
+
+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 C<rmsexpand>.
+(If the file does not exist, the input specification is expanded as much
+as possible.) If an error occurs, returns C<undef> and sets C<$!>
+and C<$^E>.
+
=head2 vmsify
Converts a file specification to VMS syntax.
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
+F<.DIR;1>. For compatibility with Unix usage, the type and version
+may also be omitted.
=head2 fileify
directory file - that is, a string you can pass to functions like
C<stat> or C<rmdir> to manipulate the directory file. If the
input directory specification uses VMS syntax, the returned file
-specification does, too; likewise for Unix syntax.
+specification does, too; likewise for Unix syntax. As with
+C<pathify>, the input file specification must have a type and
+version of F<.DIR;1>, or the type and version must be omitted.
=head2 vmspath
=head1 REVISION
-This document was last revised 08-Mar-1995, for Perl 5.001.
+This document was last revised 22-Feb-1996, for Perl 5.002.
=cut
package VMS::Filespec;
+require 5.002;
+
+our $VERSION = '1.11';
-# If you want to use this package on a non-VMS system, uncomment
-# the following line, and add AutoLoader to @ISA.
-# require AutoLoader;
+# If you want to use this package on a non-VMS system,
+# uncomment the following line.
+# use AutoLoader;
require Exporter;
@ISA = qw( Exporter );
-@EXPORT = qw( &rmsexpand &vmsify &unixify &pathify
- &fileify &vmspath &unixpath &candelete);
+@EXPORT = qw( &vmsify &unixify &pathify &fileify
+ &vmspath &unixpath &candelete &rmsexpand );
1;
# should be adequate for most purposes.
# A sort-of sys$parse() replacement
-sub rmsexpand {
+sub rmsexpand ($;$) {
my($fspec,$defaults) = @_;
if (!$fspec) { return undef }
my($node,$dev,$dir,$name,$type,$ver,$dnode,$ddev,$ddir,$dname,$dtype,$dver);
($node,$dev,$dir,$name,$type,$ver) = $fspec =~
/([^:]*::)?([^:]*:)?([^>\]]*[>\]])?([^.;]*)(\.?[^.;]*)([.;]?\d*)/;
foreach ((@$defaults,$ENV{'DEFAULT'})) {
+ next unless defined;
last if $node && $ver && $type && $dev && $dir && $name;
($dnode,$ddev,$ddir,$dname,$dtype,$dver) =
/([^:]*::)?([^:]*:)?([^>\]]*[>\]])?([^.;]*)(\.?[^.;]*)([.;]?\d*)/;
$fspec;
}
-sub vmsify {
+sub vmsify ($) {
my($fspec) = @_;
my($hasdev,$dev,$defdirs,$dir,$base,@dirs,@realdirs);
}
}
-sub unixify {
+sub unixify ($) {
my($fspec) = @_;
return $fspec if $fspec !~ m#[:>\]]#;
}
-sub fileify {
+sub fileify ($) {
my($path) = @_;
if (!$path) { return undef }
+ if ($path eq '/') { return 'sys$disk:[000000]'; }
if ($path =~ /(.+)\.([^:>\]]*)$/) {
$path = $1;
if ($2 !~ /^dir(?:;1)?$/i) { return undef }
}
}
-sub pathify {
+sub pathify ($) {
my($fspec) = @_;
if (!$fspec) { return undef }
}
}
-sub vmspath {
+sub vmspath ($) {
pathify(vmsify($_[0]));
}
-sub unixpath {
+sub unixpath ($) {
pathify(unixify($_[0]));
}
-sub candelete {
+sub candelete ($) {
my($fspec) = @_;
my($parent);
return '' unless -w $fspec;
$fspec =~ s#/$##;
if ($fspec =~ m#/#) {
- ($parent = $fspec) =~ s#/[^/]+$#;
+ ($parent = $fspec) =~ s#/[^/]+$##;
return (-w $parent);
}
elsif ($parent = fileify($fspec)) { # fileify() here to expand lnms