diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /unix/os/zgcmdl.c | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'unix/os/zgcmdl.c')
-rw-r--r-- | unix/os/zgcmdl.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/unix/os/zgcmdl.c b/unix/os/zgcmdl.c new file mode 100644 index 00000000..2624ec73 --- /dev/null +++ b/unix/os/zgcmdl.c @@ -0,0 +1,91 @@ +#include <stdio.h> +#define import_kernel +#define import_knames +#define import_spp +#include <iraf.h> + +extern char *environ[]; +#ifdef MACOSX +extern char ***_NSGetArgv(); +extern int *_NSGetArgc(); +#endif + +#ifdef LINUXPPC +#define xargc f__xargc +#define xargv f__xargv +#endif + +#ifdef LINUX +extern char **xargv; /* defined in getarg(3f); requires libU77! */ +extern int xargc; +#else +static char **xargv = NULL; +static int xargc = 0; +#endif + +/* ZGCMDL -- Get the host system command line used to invoke this process. + * There does not seem to be any straightforward way to do this for UNIX, + * but the argc,argv info is evidently pushed on the stack immediately before + * the environment list, so we can locate the ARGV array by searching back + * up the stack a bit. This is very host OS dependent. + */ +int +ZGCMDL ( + PKCHAR *cmd, /* receives the command line */ + XINT *maxch, /* maxch chars out */ + XINT *status +) +{ + register char *ip, *op; + register int n; + char **argv; + +#ifdef MACOSX + argv = *_NSGetArgv(); + xargc = *_NSGetArgc(); + xargv = argv; + +#else + unsigned int *ep; + register int narg; + + + if (!(argv = xargv)) { + /* Locate the ARGV array. This assumes that argc,argv are + * stored in memory immediately preceeding the environment + * list, i.e., + * + * argc + * argv[0] + * argv[1] + * ... + * argv[argc-1] + * NULL + * env[0] <- environ + * env[1] + * ... + * + * !! NOTE !! - This is very system dependent! + */ + ep = ((unsigned int *) *environ) - 1; + for (narg=0; *(ep-1) != (unsigned int)narg; narg++) + --ep; + xargc = narg; + argv = (char **)ep; + } +#endif + + /* Reconstruct the argument list. + */ + for (op=(char *)cmd, n = *maxch, argv++; n >= 0 && *argv; argv++) { + if (op > (char *)cmd && --n >= 0) + *op++ = ' '; + for (ip = *argv; --n >= 0 && (*op = *ip++); op++) + ; + } + + *op = EOS; + *status = op - (char *)cmd; + + return (XOK); +} |