aboutsummaryrefslogtreecommitdiff
path: root/sys/etc/envgets.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/etc/envgets.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/etc/envgets.x')
-rw-r--r--sys/etc/envgets.x62
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