<> <> <> <> DIRECTORY Commander USING [CommandProc, Register], BasicTime USING [TimeNotKnown], EditedStream USING [Rubout], ExtraIagoOps, File USING [Error], FS USING [Error], IagoOps, IO, Loader USING [BCDBuildTime], Process USING [Detach], Rope, ViewerClasses USING [Viewer], ViewerIO USING [CreateViewerStreams, GetViewerFromStream]; LocalIagoImpl: CEDAR PROGRAM IMPORTS Commander, BasicTime, EditedStream, ExtraIagoOps, File, FS, IagoOps, IO, Loader, Process, Rope, ViewerIO = BEGIN OPEN ExtraIagoOps, File; -- * * * * * * * * commands implementation * * * * * * * * QuitCommand: PROC [in,out: IO.STREAM] = { ERROR ForceExit }; <<* * * * * * * Main>> Main: PROC = { in, out: IO.STREAM; v: ViewerClasses.Viewer; [in, out] _ ViewerIO.CreateViewerStreams[name: "LocalIago", backingFile: "///temp/LocalIago.log"]; v_ ViewerIO.GetViewerFromStream[in]; v.inhibitDestroy_ TRUE; out.PutF["LocalIago of %g, started at %g", IO.time[Loader.BCDBuildTime[ExtraIagoOps.GetAddress]], IO.time[]]; out.PutRope["\n\nType \"?\" at any time if you need help.\n"]; DO ENABLE { ABORTED => EXIT; EditedStream.Rubout => { IO.PutRope[out, " XXX"]; LOOP }; }; c: IagoOps.CommandInfo = IagoOps.GetCommand[in: in, out: out, diskReadable: TRUE]; exit, overwritten: BOOL; [exit, overwritten] _ DoCommand[in, out, c]; IF exit THEN EXIT; ENDLOOP; IO.PutRope[out, "\nLeaving LocalIago ...\n"]; v.inhibitDestroy_ FALSE; in.Close[]; out.Close[]; }; DoCommand: PROC [in, out: IO.STREAM, c: IagoOps.CommandInfo] RETURNS [exit: BOOL _ FALSE, overwritten: BOOL _ FALSE] = { ENABLE { EditedStream.Rubout, IagoOps.Rubout => { IO.PutRope[out, " XXX"]; GO TO leave }; File.Error => { IO.PutRope[out, " ... \n "]; IO.PutRope[out, IagoOps.FileError[why]]; GO TO leave }; FS.Error => { IO.PutRope[out, " ... \n "]; IO.PutRope[out, IF error.explanation.Length[] # 0 THEN error.explanation ELSE "FS.Error without a message: consult an expert"]; GO TO leave }; BasicTime.TimeNotKnown => { IO.PutRope[out, " ... I can't do that without knowing the current time."]; GO TO leave }; ForceExit => { exit _ TRUE; GO TO leave }; Overwritten => { overwritten _ TRUE; GO TO leave }; }; c.commandProc[in, out]; EXITS leave => {}; }; ForceExit: ERROR = CODE; Overwritten: ERROR = CODE; Start: Commander.CommandProc = { TRUSTED {Process.Detach[FORK Main[]] } }; <<* * * * * * * start code ** register commands with Iago>> IagoOps.RegisterCommand[[QuitCommand, "Quit"]]; <<>> Commander.Register["LocalIago", Start]; END.