(*
    Title: 	Opening Modula-2 Files - Definitions
    LastEdit:	"Tue Sep 25 15:24:01 1984"
    Author: 	Mick Jordan
		Cambridge University Computer Laboratory
*)


DEFINITION MODULE M2Files;

FROM Streams IMPORT Stream;
EXPORT QUALIFIED 
    Extension, CreateInput, CreateOutput, CreateInOutput, 
    Filename, HashExt, SetM2PathFromFile;

(*  The following procedures are as per FileIO, save that they
    open a file called 'name.ext', which is searched according the
    following strategy.

    CreateInput, CreateInOutput
    
    If 'ext' is "mod" or "def" then the file "name.ext" is looked up
    in all the directories contained in the environment variable
    M2PATH.  This string has directory names separated by a ':' and
    conventionally starts with a '.' so that the search starts in the
    current directory.  If 'ext' is not one of these it is assumed to
    be one of the derived (hidden) files (e.g .lnk) and the string
    ".ext/" is prepended to "name".  The search then proceeds
    as described above.
    
    CreateOutput
    
    The strategy is as above except that files will only be created 
    in the current directory.
    
    The name of the file actually opened is stored in the 
    variable 'Filename'.
    
*)

TYPE Extension = ARRAY [0..3] OF CHAR;
(*  filename extension, does not include the '.' *)

PROCEDURE CreateInput(name: ARRAY OF CHAR; ext: Extension): Stream;
PROCEDURE CreateOutput(name: ARRAY OF CHAR; ext: Extension): Stream;
PROCEDURE CreateInOutput(name: ARRAY OF CHAR; ext: Extension): Stream;

VAR Filename: ARRAY [0..255] OF CHAR;
(*  The name of the file actually opened.
    This variable is read-only and only valid
    for the preceding call to one of the above procedures
*)
PROCEDURE HashExt(ext: Extension);
(*  builds a hash table for files on M2PATH with the extension 'ext',
    which helps to speed up the search.
*)
PROCEDURE SetM2PathFromFile;
(*  a procedure which updates the M2PATH environment variable
    for this program from a file called 'm2path' in the current directory.
    The file is assumed to contain a line of the form:-
    
    setenv M2PATH directory-list
*)
END M2Files.
