diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /sys/etc/envgets.x | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/etc/envgets.x')
-rw-r--r-- | sys/etc/envgets.x | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/sys/etc/envgets.x b/sys/etc/envgets.x new file mode 100644 index 00000000..969a660d --- /dev/null +++ b/sys/etc/envgets.x @@ -0,0 +1,62 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <knet.h> +include <fset.h> +include "environ.h" + +# ENVGETS -- Search the environment list for the named environment variable +# and return the string value if found. If not found and the process input +# is a terminal (the process is being run interactively in debug mode), generate +# a query on the terminal, read the value of the environment variable, enter +# it into the environment table, and return the value to the caller. + +int procedure envgets (key, value, maxch) + +char key[ARB] # environment variable name +char value[maxch] # string value (output) +int maxch + +char buf[SZ_FNAME] +int nchars, ttydriver, junk, in, out, ip +int gstrcpy(), envfind(), fstati(), strlen(), envputs() +extern zgetty() + +begin + # Search the environment list first. + nchars = envfind (key, value, maxch) + if (nchars >= 0) + return (nchars) + + # Key not found. If the process input CLIN is a terminal, query the + # user for the value of the environment variable. Only low level + # calls are used in the query to avoid the possibity of recursion. + + call zlocpr (zgetty, ttydriver) + iferr { + out = fstati (CLOUT, F_CHANNEL) + in = fstati (CLIN, F_CHANNEL) + } then + return (0) + + if (fstati (CLIN, F_DEVICE) == ttydriver) { + # Issue prompt, format "env.key: " + call zputty (out, "env.", 4, junk) + call zputty (out, key, strlen(key), junk) + call zputty (out, ": ", 2, junk) + call zflsty (out, junk) + + # Get value and enter in envlist, excluding the trailing newline. + + call zgetty (in, buf, SZ_FNAME, nchars) + if (nchars <= 0) + return (0) + for (ip=1; buf[ip] != '\n' && ip <= nchars; ip=ip+1) + ; + buf[ip] = EOS + junk = envputs (key, buf) + + return (gstrcpy (buf, value, maxch)) + + } else + return (0) +end |