<<>> <> <> <> <> <> <> DIRECTORY AsynchronousEvents, Atom, Commander, CommanderOps, IO, Process, ProcessProps, Rope, StandardStreams; CommanderOnStandardStreamsImpl: CEDAR PROGRAM IMPORTS AsynchronousEvents, Atom, CommanderOps, IO, Rope, Process, ProcessProps, StandardStreams ~ BEGIN ROPE: TYPE ~ Rope.ROPE; firstTime: BOOL ¬ TRUE; <> RunCommander: PROC ~ { cmd: Commander.Handle ~ CommanderOps.CreateFromStreams[ in: StandardStreams.CreateStandardInputStream[], out: StandardStreams.CreateStandardOutputStream[]]; Inner: PROC ~ { result: REF ¬ $Failure; msg: ROPE ¬ NIL; hadFailure: BOOL ¬ FALSE; persist: BOOL ¬ FALSE; IF initial # NIL THEN { [result: result, msg: msg] ¬ CommanderOps.ExecuteCommand[cmd, initial]; }; IF msg # NIL THEN { IO.PutRope[cmd.out, msg]; IO.PutRope[cmd.out, "\n"]; }; IF result=$Failure THEN { IO.PutRope[cmd.out, "[[COMMANDER_INITIAL_COMMAND="]; IO.PutRope[cmd.out, initial]; IO.PutRope[cmd.out, "]]\n"]; }; hadFailure ¬ CommanderOps.ReadEvalPrintLoop[cmd]; persist ¬ Rope.Size[GetEnv[cmd, "COMMANDER_INITIAL_PERSIST"]] > 0 OR Atom.GetProp[$CommanderOnStandardStreams, $DontExit]#NIL; IF NOT persist THEN IO.PutRope[cmd.out, " Exiting Initial Commander\n"]; IF hadFailure THEN {IO.PutRope[cmd.err, " (some commands failed)\n"];}; <<--Hack to prevent X11Viewers from disappearing>> WHILE persist DO Process.Pause[400000] ENDLOOP; }; initial: ROPE ~ IF firstTime THEN GetEnv[cmd, "COMMANDER_INITIAL_COMMAND"] ELSE ""; firstTime ¬ FALSE; AsynchronousEvents.RegisterInterest[SIGINT, TRUE]; -- turn user's ­C into ABORTED signal ProcessProps.AddPropList[LIST[NEW[Atom.DottedPairNode ¬ ["",""]]], Inner]; -- dummy prop list so SetProcessProperty has a chance to work. }; GetEnv: PROC [cmd: Commander.Handle, key: ROPE] RETURNS [ROPE] ~ { WITH CommanderOps.GetProp[cmd, Atom.MakeAtom[key]] SELECT FROM rope: ROPE => RETURN [rope]; ENDCASE => RETURN [NIL]; }; RunCommander[]; END.