FSStreamImpl.mesa
Implementation of the "workstation FS" subclass of FileStream. This is mostly a veneer over the generic FileStream; only stream creation is special.
Last Edited by: Taft, November 14, 1983 2:23 pm
Last Edited by: Schroeder, November 28, 1983 12:35 pm
DIRECTORY
FileStream USING [ErrorFromStream, OpenFileFromStream, StreamFromOpenFile, StreamFromOpenStream],
FS USING [AccessOptions, ByteCount, Close, Create, Error, ErrorDesc, ExtendFileProc, InitialPosition, Lock, Open, OpenFile, OpenOrCreate, PagesForBytes, StreamBufferParms, StreamOptions],
FSExtras USING[],
IO USING [STREAM],
Rope USING [ROPE];
FSStreamImpl: CEDAR PROGRAM
IMPORTS FileStream, FS
EXPORTS FS, FSExtras
= BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
StreamOpen: PUBLIC PROCEDURE [fileName: ROPE, accessOptions: FS.AccessOptions, streamOptions: FS.StreamOptions, keep: CARDINAL, createByteCount: FS.ByteCount, streamBufferParms: FS.StreamBufferParms, extendFileProc: FS.ExtendFileProc] RETURNS [STREAM] =
BEGIN
fileHandle: FS.OpenFile = SELECT accessOptions FROM
$read => FS.Open[name: fileName],
$create => FS.Create[name: fileName, keep: keep, pages: FS.PagesForBytes[createByteCount]],
$append => FS.OpenOrCreate[name: fileName, keep: keep, pages: FS.PagesForBytes[createByteCount]],
$write => FS.Open[name: fileName, lock: $write],
ENDCASE => ERROR;
RETURN[FileStream.StreamFromOpenFile[openFile: fileHandle, accessRights: IF accessOptions = $read THEN $read ELSE $write, initialPosition: IF accessOptions = $append THEN $end ELSE $start, streamOptions: streamOptions, streamBufferParms: streamBufferParms, extendFileProc: extendFileProc
! FS.Error => FS.Close[file: fileHandle]]];
END;
The following procedures simply re-export the ones from FileStream. However, directly exporting the procedure values imported from FileStream does not work for some reason.
StreamFromOpenFile: PUBLIC PROCEDURE [openFile: FS.OpenFile, accessRights: FS.Lock, initialPosition: FS.InitialPosition, streamOptions: FS.StreamOptions, streamBufferParms: FS.StreamBufferParms, extendFileProc: FS.ExtendFileProc] RETURNS [STREAM] =
BEGIN
RETURN [FileStream.StreamFromOpenFile[openFile: openFile, accessRights: accessRights, initialPosition: initialPosition, streamOptions: streamOptions, streamBufferParms: streamBufferParms, extendFileProc: extendFileProc]];
END;
StreamFromOpenStream: PUBLIC PROCEDURE [self: STREAM] RETURNS [STREAM] =
BEGIN
RETURN [FileStream.StreamFromOpenStream[self]];
END;
OpenFileFromStream: PUBLIC PROCEDURE [self: STREAM] RETURNS [FS.OpenFile] =
BEGIN
RETURN [FileStream.OpenFileFromStream[self]];
END;
ErrorFromStream: PUBLIC PROCEDURE [self: STREAM] RETURNS [FS.ErrorDesc] =
BEGIN
RETURN [FileStream.ErrorFromStream[self]];
END;
END.