CheckBasicLoadees.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Russ Atkinson, March 12, 1985 1:07:08 pm PST
DIRECTORY
Commander USING [CommandProc, Register],
DefaultRemoteNames USING [Get],
FS USING [Error, FileInfo, StreamOpen],
IO USING [BreakProc, GetChar, GetTokenRope, PutF, PutFR, STREAM],
Process USING [CheckForAbort],
Rope USING [Flatten, Length, Replace, ROPE, Run, SkipOver, SkipTo];
CheckBasicLoadees: CEDAR PROGRAM
IMPORTS Commander, DefaultRemoteNames, FS, IO, Process, Rope
= BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
CheckBasicLoadeesCommand: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REFNIL, msg: ROPENIL]
CommandObject = [
in, out, err: STREAM, commandLine, command: ROPE,
propertyList: List.AList, procData: CommandProcHandle]
stream: STREAM = FS.StreamOpen["Basic.Loadees"];
currentDir: ROPE ← DefaultRemoteNames.Get[].current;
currentDirLen: INT = Rope.Length[currentDir];
previousDir: ROPE ← DefaultRemoteNames.Get[].previous;
previousDirLen: INT = Rope.Length[previousDir];
fileCount: INT ← 0;
LineBreak: IO.BreakProc = {
IF char = '\n THEN RETURN [break] ELSE RETURN [other];
};
DO
line: ROPEIO.GetTokenRope[stream, LineBreak].token;
start: INT = Rope.SkipOver[line, 0, " \t"];
fileName: ROPE = Rope.Flatten[line, start, Rope.SkipTo[line, start, " \n/"]];
otherName: ROPENIL;
IF Rope.Length[fileName] = 0 THEN {
IF fileCount = 0 THEN LOOP;
EXIT;
};
[] ← IO.GetChar[stream];
Process.CheckForAbort[];
{fullName: ROPENIL;
fullName ← FS.FileInfo[fileName
! FS.Error => IF error.group # bug THEN {
IO.PutF[cmd.out, "Not checked: %g,\n %g\n",
[rope[fileName]], [rope[error.explanation]]];
GO TO bailOut
}
].fullFName;
SELECT TRUE FROM
Rope.Run[fullName, 0, previousDir, 0, FALSE] = previousDirLen => {
This entry points at the previous directory, so we have to check for a new file on the release directory.
newFile: ROPE = Rope.Replace[fileName, 0, previousDirLen, currentDir];
fullName ← FS.FileInfo[newFile
! FS.Error => IF error.group # bug THEN {
IF error.code # $unknownFile THEN
IO.PutF[cmd.out, "Not checked: %g,\n %g\n",
[rope[fileName]], [rope[error.explanation]]];
GO TO bailOut
}
].fullFName;
IO.PutF[cmd.out, "More recent? %g.\n", [rope[fileName]]];
};
Rope.Run[fullName, 0, currentDir, 0, FALSE] # currentDirLen => {
This entry doe not point at either the new directory or the old, so warn the user about it. No further checking is needed.
IO.PutF[cmd.out, "Unusual directory: %g\n", [rope[fileName]]];
GO TO bailOut
};
ENDCASE => {
This file checks out nicely, so go bail out
GO TO bailOut;
};
EXITS bailOut => {};
};
fileCount ← fileCount + 1;
ENDLOOP;
msg ← IO.PutFR["%g files checked.\n", [integer[fileCount]]];
};
Commander.Register[
"///Commands/CheckBasicLoadees", CheckBasicLoadeesCommand,
"checks Basic.Loadees for being current."];
END.