1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
#include <string.h>
#define import_xnames
#include "bootlib.h"
char *_os_getenv();
/* OS_GETENV -- Return the value of the named environment variable. Null is
* returned if the named variable is not found.
*/
char *
os_getenv (char *envvar)
{
static char irafdir[SZ_PATHNAME+1] = "";
static char hostdir[SZ_PATHNAME+1] = "";
static char valstr[SZ_COMMAND+1];
static char errmsg[] = "environment variable `%s' not found\n";
extern char *os_subdir();
char *vp;
/* Try the standard environment first. */
memset (valstr, 0, SZ_COMMAND+1);
if ( (vp = _os_getenv (envvar, valstr, SZ_COMMAND)) )
return (vp);
/* The following maps certain well-known IRAF logical directories
* even if there is no regular (VOS) environment facility.
*/
if (irafdir[0] == EOS)
if (_os_getenv ("iraf", irafdir, SZ_PATHNAME) == NULL) {
fprintf (stderr, errmsg, "iraf");
return (NULL);
}
if (hostdir[0] == EOS)
if (_os_getenv ("host", hostdir, SZ_PATHNAME) == NULL) {
fprintf (stderr, errmsg, "host");
return (NULL);
}
/* Map the names of the well known IRAF logical directories which
* are defined portably in terms of iraf$ or host$.
*/
if ( strcmp (envvar, "lib") == 0) /* iraf/. */
strcpy (valstr, os_subdir (irafdir, "lib"));
else if (strcmp (envvar, "bin") == 0)
strcpy (valstr, os_subdir (irafdir, "bin"));
else if (strcmp (envvar, "dev") == 0)
strcpy (valstr, os_subdir (irafdir, "dev"));
else if (strcmp (envvar, "pkg") == 0)
strcpy (valstr, os_subdir (irafdir, "pkg"));
else if (strcmp (envvar, "sys") == 0)
strcpy (valstr, os_subdir (irafdir, "sys"));
else if (strcmp (envvar, "math") == 0)
strcpy (valstr, os_subdir (irafdir, "math"));
else if (strcmp (envvar, "hlib") == 0) /* host/. */
strcpy (valstr, os_subdir (hostdir, "hlib"));
else if (strcmp (envvar, "as") == 0)
strcpy (valstr, os_subdir (hostdir, "as"));
else
return (NULL);
return (valstr);
}
#ifdef NOVOS
/* _OS_GETENV -- Fetch the value of the named environment variable from the
* host environment.
*/
char *
_os_getenv (
char *envvar, /* name of environment variable */
char *outstr, /* receives value */
int maxch
)
{
PKCHAR symbol[SZ_FNAME+1];
PKCHAR value[SZ_COMMAND+1];
XINT x_maxch = SZ_COMMAND, status=1;
strcpy ((char *)symbol, envvar);
ZGTENV (symbol, value, &x_maxch, &status);
if (status < 0) {
outstr[0] = EOS;
return (NULL);
} else {
strncpy (outstr, (char *)value, maxch);
outstr[maxch] = EOS;
return (outstr);
}
}
#else
/* _OS_GETENV -- Fetch the value of the named environment variable from the
* host environment.
*/
char *
_os_getenv (
char *envvar, /* name of environment variable */
char *outstr, /* receives value */
int maxch
)
{
XCHAR x_symbol[SZ_FNAME+1];
XCHAR x_value[SZ_COMMAND+1];
XINT x_maxch = SZ_COMMAND, status=1;
extern XINT ENVFIND();
os_strupk (envvar, x_symbol, SZ_FNAME);
status = ENVFIND (x_symbol, x_value, &x_maxch);
if (status <= 0) {
outstr[0] = EOS;
return (NULL);
} else {
os_strpak (x_value, outstr, maxch);
return (outstr);
}
}
#endif
|