FILE: StructuredStreamsImpl.Mesa from [Indigo]<PreCedar>Top>StructuredStreams.DF
last edited by Spreitzer December 12, 1983 1:19 pm
DIRECTORY
Rope, IO, IOUtils, UnparserBuffer, StructuredStreams;
StructuredStreamsImpl: CEDAR PROGRAM
IMPORTS IO, IOUtils, UB:UnparserBuffer
EXPORTS StructuredStreams
SHARES IO =
BEGIN
SSData: TYPE = REF SSDataRec;
SSDataRec: TYPE = RECORD [
ubh: UB.Handle];
used: CARDINAL ← 0;
SSProcs: REF IO.StreamProcs ← IO.CreateStreamProcs[
variety: output,
class: $StructuredStream,
putChar: PutChar,
flush: Flush,
close: Close];
Create: PUBLIC PROCEDURE [onTopOf: IO.STREAM, margin: INTEGER ← 69] RETURNS [ss: IO.STREAM] =
BEGIN
ssd: SSData ← NEW [SSDataRec ← [ubh: NIL]];
TRUSTED {ssd.ubh ← UB.NewHandle[]; ssd.ubh.output ← onTopOf; UB.Init[ssd.ubh]};
ss ← IO.CreateStream[streamProcs: SSProcs,
streamData: ssd,
backingStream: onTopOf];
END;
IsAnSS: PUBLIC PROC [s: IO.STREAM] RETURNS [BOOLEAN] =
BEGIN
IF s.streamData = NIL THEN RETURN [FALSE];
RETURN [ISTYPE[s.streamData, SSData]];
END;
UnderStream: PUBLIC PROC [ss: IO.STREAM] RETURNS [IO.STREAM] =
BEGIN
IF ss.streamData = NIL THEN RETURN [ss];
IF NOT ISTYPE[ss.streamData, SSData] THEN RETURN [ss];
RETURN [ss.backingStream];
END;
CloseThrough: PUBLIC PROCEDURE [self: IO.STREAM] =
BEGIN
IF NOT IsAnSS[self] THEN self.Close[]
ELSE {
ssd: SSData ← NARROW[self.streamData];
behind: IO.STREAM ← ssd.ubh.output;
self.Close[];
behind.Close[]};
END;
Begin: PUBLIC PROCEDURE [ss: IO.STREAM] = TRUSTED
BEGIN
IF IsAnSS[ss] THEN NARROW[ss.streamData, SSData].ubh.Setb[];
END;
End: PUBLIC PROCEDURE [ss: IO.STREAM] = TRUSTED
BEGIN
IF IsAnSS[ss] THEN NARROW[ss.streamData, SSData].ubh.Endb[];
END;
Bp: PUBLIC PROCEDURE [ss: IO.STREAM, united: BOOLEAN, offset: INTEGER] = TRUSTED
BEGIN
IF IsAnSS[ss] THEN
BEGIN
ssd: SSData ← NARROW[ss.streamData];
ssd.ubh.Bp[united, offset];
END;
END;
ChangeMargin: PUBLIC PROCEDURE [ss: IO.STREAM, newMargin: INTEGER ← 69] =
BEGIN
IF IsAnSS[ss] THEN
BEGIN
ssd: SSData ← NARROW[ss.streamData];
ssd.ubh.margin ← newMargin;
END;
END;
PutChar: PROCEDURE [self: IO.STREAM, char: CHAR] = TRUSTED
{ssd: SSData ← NARROW[self.streamData];
IF char = IO.CR THEN ssd.ubh.Newlineb[0]
ELSE ssd.ubh.Charb[char];
};
Flush: PROCEDURE [self: IO.STREAM] = {IO.Flush[self.backingStream]};
Close: PROC [self: IO.STREAM, abort: BOOLFALSE] =
BEGIN
IOUtils.AmbushStream[self: self, streamProcs: IOUtils.closedStreamProcs, streamData: NIL];
END;
END.