FileNames.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Stewart, December 13, 1983 6:44 pm
Russ Atkinson (RRA) March 5, 1985 4:08:00 pm PST
This interface provides some utilities for manipulating file names and path names.
DIRECTORY
Rope USING [ROPE];
FileNames: CEDAR DEFINITIONS = BEGIN OPEN Rope;
FileWithSearchRules: PROC [root: ROPE, defaultExtension: ROPE, requireExtension: BOOLTRUE, requireExact: BOOLTRUE, searchRules: REF ANY] RETURNS [fullPath: ROPE, ambiguous: BOOLFALSE];
FileWithSearchRules uses the working directory and the search rules to try to translate the short name of a file into a full path name. Calls ResolveRelativePath first. NIL is returned if the file cannot be found.
searchRules should either be a LIST OF REF ANY each of whose elements are Rope.ROPEs or a LIST OF ROPE.
If requireExtension, then if root has an extension, it must be the same as defaultExtension.
FileWithSearchRules adds !H to all pattern matches
IF requireExact = TRUE, then FileWithSearchRules will not try for a unique pattern match, but will only check exact names.
FileWithSearchRules returns NIL and ambiguous = TRUE if it finds more than one matching file.
FileNames returns not-NIL and ambiguous = TRUE if the result was found as a consequence of a unique pattern match.
FileWithSearchRules uses the following rules:
IF root is a full path name then {
tries root
tries Concat[root, defaultExtension]
IF NOT requireExact THEN tries for a unique match for Cat[root, *, defaultExtension]
}
ELSE {
tries root (automatically used $WorkingDirectory)
FOR wdir ← each element of search rules {
tries Concat[wdir, root]
}
tries Concat[root, defaultExtension] (automatically used $WorkingDirectory)
FOR wdir ← each element of search rules {
tries Cat[wdir, root, defaultExtension]
}
IF NOT requireExact THEN FOR wdir ← each element of search rules {
tries for a unique match for Cat[wdir, root, *, defaultExtension]
}
}
Returns NIL if can't find it.
ResolveRelativePath: PROC [path: ROPE] RETURNS [ROPE];
If path starts with ./ or ../, ResolveRelativePath converts it into the equivalent full path name using the $WorkingDirectory property on the process properties list.
If path = "." returns the current working directory.
If path = ".." returns the parent of the current working directory.
ConvertToSlashFormat: PROC [path: ROPE] RETURNS [ROPE];
Converts FS name strings to slash format, but makes no consistancy checks.
CurrentWorkingDirectory: PROC RETURNS [ROPE];
Returns the currentworking directory, if there is one, otherwise returns the FS default working directory. Converts to slash format. (If any conversion was necessary, stores back the new version as the working directory.)
HomeDirectory: PROC RETURNS [ROPE];
Returns the current user's directory. This will be something like ///Users/Stewart.pa/.
IsADirectory: PROC [path: ROPE] RETURNS [BOOL];
If the path ends in '/ or '>, or '], returns TRUE. Returns FALSE if the path is empty.
IsAPattern: PROC [path: ROPE] RETURNS [BOOL];
If the path contains a '*, returns TRUE.
GetShortName: PROC [path: ROPE, stripOffVersionNumber: BOOLTRUE] RETURNS [ROPE];
Returns the part of the path after the last '/, '>, or ']. (Strips off version number if stripOffVersionNumber is TRUE.)
Tail: PROC [s: ROPE, char: CHAR] RETURNS [ROPE];
Tail returns the part of a rope after the last instance of char.
StripVersionNumber: PROC [path: ROPE] RETURNS [ROPE];
Returns the part of path before the '!, if any.
IsRemote: PROC [path: ROPE] RETURNS [BOOL];
Returns TRUE if the server part of path is not empty. If path is not a full path name, then IsRemote looks at the current working directory.
InASubdirectory: PROC [parent: ROPE, path: ROPE] RETURNS [BOOL];
If parent is not a prefix of path returns FALSE. If parent is a prefix of path, returns TRUE only if the part of path after the prefix contains a '/ or '>.
FirstSubdirectory: PROC [parent: ROPE, path: ROPE] RETURNS [ROPE];
If NOT InASubdirectory[parent, path] then returns NIL. Otherwise, returns the part of path up to and including the first '/ or '> after the end of parent.
DirectoryContaining: PROC [path: ROPE, pos: INT] RETURNS [ROPE];
Return the prefix of the part of name before pos which is the name of a directory..
Directory: PROC [path: ROPE] RETURNS [ROPE];
Return the directory part of the path.
Parent: PROC [path: ROPE] RETURNS [ROPE];
If path is a directory, then returns the parent directory. If path is a file, then returns the current directory. In either case, this means that Parent returns the directory which contains the current object.
END.