Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ncar!midway!ellis.uchicago.edu!goer From: goer@ellis.uchicago.edu (Richard L. Goerwitz) Newsgroups: comp.lang.icon Subject: continuation of the code orgy Message-ID: <1990Dec11.031550.9454@midway.uchicago.edu> Date: 11 Dec 90 03:15:50 GMT Sender: news@midway.uchicago.edu (News Administrator) Organization: University of Chicago Lines: 69 I get annoyed when software requires that I be in this or that directory, and refuses to poke around a bit, looking for files. To help remedy the deficiency, I wrote the procedure appended below. Right now I've only tested it under Unix and MS-DOS. I'd love it if someone would repost with additions to make it work under other operating systems. -Richard (goer@sophist.uchicago.edu) ############################################################################ # # Name: getpaths.icn # # Title: suspend elements in path environment variable # # Author: Richard L. Goerwitz # # Version: 1.3 # ############################################################################ # # Suspends, in turn, the paths supplied as args to getpaths(), # then all paths in the PATH environment variable. A typical # invocation might look like: # # open(getpaths("/usr/local/lib/icon/procs") || filename) # # Note that getpaths() will be resumed in the above context until # open succeeds in finding an existing, readable file. Getpaths() # can take any number of arguments. # ############################################################################ # # Requires: UNIX or MS-DOS # ############################################################################ procedure getpaths(base_paths[]) local paths, p static sep, trailer, trimmer initial { if find("UNIX", &features) then { sep := ":" trailer := "/" trimmer := cset(trailer || " ") } else if find("MS-DOS", &features) then { sep := ";" trailer := "\\" trimmer := cset(trailer || " ") } else stop("getpaths: OS not supported.") } suspend !base_paths paths := getenv("PATH") \paths ? { tab(match(sep)) while p := 1(tab(find(sep)), move(1)) do suspend ("" ~== trim(p,trimmer)) || trailer return ("" ~== trim(tab(0),trimmer)) || trailer } end