MoreCmd: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
controlStream: IO.STREAM¬NIL;
echoStream: IO.STREAM¬NIL;
RestoreEchoStream:
PROC = {
IF echoStream#NIL THEN EditedStream.SetEcho[controlStream, echoStream];
echoStream ¬ NIL;
};
numLinesR: Rope.ROPE ¬ CommanderOps.NextArgument[cmd];
numLines: INT ¬ 0;
lineCount: INT ¬ 0;
IF numLinesR#NIL THEN numLines ¬ Convert.IntFromRope[numLinesR];
{
ENABLE {
IO.EndOfStream => { RestoreEchoStream[]; CONTINUE; };
IO.Error => GOTO Failed;
UNWIND => RestoreEchoStream[];
};
controlChar: CHAR;
waiting: BOOL ¬ FALSE;
pleaseWait: BOOL ¬ FALSE;
parentCmd: Commander.Handle ¬ CommanderBackdoor.AdamOrEve[cmd];
controlStream ← NARROW[
Commander.GetProperty[key: $ErrorInputStream, aList: cmd.propertyList]];
controlStream ¬ parentCmd.in;
IF controlStream = NIL THEN RETURN[$Failed, "*** No error stream ***"];
echoStream ¬ EditedStream.GetEcho[controlStream];
IF echoStream#NIL THEN EditedStream.SetEcho[controlStream, NIL];
WHILE
TRUE
DO
controlChar ¬ Ascii.DEL;
IF controlStream.CharsAvail[]=0
AND ~waiting
THEN {
c: CHAR ¬ cmd.in.GetChar[];
IF c = '\015 THEN c ¬ '\n;
cmd.out.PutChar[c];
IF c = '\n
THEN {
lineCount ¬ lineCount+1;
IF pleaseWait THEN waiting ¬ TRUE
ELSE IF numLines#0
AND lineCount
MOD numLines = 0
THEN {
cmd.err.PutRope["***More?"]; waiting ¬ TRUE;
};
};
}
ELSE
{
controlChar ¬ Ascii.DEL;
controlChar¬ controlStream.GetChar[! IO.Rubout => CONTINUE];
SELECT controlChar
FROM
Ascii.DEL, '. => { RestoreEchoStream[]; RETURN[$ManualTermination, "-- <del>"]; };
ENDCASE =>
IF waiting
THEN { waiting ¬ pleaseWait ¬
FALSE; lineCount ¬ 0; }
ELSE pleaseWait ¬ ~pleaseWait;
};
ENDLOOP;
RestoreEchoStream[];
EXITS
Failed => { RestoreEchoStream[]; RETURN[$Failed, "*** Uncaught IO Error ***"]};
};
};