home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / GETPATHS.ICN < prev    next >
Text File  |  1991-09-05  |  2KB  |  59 lines

  1. ############################################################################
  2. #
  3. #    Name:     getpaths.icn
  4. #
  5. #    Title:     suspend elements in path environment variable
  6. #
  7. #    Author:     Richard L. Goerwitz
  8. #
  9. #    Version: 1.3
  10. #
  11. #    Date:     June 1, 1991
  12. #
  13. ############################################################################
  14. #
  15. #      Suspends, in turn, the paths supplied as args to getpaths(),
  16. #  then all paths in the PATH environment variable.  A typical
  17. #  invocation might look like:
  18. #
  19. #     open(getpaths("/usr/local/lib/icon/procs") || filename)
  20. #
  21. #  Note that getpaths() will be resumed in the above context until
  22. #  open succeeds in finding an existing, readable file.  Getpaths()
  23. #  can take any number of arguments.
  24. #
  25. ############################################################################
  26. #
  27. #  Requires: UNIX or MS-DOS
  28. #
  29. ############################################################################
  30.  
  31. procedure getpaths(base_paths[])
  32.  
  33.     local paths, p
  34.     static sep, trailer, trimmer
  35.     initial {
  36.     if find("UNIX", &features) then {
  37.         sep := ":"
  38.         trailer := "/"
  39.         trimmer := cset(trailer || " ")
  40.         }
  41.     else if find("MS-DOS", &features) then {
  42.         sep := ";"
  43.         trailer := "\\"
  44.         trimmer := cset(trailer || " ")
  45.     }
  46.         else stop("getpaths:  OS not supported.")
  47.     }
  48.  
  49.     suspend !base_paths
  50.     paths := getenv("PATH")
  51.     \paths ? {
  52.     tab(match(sep))
  53.     while p := 1(tab(find(sep)), move(1))
  54.     do suspend ("" ~== trim(p,trimmer)) || trailer
  55.     return ("" ~== trim(tab(0),trimmer)) || trailer
  56.     }
  57.  
  58. end
  59.