
DEFINITION MODULE FileInOut;

(* Library module for 
   Printing to a File  and
   Reading from a File.
 
Author:         John Forester
Last Edit:      12 Feb 86 *)

IMPORT FileSystem;

FROM InOut IMPORT WriteString, WriteLn;

FROM NumberConversion IMPORT StringToCard, StringToInt, CardToString,
                             IntToString;

FROM RealConversions IMPORT RealToString, StringToReal;


 
EXPORT QUALIFIED FileBool, FileString, FileCard, FileInt, FileReal,
                 ScanBool, ScanString, ScanCard, ScanInt, ScanReal;




PROCEDURE FileBool(VAR OutFile : FileSystem.File; Bool : BOOLEAN);
(* Prints the value of a BOOLEAN to the file OutFile. *)

PROCEDURE FileString(VAR OutFile : FileSystem.File; str  : ARRAY OF CHAR);
(* Prints the STRING str to the file OutFile *)

PROCEDURE FileCard(VAR OutFile : FileSystem.File; x, width : CARDINAL);
(* Prints the CARDINAL x to the file OutFile in w characters. *)

PROCEDURE FileInt(VAR OutFile : FileSystem.File; x  : INTEGER;
                  width : CARDINAL);
(* Prints the INTEGER x to the file OutFile in w characters. *)

PROCEDURE FileReal(VAR OutFile : FileSystem.File; x : REAL;
                   digits, width  :  INTEGER); 
(* Prints the REAL x to the file OutFile in w characters
   with 'digits' number of digits to the right of the decimal
   point.  Writes in decimal format if 'digits' is positive, 
   in exponential format if 'digits' is negative.
   For decimal format width must be => total digits + 2.
   For exponential format width must be => digits to right of
   decimal point + 8. *)

PROCEDURE ScanBool(VAR InFile : FileSystem.File; VAR Bool : BOOLEAN);
(* Reads the value of a BOOLEAN from the file InFile. *)

PROCEDURE ScanString(VAR InFile : FileSystem.File; VAR str : ARRAY OF CHAR);
(* Reads a STRING from the file InFile. *)

PROCEDURE ScanCard(VAR InFile : FileSystem.File; VAR x : CARDINAL; 
                   width  :  CARDINAL);
(* Reads w characters from the file InFile to form the value of 
   the CARDINAL x.  Maximum width is 5 characters.  *)

PROCEDURE ScanInt(VAR InFile : FileSystem.File; VAR x : INTEGER;
                  width  :  CARDINAL);
(* Reads w characters from the file InFile to form the value of
   the INTEGER x.  Maximum width is 6 characters including the
   sign for negative numbers. *)
                  
PROCEDURE ScanReal(VAR InFile : FileSystem.File; VAR x : REAL;
                   width  :  CARDINAL);
(* Reads w characters from the file InFile to form the value of
   the REAL x.  The characters may be in decimal or exponential
   format. *)
 

END FileInOut.


