PATHLOOK.DEF 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. (* ========================================================= *)
  2. (* Preliminary library module for Gardens Point Modula *)
  3. (* ========================================================= *)
  4. (* !LIBRARY! *) DEFINITION MODULE PathLookup;
  5. FROM UxFiles IMPORT File;
  6. PROCEDURE FindAndOpen(pathString : ARRAY OF CHAR;
  7. baseName : ARRAY OF CHAR;
  8. VAR openName : ARRAY OF CHAR;
  9. VAR openFile : File);
  10. (* precondition : pathString is nul terminated and has *)
  11. (* components separated by colon chars, *)
  12. (* openName is long enough for pathname *)
  13. (* postcondition : openFile <> NIL ==> file was found. *)
  14. (* openName has nul terminated absolute *)
  15. (* path name, or nul string if not found *)
  16. PROCEDURE FindAbsName(pathString : ARRAY OF CHAR;
  17. baseName : ARRAY OF CHAR;
  18. VAR openName : ARRAY OF CHAR;
  19. VAR found : BOOLEAN);
  20. (* precondition : pathString is nul terminated and has *)
  21. (* components separated by colon chars, *)
  22. (* openName is long enough for pathname *)
  23. (* postcondition : found = TRUE ==> file was found. *)
  24. (* openName has nul terminated absolute *)
  25. (* path name, or nul string if not found *)
  26. (* example of usage : to find file "foo.mod" on path $FOOPATH --
  27. FROM PathLookup IMPORT FindAbsName;
  28. FROM ProgArgs IMPORT EnvironString;
  29. FROM UxFiles IMPORT File;
  30. VAR file : File;
  31. path : ARRAY [0 .. 99] OF CHAR;
  32. name : ARRAY [0 .. 79] OF CHAR;
  33. found : BOOLEAN;
  34. BEGIN
  35. EnvironString("FOOPATH",path);
  36. FindAbsName(path,"foo.mod",name,found);
  37. IF found THEN
  38. WriteString("found ");
  39. WriteString(name); WriteLn;
  40. -- and do whatever
  41. ELSE WriteString("not found");
  42. END;
  43. *)
  44. END PathLookup.