-- PilotStreams.mesa  Edited by Sandman on October 2, 1980  12:30 PM

DIRECTORY
  FileStream USING [EndOf, GetIndex, GetLength, SetIndex],
  Segments USING [
    Access, AllAccess, DefaultAccess, FHandle, Read, ReadWrite, Write],
  Stream USING [EndOfStream, Handle],
  Time USING [Packed];


Streams: DEFINITIONS IMPORTS FileStream, Stream =
  BEGIN

  Address: TYPE = LONG POINTER;

  -- Assert: The word POINTER does not appear below here.

  Handle: TYPE = PRIVATE Stream.Handle;

  Access: TYPE = PRIVATE Segments.Access;
  AllAccess: Access = Segments.AllAccess;
  DefaultAccess: Access = Segments.DefaultAccess;
  Read: Access = Segments.Read;
  ReadWrite: Access = Segments.ReadWrite;
  Write: Access = Segments.Write;

  End: PROCEDURE RETURNS [SIGNAL] = INLINE {
    RETURN[LOOPHOLE[Stream.EndOfStream]]};

  Cleanup: PROCEDURE [h: Handle];

  CreateStream: PROCEDURE [file: Segments.FHandle, access: Access ← Read]
    RETURNS [Handle];

  Destroy: PROCEDURE [h: Handle];

  Ended: PROCEDURE [h: Handle] RETURNS [BOOLEAN] = INLINE {
    RETURN[FileStream.EndOf[h]]};

  FileFromStream: PROCEDURE [h: Handle] RETURNS [Segments.FHandle];

  GetIndex: PROCEDURE [h: Handle] RETURNS [LONG CARDINAL] = INLINE {
    RETURN[FileStream.GetIndex[h]]};

  GetLength: PROCEDURE [h: Handle] RETURNS [LONG CARDINAL] = INLINE {
    RETURN[FileStream.GetLength[h]]};

  GetTimes: PROCEDURE [h: Handle] RETURNS [create, write, read: Time.Packed];

  NewStream: PROCEDURE [name: STRING, access: Access ← Read] RETURNS [Handle];

  Restart: PROCEDURE [h: Handle] = INLINE {};

  SetIndex: PROCEDURE [h: Handle, i: LONG CARDINAL] = INLINE {
    FileStream.SetIndex[h, i]};

  SetTimes: PROCEDURE [h: Handle, create, write, read: Time.Packed];

  Suspend: PROCEDURE [h: Handle] = INLINE {Cleanup[h]};

  GetBlock: PROCEDURE [h: Handle, a: Address, words: CARDINAL] RETURNS [CARDINAL];

  GetByte: PROCEDURE [h: Handle] RETURNS [UNSPECIFIED [0..256)] = INLINE {
    RETURN[h.getByte[h]]};

  GetChar: PROCEDURE [h: Handle] RETURNS [CHARACTER] = INLINE {
    RETURN[LOOPHOLE[h.getByte[h]]]};

  GetWord: PROCEDURE [h: Handle] RETURNS [UNSPECIFIED] = INLINE {
    RETURN[h.getWord[h]]};

  PutBlock: PROCEDURE [h: Handle, a: Address, words: CARDINAL] RETURNS [CARDINAL];

  PutByte: PROCEDURE [h: Handle, u: UNSPECIFIED [0..256)] = INLINE {
    h.putByte[h, u]};

  PutChar: PROCEDURE [h: Handle, c: CHARACTER] = INLINE {h.putByte[h, LOOPHOLE[c]]};

  PutWord: PROCEDURE [h: Handle, u: UNSPECIFIED] = INLINE {h.putWord[h, u]};

  END.