AMFilesImpl.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Paul Rovner: December 12, 1983 10:57 am
Bob Hagmann: May 7, 1984 12:40:48 pm PDT
Russ Atkinson: February 11, 1985 7:02:51 pm PST
DIRECTORY
AMFiles USING [],
BasicTime USING [GMT, nullGMT],
FS USING [OpenFile, FileInfo, Error, Open, nullOpenFile],
Rope USING [Fetch, ROPE];
AMFilesImpl: CEDAR MONITOR -- protects paths
IMPORTS FS, Rope
EXPORTS AMFiles
= BEGIN OPEN Rope;
pathPrefixes: PUBLIC LIST OF ROPELIST[NIL, "///", "///Commands/"];
NIL => use the current default for the running process (do this first)
///Commands/ => use the Commands subdirectory
/// => use the root directory
FullFileName: PUBLIC PROC [shortName: ROPE, createTime: BasicTime.GMT ← BasicTime.nullGMT] RETURNS[fullName: ROPENIL] = {
returns NIL if not found
firstChar: CHAR = shortName.Fetch[0];
IF firstChar = '[ OR firstChar = '/ OR firstChar = '< THEN RETURN[shortName];
FOR paths: LIST OF ROPE ← pathPrefixes, paths.rest UNTIL paths = NIL DO
ENABLE FS.Error => IF error.group # bug THEN LOOP;
RETURN[FS.FileInfo[name: shortName, wantedCreatedTime: createTime, wDir: paths.first
! FS.Error => IF error.group # bug THEN LOOP
].fullFName];
ENDLOOP;
};
FullFileNameList: PUBLIC PROC [shortName: ROPE, createTime: BasicTime.GMT ← BasicTime.nullGMT] RETURNS[fullNameList: LIST OF ROPENIL] = {
fullName: ROPENIL;
firstChar: CHAR = shortName.Fetch[0];
tail: LIST OF ROPENIL;
IF firstChar = '[ OR firstChar = '/ OR firstChar = '< THEN RETURN[CONS[shortName, NIL]];
FOR paths: LIST OF ROPE ← pathPrefixes, paths.rest UNTIL paths = NIL DO
new: LIST OF ROPELIST[
FS.FileInfo[
name: shortName, wantedCreatedTime: createTime, wDir: paths.first
! FS.Error => IF error.group # bug THEN LOOP
].fullFName
];
IF fullNameList = NIL THEN fullNameList ← new ELSE tail.rest ← new;
tail ← new;
ENDLOOP;
};
OpenIt: PUBLIC PROC [shortName: ROPE, createTime: BasicTime.GMT ← BasicTime.nullGMT] RETURNS[fullName: ROPE ← NIL, openFile: FS.OpenFile ← FS.nullOpenFile] = {
procedure for opening symbol and source files (for read)
fullName ← FullFileName[shortName, createTime];
IF fullName # NIL
THEN openFile ← FS.Open[fullName ! FS.Error => {fullName ← NIL; CONTINUE}];
};
PrependPathPrefix: PUBLIC ENTRY PROC[pathPrefix: ROPE] = {
ENABLE UNWIND => NULL;
Add in a search path. Always put the current inherited working directory first in the list.
pathPrefixes ← CONS[NIL, CONS[pathPrefix, pathPrefixes.rest]];
};
END.