CommanderOnStandardStreamsImpl.mesa
Copyright Ó 1989, 1990, 1991, 1992 by Xerox Corporation. All rights reserved.
Michael Plass, June 23, 1992 1:25 pm PDT
Chauser, September 13, 1991 3:40 pm PDT
Christian Jacobi, April 2, 1992 6:53 pm PST
Willie-s, January 26, 1993 3:30 pm PST
DIRECTORY Atom, Commander, CommanderOps, IO, Process, ProcessProps, Rope, UXIO;
CommanderOnStandardStreamsImpl: CEDAR PROGRAM
IMPORTS Atom, CommanderOps, IO, Rope, Process, ProcessProps, UXIO
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
firstTime: BOOL ¬ TRUE;
NOTE: RunCommander should be first so we can make a good guess about its c-name
RunCommander: PROC ~ {
cmd: Commander.Handle ~ CommanderOps.CreateFromStreams[
in: UXIO.CreateStandardStream[input],
out: UXIO.CreateStandardStream[output]];
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𡤌OMMAND="];
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𡤌OMMAND"] ELSE "";
firstTime ¬ FALSE;
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.