-- StreamDefs.Mesa  Edited by Sandman on June 30, 1980  5:05 PM
-- Mashed for use in Pilot by Martin Newell: 23-Jul-81 11:53:15
-- Last changed by Doug Wyatt, 25-Sep-81 13:29:31

StreamDefs: DEFINITIONS =
  BEGIN

  StreamHandle: TYPE = LONG POINTER TO StreamObject;

  StreamObject: TYPE = RECORD [
    reset: PROCEDURE [StreamHandle],
    get: PROCEDURE [StreamHandle] RETURNS [UNSPECIFIED],
    putback: PROCEDURE [StreamHandle, UNSPECIFIED],
    put: PROCEDURE [StreamHandle, UNSPECIFIED],
    endof: PROCEDURE [StreamHandle] RETURNS [BOOLEAN],
    destroy: PROCEDURE [StreamHandle],
    data: LONG POINTER];

  StreamError: SIGNAL [stream: StreamHandle, error: StreamErrorCode];

  StreamErrorCode: TYPE = {
    StreamType, StreamAccess, StreamOperation, StreamPosition, StreamEnd,
    StreamBug};

  -- extensions applicable to keyboard streams

  GetDefaultKey: PROCEDURE RETURNS [StreamHandle];

  GetDefaultDisplayStream: PROCEDURE RETURNS [StreamHandle];

  -- extensions applicable to disk streams

  StreamPosition,StreamIndex: TYPE = LONG CARDINAL;

  AccessOptions: TYPE = [0..7];
  Read: AccessOptions = 1;
  Write: AccessOptions = 2;
  Append: AccessOptions = 4;
  ReadWrite: AccessOptions = 3;
  WriteAppend: AccessOptions = 6;
  ReadWriteAppend: AccessOptions = 7;
  DefaultAccess: AccessOptions = 0;

  NewByteStream, NewWordStream: PROCEDURE [name: LONG STRING, access: AccessOptions]
    RETURNS [StreamHandle];
  FileNameError: SIGNAL [name: LONG STRING];
  OpenDiskStream, CloseDiskStream: PROCEDURE [stream: StreamHandle];
  CleanupDiskStream, TruncateDiskStream: PROCEDURE [stream: StreamHandle];
  FileLength: PROCEDURE [stream: StreamHandle] RETURNS [StreamIndex];
  ReadBlock, WriteBlock: PROCEDURE [
    stream: StreamHandle, address: LONG POINTER, words: CARDINAL] RETURNS [CARDINAL];

  -- StreamPosition Stuff

  GetPosition,GetIndex: PROCEDURE [stream: StreamHandle] RETURNS [StreamPosition];
  SetPosition,SetIndex: PROCEDURE [stream: StreamHandle, pos: StreamPosition];

  ModifyPosition,ModifyIndex: PROCEDURE [pos: StreamPosition, change: INTEGER]
    RETURNS [StreamPosition] = INLINE
    BEGIN
    RETURN[IF change < 0 AND pos <= ABS[change] THEN 0 ELSE pos + change];
    END;

  END.