CopyFromKbdImpl.mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
Swinehart, March 18, 1988 11:06:46 pm PST
DIRECTORY
Commander USING [CommandProc, Handle, Register],
CommandTool USING [ NextArgument ],
FS USING [ StreamOpen ],
IO USING [Close, GetChar, PutChar, STREAM ],
Rope USING [ Equal, Fetch, ROPE ];
CopyFromKbdImpl: CEDAR PROGRAM
IMPORTS Commander, CommandTool, FS, IO, Rope
~ BEGIN
CopyFromKbdCmd: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL]
stopChar, c: CHAR;
stopStr: Rope.ROPE;
fileName: Rope.ROPE;
s: IO.STREAM;
IF ~CommandTool.NextArgument[cmd].Equal["-q"] THEN
RETURN[$Failure, "Usage: CopyFromKbd -q <switch> <fileName>"];
stopStr ← CommandTool.NextArgument[cmd];
stopChar ← IF stopStr=NIL THEN 'Z ELSE stopStr.Fetch[0];
IF stopChar >= 'a THEN stopChar ← stopChar - ('a - 'A);
IF stopChar >= 'A THEN stopChar ← LOOPHOLE[(stopChar - 'A) + 1];
fileName ← CommandTool.NextArgument[cmd];
IF fileName=NIL THEN RETURN[$Failure, "Usage: CopyFromKbd -q <switch> <fileName>"];
s ← FS.StreamOpen[fileName, $create];
WHILE (c𡤌md.in.GetChar[])#stopChar DO s.PutChar[c]; ENDLOOP;
s.Close[];
};
Commander.Register["CopyFromKbd", CopyFromKbdCmd];
END.