File: ViewerIO.mesa
Teitelman on January 21, 1983 11:05 pm
DIRECTORY
Rope USING [ROPE],
IO USING [STREAM, DeliverWhenProc, IsACR],
ViewerClasses USING [Viewer]
;
ViewerIO: CEDAR DEFINITIONS IMPORTS IO =
BEGIN
CreateViewerStreams: PROC [name: Rope.ROPE, viewer: ViewerClasses.Viewer ← NIL, backingFile: Rope.ROPENIL, editedStream: BOOLTRUE] RETURNS [in: IO.STREAM, out: IO.STREAM];
If viewer is non-NIL, creates two streams, one for input, one for output, and "connects" them to the indicated viewer. Viewer must be of viewerclass TypeScript or raises RTTypesBasic.NarrowRefFault.
If viewer is NIL, creates a Viewer of class TypeScript with name name, and proceeds as above.
If backingFile is non-NIL, creates a file stream on this file (using overWrite semantics), then creates a dribble stream which outputs to the out and dribbles to the file stream, flushing every 256 characters, i.e. out ← IO.CreateDribbleStream[stream: out, dribbleTo: CreateFileStream[backingFile, overWrite], flushEveryNChars: 256]
If editedStream is TRUE, in ← CreateEditedViewerStream[in, out].
N.B. It is perfectly permissible to have more than one output stream connected to the same viewer. However, if two input streams are connected to the same viewer and a character is typed, only one of the streams will get the character.
If a viewer to which a viewer stream is connected is destroyed, the next time an attempt to do an output or input operation (or if the system is currently waiting for a character from that stream), the signal IO.ERROR[StreamClosed] will be raised.
GetViewerFromStream: PROC [stream: IO.STREAM] RETURNS[ViewerClasses.Viewer];
If stream is connected to a viewer, return corresponding viewer, otherwise NIL. stream can be one of the values returned from CreateViewerStreams, or a stream whose backingStream is connected to a viewer, i.e. if you create a dribbleStream which dribbles characters outputted to a viewer a backing file, GetViewerStream will still return the corresponding viewer.
CreateEditedViewerStream: PUBLIC PROCEDURE [in: IO.STREAM, echoTo: IO.STREAM, deliverWhen: IO.DeliverWhenProc ← IO.IsACR] RETURNS [h: IO.STREAM];
like IO.CreateEditedStream except that uses the typescript document itself as the "buffer". Thus, if editable typescripts are enabled, the user can edit any of the characters not yet read. For example, if deliverWhen = IsACR, the user can edit anything on the line that he is typing. This includes deleting material previously typed, as well as inserting new material.
NotAllowed: PRIVATE ERROR [stream: IO.STREAM];
raised by a viewers edited stream when attempt made to set echo to a stream that is not connected (possibly through backing streams) to the same viewer, or, more typically, when echoing is off during which time the buffer (viewer) gets out of synch. Caught by UserExec.
CreateMessageWindowStream: PROCEDURE RETURNS [IO.STREAM];
Characters output to the stream will be displayed in the message window when the stream is flushed.
END.
Edited on December 14, 1982 4:58 pm, by Teitelman
added NotAllowed and CreateMessageWindowStream
changes to: NotAllowed, CreateMessageWindowStream