home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / modu1096.zip / GPMsym / pathlookup.def < prev    next >
Text File  |  1996-08-29  |  3KB  |  65 lines

  1. (****************************************************************)
  2. (*                                                              *)
  3. (*         Gardens Point Modula-2 Library Definition            *)
  4. (*                                                              *)
  5. (*                                                              *)
  6. (*     (c) Copyright 1996 Faculty of Information Technology     *)
  7. (*              Queensland University of Technology             *)
  8. (*                                                              *)
  9. (*     Permission is granted to use, copy and change this       *)
  10. (*     program as long as the copyright message is left intact  *)
  11. (*                                                              *)
  12. (****************************************************************)
  13.  
  14. (* !LIBRARY! *) DEFINITION MODULE PathLookup;
  15.  
  16.   FROM UxFiles IMPORT File;
  17.  
  18.   PROCEDURE FindAndOpen(pathString   : ARRAY OF CHAR;
  19.                         baseName     : ARRAY OF CHAR;
  20.                         VAR openName : ARRAY OF CHAR;
  21.                         VAR openFile : File);
  22.  
  23.   (* precondition  : pathString is nul terminated and has    *)
  24.   (*                 components separated by colon chars,    *)
  25.   (*                 openName is long enough for pathname    *)
  26.   (* postcondition : openFile <> NIL ==> file was found.     *)
  27.   (*                 openName has nul terminated absolute    *)
  28.   (*                 path name, or nul string if not found   *)
  29.  
  30.  
  31.   PROCEDURE FindAbsName(pathString   : ARRAY OF CHAR;
  32.                         baseName     : ARRAY OF CHAR;
  33.                         VAR openName : ARRAY OF CHAR;
  34.                         VAR found    : BOOLEAN);
  35.  
  36.   (* precondition  : pathString is nul terminated and has    *)
  37.   (*                 components separated by colon chars,    *)
  38.   (*                 openName is long enough for pathname    *)
  39.   (* postcondition : found = TRUE ==> file was found.        *)
  40.   (*                 openName has nul terminated absolute    *)
  41.   (*                 path name, or nul string if not found   *)
  42.  
  43.  
  44. (* example of usage : to find file "foo.mod" on path $FOOPATH --
  45.  *
  46.  *  FROM PathLookup IMPORT FindAbsName;
  47.  *  FROM ProgArgs IMPORT EnvironString;
  48.  *  FROM UxFiles IMPORT File;
  49.  *
  50.  *  VAR file  : File;
  51.  *      path  : ARRAY [0 .. 99] OF CHAR;
  52.  *      name  : ARRAY [0 .. 79] OF CHAR;
  53.  *      found : BOOLEAN;
  54.  *
  55.  *  BEGIN
  56.  *    EnvironString("FOOPATH",path);
  57.  *    FindAbsName(path,"foo.mod",name,found);
  58.  *    IF found THEN
  59.  *       (* -- do whatever *)
  60.  *    ELSE WriteString(name); WriteString(" not found"); WriteLn;
  61.  *    END;
  62.  *)
  63.  
  64. END PathLookup.
  65.