from main.c
#else
	kcl_self = find_executable(argv[0]);
#endif


#ifdef NeXT
#include <fcntl.h>
#include <sys/stat.h>


static int
is_executable(fn)
    char *fn;
{
    struct stat s;

    return stat (fn, &s) != -1 && (s.st_mode & S_IFMT) == S_IFREG
	    && access (fn, X_OK) != -1;
}

char *
find_executable(fn)
    char *fn;
{
    char *path, *getenv();
    static char buf[MAXPATHLEN+1];
    static char msg[100];
    register char *p;

    for (p = fn; *p; p++) {
	if (*p == '/') {
	    if (is_executable (fn))
		return fn;
	    else {
		sprintf(msg, "%s is not executable", fn);
		error(msg);
	    }
	}
    }
    if ((path = getenv ("PATH")) == 0)
	error("PATH is undefined");
    do {
	p = buf;
	while (*path && *path != ':')
	    *p++ = *path++;
	if (*path)
	    ++path;
	if (p > buf)
	    *p++ = '/';
	strcpy (p, fn);
	if (is_executable (buf))
	    return buf;
    } while (*path);
    sprintf(msg, "cannot find pathname of %s", fn);
    error(msg);
}
#endif


