TempusImpl.mesa; Edited by Teitelman on June 22, 1983 9:21 am
DIRECTORY
AMBridge USING [IsRemote, TVToLC],
Commander USING [Register, CommandProc],
CommandProcOps USING [EventFailed],
IO USING [AttachTVPrintProc, PutRope, STREAM, TVPrintProc],
Rope USING [Cat, Substr, ROPE],
Tempus USING [Packed, Unintelligible, PackedSeconds, SecondsToPacked, MakeRope, defaultTime, Parse],
ViewerClasses USING [Viewer],
ViewerOps USING [FindViewer, DestroyViewer]
;
TempusUtilImpl: CEDAR PROGRAM
IMPORTS AMBridge, Commander, CommandProcOps, IO, Rope, Tempus, ViewerOps
SecondsPrintProc: IO.TVPrintProc =
TRUSTED {
-- AMBridge
s: Tempus.PackedSeconds;
t: Tempus.Packed;
IF AMBridge.IsRemote[tv] THEN ERROR; -- shouldnt be called. TVPrintProc says can't handle remote.
s ← LOOPHOLE[AMBridge.TVToLC[tv]];
t ← SecondsToPacked[s];
IF t = defaultTime THEN stream.PutRope["{current time}"]
ELSE stream.PutRope[MakeRope[time: t, precision: seconds, includeDayOfWeek: TRUE]];
};
PackedPrintProc: IO.TVPrintProc =
TRUSTED {
-- AMBridge
t: Tempus.Packed;
IF AMBridge.IsRemote[tv] THEN ERROR; -- shouldnt be called. TVPrintProc says can't handle remote.
t ← LOOPHOLE[AMBridge.TVToLC[tv]];
IF t = defaultTime THEN stream.PutRope["{current time}"]
ELSE stream.PutRope[MakeRope[time: t, precision: seconds, includeDayOfWeek: TRUE]];
};
WhenIs: Commander.CommandProc = {
err: Rope.ROPE;
t: Packed;
[t, ] ← Parse[cmd.commandLine !
Unintelligible => {
err ←
SELECT ec
FROM
invalid => "Invalid",
tooVague => "Too Vague",
overConstrained => "Over Constrained",
nothingSpecified => "Not a time",
notImplemented => "Not Implemented",
ENDCASE => ERROR;
IF vicinity # -1
THEN err ← Rope.Cat[
err,
": ",
Rope.Substr[base: rope, len: vicinity],
"<>",
Rope.Substr[base: rope, start: vicinity]
];
CONTINUE;
};
];
IF err # NIL THEN CommandProcOps.EventFailed[handle: cmd, msg: err];
cmd.out.PutRope[MakeRope[time: t, includeDayOfWeek: TRUE]];
TRUSTED { when StoreInSymTab is implemented in CommandProcOps put this back.
UserExecPrivate.StoreInSymTab[value: AMBridge.TVForReferent[NEW[Packed ← t]], event: event, exec: exec];
};
};
WhenIs: UserExec.CommandProc = {
err: Rope.ROPE;
t: Packed;
[t, ] ← Parse[event.commandLine !
Unintelligible => {
err ← SELECT ec FROM
invalid => "Invalid",
tooVague => "Too Vague",
overConstrained => "Over Constrained",
nothingSpecified => "Not a time",
notImplemented => "Not Implemented",
ENDCASE => ERROR;
IF vicinity # -1 THEN err ← Rope.Cat[
err,
": ",
Rope.Substr[base: rope, len: vicinity],
"<>",
Rope.Substr[base: rope, start: vicinity]
];
CONTINUE;
};
];
IF err # NIL THEN UserExecPrivate.EventFailed[event: event, msg: err];
UserExec.GetStreams[exec].out.PutRope[MakeRope[time: t, includeDayOfWeek: TRUE]];
TRUSTED {
UserExecPrivate.StoreInSymTab[value: AMBridge.TVForReferent[NEW[Packed ← t]], event: event, exec: exec];
};
};
IO.AttachTVPrintProc[type: CODE[Tempus.PackedSeconds], tvPrintProc: SecondsPrintProc, canHandleRemote: FALSE ! ANY => CONTINUE];
IO.AttachTVPrintProc[type: CODE[Tempus.Packed], tvPrintProc: PackedPrintProc, canHandleRemote: FALSE ! ANY => CONTINUE]; -- redefines printproc in basic system so that includes day of week.
Commander.Register["WhenIs", WhenIs, "For testing time.parse"];
{oldClock: ViewerClasses.Viewer ← ViewerOps.FindViewer["Clock"]; -- going to load myclock so pretendits works.
IF oldClock # NIL THEN ViewerOps.DestroyViewer[oldClock];
};
END.