(****************************************************************)
(*                                                              *)
(*         Gardens Point Modula-2 Library Definition            *)
(*                                                              *)
(*                                                              *)
(*     (c) Copyright 1996 Faculty of Information Technology     *)
(*              Queensland University of Technology             *)
(*                                                              *)
(*     Permission is granted to use, copy and change this       *)
(*     program as long as the copyright message is left intact  *)
(*                                                              *)
(****************************************************************)

(* !LIBRARY! *) DEFINITION MODULE PathLookup;

  FROM UxFiles IMPORT File;

  PROCEDURE FindAndOpen(pathString   : ARRAY OF CHAR;
                        baseName     : ARRAY OF CHAR;
                        VAR openName : ARRAY OF CHAR;
                        VAR openFile : File);

  (* precondition  : pathString is nul terminated and has    *)
  (*                 components separated by colon chars,    *)
  (*                 openName is long enough for pathname    *)
  (* postcondition : openFile <> NIL ==> file was found.     *)
  (*                 openName has nul terminated absolute    *)
  (*                 path name, or nul string if not found   *)


  PROCEDURE FindAbsName(pathString   : ARRAY OF CHAR;
                        baseName     : ARRAY OF CHAR;
                        VAR openName : ARRAY OF CHAR;
                        VAR found    : BOOLEAN);

  (* precondition  : pathString is nul terminated and has    *)
  (*                 components separated by colon chars,    *)
  (*                 openName is long enough for pathname    *)
  (* postcondition : found = TRUE ==> file was found.        *)
  (*                 openName has nul terminated absolute    *)
  (*                 path name, or nul string if not found   *)


(* example of usage : to find file "foo.mod" on path $FOOPATH --
 *
 *  FROM PathLookup IMPORT FindAbsName;
 *  FROM ProgArgs IMPORT EnvironString;
 *  FROM UxFiles IMPORT File;
 *
 *  VAR file  : File;
 *      path  : ARRAY [0 .. 99] OF CHAR;
 *      name  : ARRAY [0 .. 79] OF CHAR;
 *      found : BOOLEAN;
 *
 *  BEGIN
 *    EnvironString("FOOPATH",path);
 *    FindAbsName(path,"foo.mod",name,found);
 *    IF found THEN
 *       (* -- do whatever *)
 *    ELSE WriteString(name); WriteString(" not found"); WriteLn;
 *    END;
 *)

END PathLookup.
