MoreImpl.mesa
Copyright Ó 1988, 1992 by Xerox Corporation. All rights reserved.
Swinehart, December 2, 1991 11:45 am PST
Willie-s, May 11, 1992 9:23 pm PDT
DIRECTORY
Ascii USING [ DEL ],
Commander USING [CommandProc, Handle, Register],
CommanderBackdoor USING [AdamOrEve],
CommanderOps USING [ NextArgument ],
Convert USING [ IntFromRope ],
EditedStream USING [GetEcho, SetEcho ],
IO,
Rope USING [ROPE]
;
MoreImpl: CEDAR PROGRAM
IMPORTS Commander, CommanderBackdoor, CommanderOps, Convert, EditedStream, IO ~ {
OPEN IO;
MoreCmd: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL]
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 ***"]};
};
};
Commander.Register["More", MoreCmd, "Repeats its input"];
}.