DEFINITION MODULE InOut;

(** ------------------------------------------------------------------

                  Commodore Amiga standard InOut module

      (c) Copyright 1986 Modula-2 Software Ltd.  All Rights Reserved
      (c) Copyright 1986 TDI Software, Inc.      All Rights Reserved

    ------------------------------------------------------------------ **)


(* VERSION FOR COMMODORE AMIGA

     Original Author : Paul Curtis, Modula-2 Software Ltd.  03-Feb-86

     Version         : 0.01a  10-Jul-86  Paul Curtis, Modula-2 Software Ltd.
                         Added localEcho for echoing to RAW streams.
                         Added OpenInputOutputFile for RAW streams.
                       0.00a  03-Feb-86  Paul Curtis, Modula-2 Software Ltd.
                         Original according to "Programming in
                         Modula-2" (third edition.)

  *)


  CONST EOL = 12C;  (*LF*)
  VAR Done:  BOOLEAN;
    termCH:  CHAR;  (*terminating character in ReadInt, ReadCard*)
    localEcho: BOOLEAN;  (* echo chars in ReadString *)


  PROCEDURE OpenInput(VAR defext: ARRAY OF CHAR);
     (*request a file name and open input file "in".
       Done := "file was successfully opened".
       If TRUE, subsequent input is read from this file.
       If name ends with ".", append extension defext*)

  PROCEDURE OpenInputFile(VAR FileName: ARRAY OF CHAR);
      (* as above by passing filename down as a parameter *)

  PROCEDURE OpenOutput(VAR defext: ARRAY OF CHAR);
     (*request a file name and open output file "out"
       Done := "file was successfully opened.
       If TRUE, subsequent output is written on this file*)

  PROCEDURE OpenOutputFile(VAR FileName: ARRAY OF CHAR);
     (* as above by passing filename down as a parameter *)

  PROCEDURE OpenInputOutputFile(VAR FileName: ARRAY OF CHAR);
     (* the input and output file are identical; this allows
        you to echo characters to a RAW stream *)

  PROCEDURE CloseInput;
     (*closes input file; returns input to terminal*)

  PROCEDURE CloseOutput;
     (*closes output file; returns output to terminal*)

  PROCEDURE CloseInputOutput;
     (*closes input & output file; returns input/output to terminal;
       only use this call for RAW streams opened by OpenInputOutputFile*)

  PROCEDURE Read(VAR ch: CHAR);
     (* Done := NOT in.eof 
        ie Done := TRUE if Read was succesful and
           Done := FALSE when the Read returns the
           end of file character in the file "in"  *)

  PROCEDURE ReadString(VAR s: ARRAY OF CHAR);
     (*read string, i.e. sequence of characters *)

  PROCEDURE ReadInt(VAR x: INTEGER);
     (*read string and convert to integer. Syntax:
         integer = ["+"|"-"] digit {digit}.
       Leading blanks are ignored.
       Done := "integer was read"*)

  PROCEDURE ReadCard(VAR x: CARDINAL);
     (*read string and convert to cardinal. Syntax:
         cardinal = digit {digit}.
       Leading blanks are ignored.
       Done := "cardinal was read"*)

  PROCEDURE Write(ch: CHAR);
     (* Writes any 8 bit character out *)

  PROCEDURE WriteLn;
     (* terminate line by writing ASCII.CR and ASCII.LF *)

  PROCEDURE WriteString ( VAR s : ARRAY OF CHAR );
     (* the string is a sequence of characters ening with ASCI.NUL *)

  PROCEDURE WriteStringRight(VAR s: ARRAY OF CHAR; n: CARDINAL);
     (*write string s with (at least) n characters on file "out".
       If n is greater than the number of characters needed,
       blanks are added preceding the string*)

  PROCEDURE WriteInt(x: INTEGER; n: CARDINAL);
     (*write integer x with (at least) n characters on file "out".
       If n is greater than the number of digits needed,
       blanks are added preceding the number*)

  PROCEDURE WriteCard(x, n: CARDINAL);
  PROCEDURE WriteOct(x, n: CARDINAL);
  PROCEDURE WriteHex(x, n: CARDINAL);

END InOut.
