-- File: FileCommon.mesa
-- Last edited by Levin:   3-Feb-81  9:55:11

DIRECTORY
  FileDefs USING [bytesPerPage, Comparison, Position],
  Inline USING [LongNumber],
  Mopcodes USING [zDUCOMP, zINC];

FileCommon: PROGRAM
  EXPORTS FileDefs =

  BEGIN OPEN FileDefs;

  -- This module exports the portions of the FileDefs interface that are not
  -- specific to any particular file system.


  -- Procedures and Signals --

  ComparePositions: PUBLIC PROCEDURE [pos1, pos2: Position] RETURNS [Comparison] =
    BEGIN

    DoCompare: PROCEDURE [lc1, lc2: Inline.LongNumber] RETURNS [Comparison] =
      MACHINE CODE {Mopcodes.zDUCOMP; Mopcodes.zINC};

    RETURN[DoCompare[[num[pos1.byte, pos1.page]], [num[pos2.byte, pos2.page]]]]
    END;

  IncrementPosition: PUBLIC PROCEDURE [pos: Position, bytes: CARDINAL]
    RETURNS [Position] =
    -- performs the logical operation pos ← pos + bytes.
    BEGIN
    lastBytes: CARDINAL;
    WHILE bytes >= bytesPerPage DO
      pos.page ← pos.page + 1; bytes ← bytes - bytesPerPage; ENDLOOP;
    IF (lastBytes ← pos.byte + bytes) >= bytesPerPage THEN
      {pos.page ← pos.page + 1; pos.byte ← lastBytes - bytesPerPage}
    ELSE pos.byte ← lastBytes;
    RETURN[pos]
    END;

  END.