DEFINITION MODULE FileSystem ;

(*
   Advice:      do NOT use, FIO is cleaner, this module is
                here for compatibality purposes only.
                Hopefully one day it will be removed.

   Title:	FileSystem, allows simple use of files.
   Version:	V1.0
   Date:	Wednesday 22/1/86
   LastEdit:	Tue Oct 17 16:04:00 BST 1989
   Author:	Gaius Mulley
		Reading University

   FileSystem - another layer above the UnixStdIO, hides
   streams and select streams etc. It allows the user to Open and
   Close a File. Also allows simple character IO to/from files
   as well as allowing Record Structures to be written and read
   to/from files and default IO.

   Could be improved by adding an EOF() function, thus allowing
   File to be implemented as a 'Hidden Type'.

   Tue Oct 17 16:04:23 BST 1989 - made the FileSystem compatible with
                                  Logitech FileSystem.
                                - prefer to take the aproach as above
                                  but this means that the Logitech version
                                  needs to be altered.
*)


FROM SYSTEM IMPORT WORD ;
IMPORT FIO ;

EXPORT QUALIFIED File, Response, IO,
                 Lookup, Close, Reset,
                 ReadChar, WriteChar,
                 WriteStructToFile, ReadStructFromFile,
                 WriteStructToDefault, ReadStructFromDefault ;



TYPE
   Response = (done, notdone) ;
   IO = (read, write) ;

   File = RECORD
             res   : Response ;
             Opened: BOOLEAN ;
             in    : FIO.File ;
             out   : FIO.File ;
             io    : IO ;
          END ;


(* Lookup - opens a specified file, filename. Henceforth the file is *)
(* referenced by, f. This file is very primitive in that it can    *)
(* only be used for rw operations. ie read XOR write but not both. *)

PROCEDURE Lookup (VAR f: File ; filename: ARRAY OF CHAR ; Create: BOOLEAN) ;


(* Close - closes a specified file, f. After this call no          *)
(* reference to f should be made.                                  *)

PROCEDURE Close (VAR f: File) ;

(* Reset - does absolutley nothing. Only remains to allow modules  *)
(* to be compatable with other systems which have this procedure.  *)

PROCEDURE Reset (VAR f: File) ;


(* ReadChar - reads a character from a specified file, f.          *)

PROCEDURE ReadChar (VAR f: File ; VAR ch: CHAR) ;


(* WriteChar - writes a character to a specified file, f.          *)

PROCEDURE WriteChar (VAR f: File ; ch: CHAR) ;


(* WriteStructToFile - writes a structure record, a, to file, f.   *)
(* Any structure may be passed as an array of word.                *)

PROCEDURE WriteStructToFile (VAR f: File ; a: ARRAY OF WORD) ;


(* ReadStructFromFile - reads a structure record, a, from file, f. *)

PROCEDURE ReadStructFromFile (VAR f: File ; VAR a: ARRAY OF WORD) ;


(* WriteStructToDefault - writes a given structure to the current  *)
(* output.                                                         *)

PROCEDURE WriteStructToDefault (a: ARRAY OF WORD) ;


(* ReadStructFromDefault - reads a structure, a, from the current  *)
(* input.                                                          *)

PROCEDURE ReadStructFromDefault (VAR a: ARRAY OF WORD) ;


END FileSystem.