aboutsummaryrefslogtreecommitdiff
path: root/unix/boot/bootlib/ossysfile.c
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /unix/boot/bootlib/ossysfile.c
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'unix/boot/bootlib/ossysfile.c')
-rw-r--r--unix/boot/bootlib/ossysfile.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/unix/boot/bootlib/ossysfile.c b/unix/boot/bootlib/ossysfile.c
new file mode 100644
index 00000000..2d4f23be
--- /dev/null
+++ b/unix/boot/bootlib/ossysfile.c
@@ -0,0 +1,113 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#include <string.h>
+#include "bootlib.h"
+
+/* Uncomment the following if the kernel for this machine does not need
+ * or provide its own custom irafpath function, used if it can not be easily
+ * determine in advance what directories need to be searched.
+ */
+/* #define STANDALONE */
+
+#ifdef STANDALONE
+#define irafpath os_irafpath
+#endif
+
+char *irafpath();
+char *os_getenv();
+extern int os_access (char *fname, int mode, int type);
+
+
+/* OS_SYSFILE -- Return the pathname of a system library file. The library
+ * search order is
+ *
+ * IRAFULIB libraries, if any
+ * HSI system libraries (lib, hlib, hbin, etc.)
+ * pkglibs applications libraries, if any
+ *
+ * Hence, the IRAFULIB mechanism may be used to make use of custom copies
+ * of system files (libraries or global include files), whereas the `pkglibs'
+ * mechanism is provided to extend the system library search path to include
+ * applications specified libraries. These are intended to be the global
+ * libraries of installed layered packages, rather than private user libraries
+ * (the IRAFULIB mechanism is better for the latter).
+ */
+int
+os_sysfile (
+ char *sysfile, /* filename from include statement */
+ char *fname, /* receives filename */
+ int maxch
+)
+{
+ register char *ip, *op;
+ char *files, *ip_save;
+
+
+ /* Search the standard system libraries and exit if the named
+ * file is found.
+ */
+ strncpy (fname, irafpath(sysfile), maxch);
+ fname[maxch-1] = EOS;
+ if (strcmp (fname, sysfile) != 0)
+ return (strlen (fname));
+
+ /* Search the designated package libraries, if any.
+ */
+ if ( (files = os_getenv ("pkglibs")) ) {
+ for (ip=files; *ip; ) {
+ /* Get the next library name from the list. */
+ while (isspace(*ip) || *ip == ',')
+ ip++;
+ for (op=fname; *ip && !isspace(*ip) && *ip != ','; op++)
+ *op = *ip++;
+ *op = EOS;
+
+ /* Append the target filename. */
+ for (ip_save=ip, (ip=sysfile); (*op++ = *ip++); )
+ ;
+ ip = ip_save;
+
+ /* Exit if the file exists. */
+ if (os_access (fname, 0, 0))
+ return (strlen (fname));
+ }
+ }
+
+ return (ERR);
+}
+
+
+#ifdef STANDALONE
+static char *libs[] = { "iraf$lib/", "host$hlib/", "" };
+
+/* OS_IRAFPATH -- Portable version of the kernel irafpath() function, used
+ * if only the standard directories LIB and HLIB need to be searched.
+ */
+char *
+os_irafpath (sysfile)
+char *sysfile; /* filename from include statement */
+{
+ register char *ip, *op;
+ register int n;
+ static char outfname[SZ_PATHNAME+1];
+ char fname[SZ_PATHNAME+1];
+ int i;
+
+ strcpy (outfname, sysfile);
+
+ for (i=0; libs[i][0] != EOS; i++) {
+ strcpy (fname, libs[i]);
+ strcat (fname, sysfile);
+ if (os_access (fname, 0,0) == YES) {
+ n = SZ_PATHNAME;
+ for (ip=fname, op=outfname; --n >= 0 && (*op = *ip++); op++)
+ ;
+ *op = EOS;
+ break;
+ }
+ }
+
+ return (outfname);
+}
+#endif