DEFINITION MODULE InOut;    (*NW 20.6.82*)
  FROM SYSTEM IMPORT WORD;
  FROM FileSystem IMPORT File;
  EXPORT QUALIFIED
    EOL, Done, in, out, termCH,
    OpenInput, OpenOutput, CloseInput, CloseOutput,
    Read, ReadString, ReadInt, ReadCard, ReadWrd,
    Write, WriteLn, WriteString, WriteInt, WriteCard,
    WriteOct, WriteHex, WriteWrd;

  CONST EOL = 36C;
  VAR Done:  BOOLEAN;
    termCH:  CHAR;  (*terminating character in ReadInt, ReadCard*)
    in, out: File;  (*for exceptional cases only*)

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

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

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

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

  PROCEDURE Read(VAR ch: CHAR);
    (*Done := NOT in.eof*)

  PROCEDURE ReadString(VAR s: ARRAY OF CHAR);
    (*read string, i.e. sequence of characters not containing
      blanks nor control characters; leading blanks are ignored.
      Input is terminated by any character <= " ";
      this character is assigned to termCH.
      DEL is used for backspacing when input from terminal*)

  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 ReadWrd(VAR w: WORD);
    (*Done := NOT in.eof*)

  PROCEDURE Write(ch: CHAR);

  PROCEDURE WriteLn;    (*terminate line*)

  PROCEDURE WriteString(s: ARRAY OF CHAR);

  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);
  PROCEDURE WriteWrd(w: WORD);
END InOut.
