goer@ellis.uchicago.edu (Richard L. Goerwitz) (12/11/90)
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
}
endok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (12/11/90)
In article <1990Dec11.031550.9454@midway.uchicago.edu>, goer@ellis.uchicago.edu (Richard L. Goerwitz) writes: > paths := getenv("PATH") $PATH is for *programs*. Data files do not belong there. A better approach would be to allow $env substitution in the argument to getpaths, e.g. getpaths("$HOME/lib/foo:$PROJECT/lib", file) -- The Marxists have merely _interpreted_ Marxism in various ways; the point, however, is to _change_ it. -- R. Hochhuth.