DEFINITION MODULE MkFile;
(* 29.11.88 / ms *)
(*$ LargeVars:=FALSE NameChk:=FALSE *)

(* 10.10.87/ms: added srcFile to FileType. Used by debugger!
 *  14.2.88/ms:	added modFile, defFile instead of srcFile.
 *  14.7.88/ms:	added binFile and all the comments.
 * 29.11.88/ms:	added return value from ReadPathTable
 * 10.06.90/bp: neue Objtypen für 68010...
 *		NIEMALS wieder DupLock/UnLock!!!
 *)

FROM DosD IMPORT
 FileLockPtr;

CONST
 pathFileName="path";
 obName='obj/';
 txName='txt/';

TYPE
 FileType=(defFile,modFile,symFile,
 	   objFile,ob1File,ob2File,ob3File,ob4File,ob8File,refFile,binFile);

(*
 * Now we're up to 11 different file types, we started with just 3 types.
 * This should cover all possibilities used within M2Amiga. Did I/we miss
 * one? For each of these types a extension and a subdirectory are defined.
 * These definitions cannot be changed by the user. I don't think it is
 * necessary but maybe you or the users want it badly.
 *
 * These definitions are:	FileType	dir	ext
 *				defFile		src	.def
 *				modFile		src	.mod
 *				symFile		sym	.sym
 *				objFile		obj	.obj,.ob1....
 *				refFile		ref	.ref
 *				binFile		bin
 *
 * M2Amiga should allow you to use a main project directory containing
 * just subdirectories, their icons and eventually a local m2path file.
 *)

PROCEDURE GetFileName(VAR name: ARRAY OF CHAR; VAR len,trenn: INTEGER;
                      type: FileType; module: ARRAY OF CHAR; new: BOOLEAN);
(*
 * GetFileName is used to find the filename of a file of <type> for <module>
 * which is returned in <name> and <len>.
 * If <new> is FALSE, it is assumed that an appropriate file must exist
 * somewhere along the path. If such a file is found its complete name
 * is returned else this procedure returns the local name as generated with
 * <new> set to TRUE.
 * If <new> is TRUE only a local filename suitable for opening such a
 * file is generated. Setting <new> to TRUE can also be used to limit the
 * search for the local directory and subdirectories, however you have to check
 * for yourself if such a file already exists.
 * trenn=-1: nodir, sonst pos des "/" oder ":" dir,name
 * m2:mod/txt/test.obj --> trenn=6
 *)

PROCEDURE ReadPathTable(name: ARRAY OF CHAR);
(*
 * The global path table is read in the initialization of this module, local
 * path tables must be read after each change of directory.This local path
 * table then is used until a next call to ForgetPathTable. The default name
 * is defined in this module <pathFileName>.
 * If the current directory is a subdirectory within a project structure,
 * ReadPathTable changes the directory to the project's main directory.
 *)

PROCEDURE ForgetPathTable;
(*
 * Geht wieder ins HauptDirectory, UnLock alle neuen Locks
 * Dies ist nötig geworden, weil m2l und m2c nun ein cd-Kommando besitzen!
 * Muß VOR einem CD-Wechsel aufgerufen werden!
 * Die anderen Programme können so bleiben, ReadPathTable macht auch Forget.
 *)

PROCEDURE GetInputFile(VAR name: ARRAY OF CHAR; VAR len: INTEGER;
                       type: FileType; givenName: ARRAY OF CHAR);

(*
 * GetInputFile now allows you to get an input file name from incomplete
 * user specifications. This allows to use programs like m2c and m2l easier.
 * Now the module name is sufficient to find the appropriate input file.
 * GetInputFile first checks if <givenName> contains a path and/or the correct
 * extension for this type. Then the missing parts are added to create a
 * valid filename for <type> in the current project.
 *
 * Examples:	givenName		name
 *		obj/dummy.obj		obj/dummy.obj
 *		obj/dummy		obj/dummy.obj
 *		dummy.obj		obj/dummy.obj
 *		dummy			obj/dummy.obj
 * BUT:		dummy.mod		obj/dummy.mod.obj
 *		src/dummy		src/dummy.obj
 *
 * NOTE:
 *
 * The compiler has to be careful using this routine, there modFile is only
 * a default but not the only type of files allowed. This may also apply to
 * other programs of M2Amiga. My solution checks for a '.' in the filename
 * at len-4 and if there is one it assumes a correct filename already given.
 * If YOU have any idea to solve this problem, you're welcome to tell me
 * you proposal. NO, checking if the given name already is a file does not
 * work because usually the binary file has the module name as its filename.
 * => m2l dummy would find an earlier version of <dummy>.
 *)
END MkFile.def
