From 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Tue, 11 Aug 2015 16:51:37 -0400 Subject: Repatch (from linux) of OSX IRAF --- unix/gdev/sgidev/sgidispatch.c | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 unix/gdev/sgidev/sgidispatch.c (limited to 'unix/gdev/sgidev/sgidispatch.c') diff --git a/unix/gdev/sgidev/sgidispatch.c b/unix/gdev/sgidev/sgidispatch.c new file mode 100644 index 00000000..90201460 --- /dev/null +++ b/unix/gdev/sgidev/sgidispatch.c @@ -0,0 +1,70 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + */ + +#include +#include +#include +#include + +#define import_spp +#define import_error +#define import_kernel +#define import_knames +#include + + +/* + * SGIDISPATCH.C -- Determine pathname to the executable for the named SGI + * translator, and execute the translator. Pass all command line arguments + * to the child, which also inherits stdin, stdout, and stderr. + * + * Usage: sgidispatch translator [args] + */ + +#define DEF_HOST "unix" /* default host system */ +#define F_OK 0 /* access mode `file exists' */ +#ifndef X_OK +#define X_OK 1 /* access mode `executable' */ +#endif + +char *irafpath(); + + +/* MAIN -- Main entry point for SGIDISPATCH. + */ +int +main (int argc, char *argv[]) +{ + char tpath[SZ_PATHNAME+1]; + char translator[SZ_PATHNAME+1]; + int ip; + + /* Do nothing if called with no arguments. + */ + if (argc < 2) + exit (OSOK); + + /* Construct pathname to translator. + */ + strcpy (translator, argv[1]); + ip = strlen (translator); + if (strcmp (&translator[ip], ".e") != 0) + strcat (translator, ".e"); + sprintf (tpath, "%s", irafpath(translator)); + + if (access (tpath, X_OK) == ERR) { + fprintf (stderr, "Fatal (sgidispatch): unable to access SGI"); + fprintf (stderr, " translator `%s'\n", tpath); + fflush (stderr); + exit (OSOK+1); + } + + /* Set up i/o for translator and attempt to fork. + */ + argv[argc] = 0; + execv (tpath, &argv[1]); + fprintf (stderr, "Fatal (sgidispatch): unable to execv(%s, ...)\n", + tpath); + fflush (stderr); + exit (OSOK+1); +} -- cgit