FileWriter.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
written by Paxton. March 1981
last written by Paxton. August 24, 1982 9:31 am
Russ Atkinson, July 22, 1983 10:21 am
Plass, March 1, 1985 4:47:32 pm PST
Doug Wyatt, March 2, 1985 4:30:31 pm PST
DIRECTORY
FS USING [OpenFile],
IO USING [STREAM],
MonitoredQueue USING [MQ],
Rope USING [ROPE],
RopeReader USING [Ref];
FileWriter: CEDAR DEFINITIONS
= BEGIN
ROPE: TYPE = Rope.ROPE;
Ref: TYPE = REF FileWriterBody;
FileWriterBody: PRIVATE TYPE = RECORD [
block: REF TEXT, -- current block of characters
blockList: BlockList, -- list of blocks
blockQueue: MonitoredQueue.MQ, -- monitored queue of blocks
blockCount: NAT ← 0, -- number added to queue/list
stream: IO.STREAM, -- file being written
toRope: BOOL, -- true if output to rope instead of file
closeStream: BOOL, -- true if should close stream after write
consumer: PROCESS, -- removes blocks from queue
kind: OfWriter ← unused
];
OfWriter: TYPE = {control, comment, data, unused};
BlockList: TYPE = REF BlockListBody;
BlockListBody: TYPE = RECORD[block: REF TEXT, next: BlockList];
blockSize: NAT = 512;
OpenC: PROC [capability: FS.OpenFile, start: INT ← 0, makeControl: BOOLTRUE]
RETURNS
[control, comment, data: Ref];
ToRope: PROC [makeControl: BOOLTRUE] RETURNS [control, comment, data: Ref];
ToStream: PROC [stream: IO.STREAM, makeControl: BOOLTRUE]
RETURNS
[control, comment, data: Ref];
Close: PROC [control, comment, data: Ref, textOnly: BOOL]
RETURNS
[dataLen, count: INT, output: ROPE];
WriteChar: PROC [c: CHAR, writer: Ref];
WriteRope: PROC [r: ROPE, size: INT, writer: Ref, reader: RopeReader.Ref];
WriteText: PROC [txt: REF READONLY TEXT, writer: Ref];
BumpWriter: PRIVATE PROC [writer: Ref] RETURNS [REF TEXT];
move chars to end of list and allocate a new one
END.