DEFINITION MODULE FileUtil;

(*
    Title: 	Useful file functions
    LastEdit:	"Tue Jul 16 13:29:48 1985"
    Author: 	ahj
		Cambridge University Computer Laboratory
*)

FROM Streams IMPORT Stream ;

EXPORT QUALIFIED Readln, SkipLayout, SkipLeadingSpaces,
                 SkipSpacesToEndOfLine, ReadWord,
                 ForceLink, ForceRename, ForceUnlink,
                 OpenStreamFromFile, OpenStreamToFile;

PROCEDURE OpenStreamFromFile (FileName : ARRAY OF CHAR ;
                              VAR OpenStream : Stream) : BOOLEAN ;
(* Returns TRUE iff the current input stream is now from FileName *)

PROCEDURE OpenStreamToFile (FileName : ARRAY OF CHAR ;
                            VAR OpenStream : Stream) : BOOLEAN ;
(* Returns TRUE iff the current output stream is now from FileName *)

PROCEDURE ForceUnlink (LinkName : ARRAY OF CHAR) : INTEGER ;
(* Unlink this name, returning the error code.
   If this is used wherever files are deleted, then the
   implementation may be changed to allow the files to
   hang around for debugging purposes *)

PROCEDURE ForceLink (FileName, LinkName : ARRAY OF CHAR) : INTEGER ;
(* Unlink LinkName if it exists, then make LinkName refer to FileName,
   returning the SysLink error code *)

PROCEDURE ForceRename (FileName, LinkName : ARRAY OF CHAR) : INTEGER ;
(* As ForceSysLink, but unlink FileName afterwards *)

PROCEDURE Readln (s : Stream) ;
(* Skips to the beginning of the next line *)
    
PROCEDURE SkipLayout (s : Stream) : CHAR ;
(* Skips non-printing layout *)
    
PROCEDURE SkipLeadingSpaces (s : Stream) ;
(* Skips leading spaces *)
    
PROCEDURE ReadWord (VAR s : ARRAY OF CHAR ;
                    st : Stream) ;
(* Reads non-layout characters into s, adding 0C as terminator *)

PROCEDURE SkipSpacesToEndOfLine (s : Stream) ;
(* Reports if any non-space characters are encountered *)

END FileUtil.
