FingerCmd.mesa
Last edited by: Donahue, October 22, 1984 9:37:40 am PDT
DIRECTORY
BasicTime USING [GMT, nullGMT],
Commander USING [CommandProc, Handle, Register],
Convert USING [RopeFromCard, RopeFromTime],
FingerOps,
IO USING [BreakProc, EndOfStream, GetTokenRope, NUL, PutRope, RIS, SP, STREAM],
Rope USING [Cat, Length, ROPE];
FingerCmd: CEDAR MONITOR
IMPORTS
Commander, Convert, FingerOps, IO, Rope =
BEGIN
fingerErrorCode: FingerOps.Reason;
PerformFingerAtExec: ENTRY Commander.CommandProc =
BEGIN
ENABLE
BEGIN
IO.EndOfStream => CONTINUE;
FingerOps.FingerError => {
fingerErrorCode ← reason; GOTO FingerProblem };
END;
Break: IO.BreakProc =
BEGIN
RETURN[IF char IN [IO.NUL..IO.SP] THEN sepr ELSE other]
END;
stream: IO.STREAMIO.RIS[cmd.commandLine];
actualName, plan, pictureFile: Rope.ROPE;
data: FingerOps.ObjectData;
WHILE TRUE DO -- stop when command line is exhausted and IO.EndOfStream is raised
userNamePattern: Rope.ROPEIO.GetTokenRope[stream, Break].token;
fingerResult: FingerOps.FingerList ← FingerOps.GetMatchingObjects[pattern: userNamePattern];
matches: CARDINAL ← 0;
FOR list: FingerOps.FingerList ← fingerResult, list.rest WHILE list # NIL DO
matches ← matches + 1
ENDLOOP;
SELECT matches FROM
0 => IO.PutRope[cmd.out, Rope.Cat["\nThere were no matches on the pattern \"", userNamePattern, "\".\n"]];
1 => IO.PutRope[cmd.out, Rope.Cat["\nThere was 1 match on the pattern \"", userNamePattern, "\":\n"]];
ENDCASE => IO.PutRope[cmd.out, Rope.Cat["\nThere were ", Convert.RopeFromCard[matches], " matches on the pattern \"", userNamePattern, "\":\n"]];
UNTIL fingerResult = NIL DO
nextObject: FingerOps.FingerObject = fingerResult.first;
[actualName, plan, pictureFile, data] ← FingerOps.GetProps[nextObject];
output results
IO.PutRope[cmd.out, Rope.Cat["\n\"", nextObject.name, "\""]];
IF Rope.Length[actualName] > 0 THEN IO.PutRope[cmd.out, Rope.Cat[" (", actualName, ")"]];
IO.PutRope[cmd.out, Rope.Cat[" is a ", IF nextObject.type = person THEN "Person" ELSE "Machine"]];
IF nextObject.type = person THEN TRUSTED {
WITH personData: data^ SELECT FROM
person =>
{IF personData.mailRead # BasicTime.nullGMT THEN
IO.PutRope[cmd.out, Rope.Cat["\n\tLast read mail at ", Convert.RopeFromTime[personData.mailRead]]];
FOR mList: LIST OF FingerOps.MachineData ← personData.used, mList.rest UNTIL mList = NIL DO
IO.PutRope[cmd.out, Rope.Cat["\n\t", IF mList.first.operation = login THEN "Logged in to " ELSE "Logged out from ", mList.first.machine, " at ", Convert.RopeFromTime[mList.first.time]]]
ENDLOOP}
ENDCASE
}
ELSE TRUSTED {
WITH machineData: data^ SELECT FROM
machine =>
IO.PutRope[cmd.out, Rope.Cat["\n ", machineData.lastUser, IF machineData.operation = login THEN " Logged in to " ELSE " Logged out from ", nextObject.name, " at ", Convert.RopeFromTime[machineData.time]]];
ENDCASE
};
IF Rope.Length[plan] > 0 THEN IO.PutRope[cmd.out, Rope.Cat["\n\tPlan: ", plan]];
IO.PutRope[cmd.out, "\n"];
fingerResult ← fingerResult.rest;
ENDLOOP;
IO.PutRope[cmd.out, "\n"];
ENDLOOP;
EXITS FingerProblem => {
IO.PutRope[cmd.out,
SELECT fingerErrorCode FROM
Aborted => "\n... Transaction Aborted; Retry Finger Operation",
Error => "\n... Internal Finger Error; Contact Implementor",
Failure => "\n... Connection with server broken; try again later",
ENDCASE => NIL ] };
END;
Register commands with the Exec to perform finger and create an instance of the Finger Tool.
Commander.Register[key: "Finger", proc: PerformFingerAtExec, doc: "Perform a finger." ];
END.