(*
    Title: 	FileIO - Definitions
    LastEdit:	Wed May 23 14:35:19 1984
    Author: 	Mick Jordan
		Acorn Research Centre
*)

DEFINITION MODULE FileIO;

(* Streams interface to the UNIX file system. *)

FROM Streams IMPORT STREAM;

EXPORT QUALIFIED 

        FILEMODE, 
        READBYOWNER, WRITEBYOWNER, EXECUTEBYOWNER,
        READBYGROUP, WRITEBYGROUP,EXECUTEBYGROUP,
        READBYWORLD, WRITEBYWORLD, EXECUTEBYWORLD,
    
        FindInput, FindOutput, FindModeOutput, FindInOutput;

TYPE    FILEMODE = SET OF [0 .. 8];  (* File creation modes *)

CONST   READBYOWNER = FILEMODE {8};  WRITEBYOWNER = FILEMODE {7}; 
     EXECUTEBYOWNER = FILEMODE {6};
     
        READBYGROUP = FILEMODE {5};  WRITEBYGROUP = FILEMODE {4}; 
     EXECUTEBYGROUP = FILEMODE {3};

        READBYWORLD = FILEMODE {2};  WRITEBYWORLD = FILEMODE {1}; 
     EXECUTEBYWORLD = FILEMODE {0};

(*  The default FILEMODE used when creating files by FindOutput is
    initialised to READBYOWNER+WRITEBYOWNER
                  +READBYGROUP+WRITEBYGROUP
                  +READBYWORLD+WRITEBYWORLD
    Note that this is modified by the current 'umask' setting,  which
    normally strips of the WRITEBYGROUP and WRITEBYWORLD bits.
*)

PROCEDURE FindInput(name : ARRAY OF CHAR) : STREAM;
(*  Open an input stream to file 'name'. *)

PROCEDURE FindOutput(name : ARRAY OF CHAR) : STREAM;
(*  Open an output stream to file 'name'.
    If the file does not exist it is created with FILEMODE DefaultMode,
    otherwise it is truncated to zero length.
*)

PROCEDURE FindInOutput(name : ARRAY OF CHAR) : STREAM;
(*  Open an input/output stream to file 'name'.
    If the file does not exist it is created with FILEMODE DefaultMode,
    otherwise it is truncated to zero length.
    It is then closed and re-opened for read and write access.
*)
    
PROCEDURE FindModeOutput(name : ARRAY OF CHAR;  mode : FILEMODE) : STREAM;
(*  As FindOutput, but if it does not exist, it is created with
    FILEMODE = mode.
*)

END FileIO .
