DIRECTORY Ascii, IO, Process, Rope, SimpleStreams, TypeScript, ViewerOps; SimpleStreamsOnTypeScriptImpl: CEDAR MONITOR IMPORTS IO, Process, Rope, SimpleStreams, TypeScript, ViewerOps = BEGIN MyRec: TYPE = RECORD [ ts: TypeScript.TS, alive: BOOL ฌ TRUE ]; TSCreateSimpleStreams: SimpleStreams.CreateProcType = { hh: REF MyRec ฌ NEW[MyRec]; IF Rope.IsEmpty[header] THEN header ฌ "Simple Stream"; hh.ts ฌ TypeScript.Create[info: [name: header]]; out ฌ IO.CreateStream[outputStreamProcs, hh]; in ฌ IO.CreateStream[inputStreamProcs, hh]; hasEcho ฌ FALSE; }; inputStreamProcs: REF IO.StreamProcs ฌ IO.CreateStreamProcs[ variety: $input, class: $X11SimpleStreamsInput, charsAvail: MyCharsAvail, getChar: MyGetChar, close: MyCloseBoth ]; outputStreamProcs: REF IO.StreamProcs ฌ IO.CreateStreamProcs[ variety: $output, class: $X11SimpleStreamsOutput, putChar: MyPutChar, eraseChar: MyEraseChar, close: MyCloseBoth ]; MyPutChar: PROC [self: IO.STREAM, char: CHAR] = { hh: REF MyRec = NARROW[self.streamData]; IF hh.ts.destroyed THEN GOTO oops; IF char=Ascii.BS THEN TypeScript.BackSpace[hh.ts ! TypeScript.Destroyed => {GOTO oops}] ELSE TypeScript.PutChar[hh.ts, char ! TypeScript.Destroyed => {GOTO oops}]; EXITS oops => {MyCloseBoth[self]; ERROR IO.Error[StreamClosed, self]}; }; MyGetChar: PROC [self: IO.STREAM] RETURNS [ch: CHAR] = { hh: REF MyRec = NARROW[self.streamData]; IF hh.ts.destroyed THEN GOTO oops; ch ฌ TypeScript.GetChar[hh.ts ! TypeScript.Destroyed => {GOTO oops}]; IF ch=4C THEN MyCloseBoth[self]; --**works only if somebody is asking for input... EXITS oops => {MyCloseBoth[self]; ERROR IO.Error[StreamClosed, self]}; }; MyEraseChar: PROC [self: IO.STREAM, char: CHAR] = { hh: REF MyRec = NARROW[self.streamData]; IF hh.ts.destroyed THEN GOTO oops; TypeScript.BackSpace[hh.ts ! TypeScript.Destroyed => {GOTO oops}]; EXITS oops => {MyCloseBoth[self]; ERROR IO.Error[StreamClosed, self]}; }; MyCharsAvail: PROC [self: IO.STREAM, wait: BOOL] RETURNS [n: INT] = { hh: REF MyRec = NARROW[self.streamData]; IF hh.ts.destroyed THEN GOTO oops; IF wait THEN { WHILE ~TypeScript.CharsAvailable[hh.ts ! TypeScript.Destroyed => GOTO oops] DO Process.Pause[1]; ENDLOOP; RETURN [1] }; IF TypeScript.CharsAvailable[hh.ts ! TypeScript.Destroyed => GOTO oops] THEN RETURN [1] ELSE RETURN [0]; EXITS oops => {MyCloseBoth[self]; n ฌ LAST[INT]}; }; SetDead: ENTRY PROC [hh: REF MyRec] RETURNS [was: BOOLฌFALSE] = { ENABLE UNWIND => NULL; IF hh#NIL THEN {was ฌ hh.alive; hh.alive ฌ FALSE}; }; MyCloseBoth: PROC [self: IO.STREAM, abort: BOOL ฌ FALSE] = { hh: REF MyRec = NARROW[self.streamData]; wasAlive: BOOL ฌ SetDead[hh]; IF wasAlive THEN { ViewerOps.DestroyViewer[hh.ts] }; }; SimpleStreams.ImplementCreate[$TypeScript, TSCreateSimpleStreams]; END. ฮ SimpleStreamsOnTypeScriptImpl.mesa Copyright ำ 1988, 1992 by Xerox Corporation. All rights reserved. Christian Jacobi, September 2, 1988 11:31:49 am PDT Christian Jacobi, March 27, 1992 4:49 pm PST สD•NewlineDelimiter –(cedarcode) style™code™"Kšœ ฯeœ7™BKšœ0ฯk™3K™,—K˜šž œ˜ Kšœžœ6˜?—šฯnœžœž˜,Kšžœžœ7˜A—Kšžœ˜K˜šœžœžœ˜Kšœžœ˜Kšœžœž˜Kšœ˜—K˜šŸœ"˜7Kšœžœ žœ˜Kšžœžœ˜6K˜0Kšœžœ%˜-Kšœžœ$˜+Kšœ žœ˜Kšœ˜—K˜– "cedar" stylešœžœžœžœ˜