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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <libgen.h>
#define import_spp
#define import_kernel
#define import_knames
#include <iraf.h>
static char *_ev_scaniraf (char *envvar);
static int _ev_loadcache (char *fname);
/* ZGTENV -- Get the value of a host system environment variable. Look first
* in the process environment. If no entry is found there and the variable is
* one of the standard named variables, get the system wide default value from
* the file <iraf.h>, which is assumed to be located in /usr/include.
*/
int
ZGTENV (
PKCHAR *envvar, /* name of variable to be fetched */
PKCHAR *outstr, /* output string */
XINT *maxch,
XINT *status
)
{
register char *ip, *op;
register int n;
op = (char *)outstr;
if ((ip = getenv ((char *)envvar)) == NULL)
ip = _ev_scaniraf ((char *)envvar);
if (ip == NULL) {
*op = EOS;
*status = XERR;
} else {
*status = 0;
op[*maxch] = EOS;
for (n = *maxch; --n >= 0 && (*op++ = *ip++); )
(*status)++;
}
return (XOK);
}
/*
* Code to bootstrap the IRAF environment list for UNIX.
*/
int ev_cacheloaded = 0;
/* SCANIRAF -- If the referenced environment variable is a well known standard
* variable, hardcode them to their default value if not set.
*
* Virtually all IRAF environment variables are defined in the source code and
* are portable. In particular, virtually all source directories are defined
* relative to the IRAF root directory "iraf$". Only those definitions which
* are both necessarily machine dependent and required for operation of the
* bootstrap C programs (e.g., the CL, XC, etc.) are satisfied at this level.
* These variables are the following.
*
* iraf The root directory of IRAF; if this is incorrect,
* bootstrap programs like the CL will not be able
* to find IRAF files.
*
* host The machine dependent subdirectory of iraf$. The
* actual name of this directory varies from system
* to system (to avoid name collisions on tar tapes),
* hence we cannot use "iraf$host/".
* Examples: iraf$unix/, iraf$vms/, iraf$sun/, etc.
*
* tmp The place where IRAF is to put its temporary files.
* This is normally /tmp/ for a UNIX system. TMP
* also serves as the default IMDIR.
*
*/
static char *
_ev_scaniraf (char *envvar)
{
if (!ev_cacheloaded) {
if (_ev_loadcache (NULL) == ERR)
return (NULL);
else
ev_cacheloaded++;
}
return (getenv(envvar));
}
/* _EV_LOADCACHE -- Follow the link <iraf.h> to the path of the IRAF
* installation. Cache these in case we are called again (they do not
* change so often that we cannot cache them in memory). Any errors
* in accessing the table probably indicate an error in installing
* IRAF hence should be reported immediately.
*/
static int
_ev_loadcache (char *fname)
{
static char *home, hpath[SZ_PATHNAME+1], *rpath, *lpath;
setenv("iraf", "/usr/lib/iraf/", 0);
setenv("host", "/usr/lib/iraf/unix/", 0);
/* tmp */
lpath = getenv("TMPDIR");
if (lpath == NULL) {
lpath = P_tmpdir;
}
lpath = strdup(lpath);
if (lpath[strlen(lpath)-1] != '/') {
lpath = realloc(lpath, strlen(lpath) + 2);
strcat(lpath, "/");
}
setenv("tmp", lpath, 0);
free(lpath);
/* Further environment variables required for compilation of
external packages */
lpath = strdup("");
rpath = getenv("CPPFLAGS");
if (rpath != NULL) {
lpath = realloc(lpath, strlen(lpath) + strlen(rpath) + 2);
strcat(lpath, " ");
strcat(lpath, rpath);
}
rpath = getenv("CFLAGS");
if (rpath != NULL) {
lpath = realloc(lpath, strlen(lpath) + strlen(rpath) + 2);
strcat(lpath, " ");
strcat(lpath, rpath);
}
rpath = getenv("iraf");
if (rpath != NULL) {
lpath = realloc(lpath, strlen(lpath) + strlen(rpath) + 11);
strcat(lpath, " -I");
strcat(lpath, rpath);
strcat(lpath, "include");
}
setenv("XC_CFLAGS", lpath, 0);
setenv("HSI_CF", lpath, 0);
free(lpath);
setenv("HSI_XF", "-x -Inolibc -/Wall -/O2", 0);
setenv("HSI_FF", "-g -DBLD_KERNEL -O2", 0);
rpath = getenv("LDFLAGS");
if (rpath == NULL)
setenv("HSI_LF", " ", 0);
else
setenv("HSI_LF", rpath, 0);
return (OK);
}
|