[net.sources] OSSI: SISystem

biagioni@unc.UUCP (Edoardo Biagioni) (11/06/86)

(***************************************************************************)
(***                                                                     ***)
(***                                                                     ***)
(***                        O  S  S  I                                   ***)
(***                        ==========                                   ***)
(***                                                                     ***)
(**)               DEFINITION MODULE SISystem;                           (**)
(***               ==========================                            ***)
(***                                                                     ***)
(***   This module defines constants and procedures that depend on       ***)
(***   the host computer, the operating system or the compiler.          ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Hardware:             VAX-11                                      ***)
(***   Operating System:     UNIX BSD 4.2                                ***)
(***   Compiler:             Cambridge                                   ***)
(***                                                                     ***)
(***   Version:      3.0                                                 ***)
(***   Implemented:  see copyright                                       ***)
(***   Date:         1986-03-12                                          ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Copyright 1984, 1985, 1986 by                                     ***)
(***      E. S. Biagioni                                                 ***)
(***      G. Heiser                                                      ***)
(***      K. Hinrichs                                                    ***)
(***      C. Muller                                                      ***)
(***                                                                     ***)
(***   Institut fuer Informatik                                          ***)
(***   ETH Zuerich                                                       ***)
(***   CH 8092 Zuerich                                                   ***)
(***   Switzerland                                                       ***)
(***                                                                     ***)
(***   Department of Computer Science                                    ***)
(***   University of North Carolina                                      ***)
(***   Chapel Hill, North Carolina 27514                                 ***)
(***   U.S.A.                                                            ***)
(***                                                                     ***)
(*** Permission to copy without fee all of this material is granted      ***)
(*** provided that the copies are not made or distributed for direct     ***)
(*** commercial advantage, that this OSSI copyright notice is            ***)
(*** included in the copy, that the module is not modified in any way    ***)
(*** except where necessary for compilation on a particular system,      ***)
(*** and that the module is always distributed in its original form.     ***)
(*** Distribution of this module in a modified form without including    ***)
(*** the original version is a violation of this copyright notice.       ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Updates:                                                          ***)
(***                                                                     ***)
(***                                                                     ***)
(***************************************************************************)

EXPORT QUALIFIED
  EOS,                 (*  CONSTants  *)
  EOL,
  SIDone,
  MinChar,
  MaxChar,
  MaxCard,
  MaxInt,
  MinInt,
  MaxReal,
  MinReal,
  LeastReal,
  RealPrecision,
  MaxByteCard,
  MaxByteInt,
  MinByteInt,
  BitsPerByte,
  MSBit,
  LSBit,
  BytesPerStorageUnit,
  StorageUnitsPerByte,
  BytesPerWord,
  BytesPerCard,
  BytesPerInt,
  BytesPerReal,
  BytesPerBitset,
  BytesPerBoolean,
  BytesPerChar,
  BytesPerPointer,
  MaxArrayIndex,
  Equal,
  NotEqual,
  Greater,
  GreaterEqual,
  NotGreater,
  Less,
  LessEqual,
  NotLess,
  BYTE,                (*  TYPEs  *)
  SIResult,
  Relation,
  Relations,
  IntFloat,            (*  PROCEDUREs and functions  *)
  CardFloat,
  IntTrunc,
  IntFloor,
  CardTrunc,
  IntToCard,
  CardToInt,
  Cap,
  UnCap,
  SIMessage;

CONST  (* these constant are all system/machine-dependent *)
  EOS                 =   0C; (* string terminator; end of file marker *)
  EOL                 =  12C; (* end of line marker       *)
  SIDone              =    0; (* SIResult = 'Done'        *)
  MinChar             =   0C; (* smallest character       *)
  MaxChar             = 177C; (* largest character        *)
  MaxCard             = 0FFFFFFFFH;   (* largest cardinal *)
  MaxInt              = 7FFFFFFFH;    (* largest integer  *)
  MinInt              = - 1 - MaxInt; (* smallest integer *)
  MaxReal             = 1.7014116E38; (* 2 ** 127         *)
                                      (* largest real     *)
  MinReal             = - MaxReal;
                                      (* smallest real    *)
  LeastReal           = 2.9387359E-39;(* 2 ** -128        *)
                                      (* smallest real > 0*)
  RealPrecision       = 1.192093E-7;     (*  2 ** -23  *)
      (* smallest real > 0 to yield a number > 1.0 when added to 1.0 *)
  MaxByteCard         =  255; (* largest one-byte Cardinal*)
  MaxByteInt          =  127; (* largest one-byte Integer *)
  MinByteInt          = -128; (* smallest one-byte Integer*)
  BitsPerByte         =  8; (* number of bits in one byte *)
  MSBit               = 31; (* number of most significant bit  *)
  LSBit               =  0; (* number of least significant bit *)
(* a storage unit may be smaller than or larger than a byte.
   The smallest unit which may be allocated in an array is a
   byte. The following two constants should be used to determine
   the number of bytes needed for a given object, as follows:
   BytesPerObject = (((ObjectStorageUnits - 1) * BytesPerStorageUnit)
                     DIV StorageUnitsPerByte) + 1                   *)
  BytesPerStorageUnit =  1; (* storage on VAX is handled in BYTES *)
  StorageUnitsPerByte =  1; (* storage on VAX is handled in BYTES *)
  BytesPerCard        =  4; (* size in bytes of variables of type CARDINAL*)
  BytesPerInt         =  4; (* size in bytes of variables of type INTEGER *)
  BytesPerReal        =  4; (* size in bytes of variables of type REAL    *)
  BytesPerWord        =  4; (* size in bytes of variables of type WORD    *)
  BytesPerBitset      =  4; (* size in bytes of variables of type BITSET  *)
  BytesPerBoolean     =  4; (* size in bytes of variables of type BOOLEAN *)
  BytesPerChar        =  4; (* size in bytes of variables of type CHAR    *)
  BytesPerPointer     =  4; (* size in bytes of pointer variables         *)
  MaxArrayIndex       = 3FFFFFFEH;
      (* maximum allowed array index in ARRAY [0..ArrayIndex] OF type     *)

      (* nb: an ARRAY OF CHAR is assumed to be packed,
             independent of the value of BytesPerChar.
             The same holds for an ARRAY OF BYTE   *)
TYPE BYTE = CHAR;

     SIResult = CARDINAL;

     Relation = (less, greater, equal, unequal);
       (* a general type which may be used to report the
          results of comparisons. Comparisons between
          entities of ordered types may return less,
          greater or equal, comparisons between entries
          of non-ordered types may return equal or unequal *)

(* The following type and constants can be used to check the
   results of comparisons, e. g. "X IN GreaterEqual" returns
   a boolean value that says whether X is greater or equal *)

     Relations = SET OF Relation;

CONST Equal        = Relations {equal};
      NotEqual     = Relations {less, greater, unequal};
      Greater      = Relations {greater};
      GreaterEqual = Greater + Equal;
      NotLess      = GreaterEqual;
      Less         = Relations {less};
      LessEqual    = Less + Equal;
      NotGreater   = Less;

(* the following procedures should be used instead of FLOAT and TRUNC
   because FLOAT and TRUNC are system-dependent in their treatment of
   negative numbers and of numbers greater than MaxInt. *)
PROCEDURE IntFloat (i: INTEGER): REAL;
(* return the REAL corresponding to the INTEGER 'i' *)

PROCEDURE CardFloat (c: CARDINAL): REAL;
(* return the REAL corresponding to the CARDINAL 'c' *)

PROCEDURE IntTrunc (r: REAL): INTEGER;
(* return the INTEGER corresponding to the REAL 'r', truncated to
   the nearest integer the absolute value of which is less than or
   equal to the absolute value of 'r'.  This procedure is not
   defined for results that are not in the legal INTEGER range *)

PROCEDURE IntFloor (r: REAL): INTEGER;
(* return the INTEGER corresponding to the REAL 'r', truncated to the
   nearest integer that is less than or equal to 'r'. This procedure
   is not defined for results that are not in the legal INTEGER range *)

PROCEDURE CardTrunc (r: REAL): CARDINAL;
(* return the CARDINAL corresponding to the REAL 'r', truncated to
   the largest CARDINAL not greater than REAL 'r'. The behaviour of this
   procedure is undefined if the result is not in the legal CARDINAL range *)

PROCEDURE IntToCard (i: INTEGER): CARDINAL;
(* Type conversion with no surprises, where if 'i' is in 0..MaxCard
   it is always converted to the correct cardinal representation *)

PROCEDURE CardToInt (c: CARDINAL): INTEGER;
(* Type conversion with no surprises, where if 'c' is in 0..MaxInt
   it is always converted to the correct integer representation *)


(* The following procedure should be used instead of CAP if c may lie
   outside the range of alphabetic characters, since CAP is only
   defined on uppercase and lowercase letters *)

PROCEDURE Cap (c: CHAR): CHAR;
(* For lower-case letters returns the corresponding
   upper-case letter, for all other characters it returns the character
   itself. *)

PROCEDURE UnCap (c: CHAR): CHAR;
(* For upper-case letters returns the corresponding lower-case letter,
   for all other characters it returns the character itself. *)

PROCEDURE SIMessage (result: SIResult; VAR message: ARRAY OF CHAR);
(* For every possible result returned by one of the Standard Interface
   procedures, returns a textual description of the state that
   corresponds to the result. If 'message' is too short for the
   description, it is truncated to fit. The messages for a given
   result are system-dependent. If result = SIDone the message
   reflects successful completion of the operation, in all other
   cases the message describes the kind of error that corresponds
   to the given 'result'. *)
    
END SISystem.