/* * YAP_FindExecutable(argv[0]) should be called on yap initialization to * locate the executable of Yap */ void Yap_FindExecutable(char *name) { register char *cp, *cp2; struct stat stbuf; cp = (char *)getenv("PATH"); if (cp == NULL) cp = ".:/usr/ucb:/bin:/usr/bin:/usr/local/bin"; if (*Yap_argv[0] == '/') { if (oktox(Yap_argv[0])) { strcpy(Yap_FileNameBuf, Yap_argv[0]); Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE); return; } } if (*cp == ':') cp++; for (; *cp;) { /* * copy over current directory and then append * argv[0] */ for (cp2 = Yap_FileNameBuf; (*cp) != 0 && (*cp) != ':';) *cp2++ = *cp++; *cp2++ = '/'; strcpy(cp2, Yap_argv[0]); if (*cp) cp++; if (!oktox(Yap_FileNameBuf)) continue; Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE); return; } /* one last try for dual systems */ strcpy(Yap_FileNameBuf, Yap_argv[0]); Yap_TrueFileName(Yap_FileNameBuf, YapExecutable, TRUE); if (oktox(YapExecutable)) return; else Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(YapExecutable)), "cannot find file being executed"); }
this code is no being maintained anymore #include <stdio.h> #include <fcntl.h> #include <sys/types.h> #include <sys/file.h> #include <sys/param.h> #include <sys/stat.h> #include <a.out.h> #define oktox(n) \ (0==stat(n,&stbuf)&&(stbuf.st_mode&S_IFMT)==S_IFREG&&0==access(n,X_OK)) #define oktow(n) \ (0==stat(n,&stbuf)&&(stbuf.st_mode&S_IFMT)==S_IFDIR&&0==access(n,W_OK)) #ifdef mips #define MAXSECTIONS 100 #else #define MAXSECTIONS 20 #endif /* mips */ #ifdef sgi #include <symbol.h> #endif /* sgi */ #define N_TXTOFF(x) (sizeof(struct filehdr)+(x).f_opthdr+(x).f_nscns*sizeof(struct scnhdr)) /* * YAP_FindExecutable(argv[0]) should be called on yap initialization to * locate the executable of Yap */ char * Yap_FindExecutable(void) { register char *cp, *cp2; struct stat stbuf; cp = (char *)getenv("PATH"); if (cp == NULL) cp = ".:/usr/ucb:/bin:/usr/bin:/usr/local/bin"; if (*GLOBAL_argv[0] == '/') { if (oktox(GLOBAL_argv[0])) { strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]); Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE); return NULL; } } if (*cp == ':') cp++; for (; *cp;) { /* * copy over current directory and then append * argv[0] */ for (cp2 = LOCAL_FileNameBuf; (*cp) != 0 && (*cp) != ':';) *cp2++ = *cp++; *cp2++ = '/'; strcpy(cp2, GLOBAL_argv[0]); if (*cp) cp++; if (!oktox(LOCAL_FileNameBuf)) continue; Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE); return GLOBAL_Executable; } /* one last try for dual systems */ strcpy(LOCAL_FileNameBuf, GLOBAL_argv[0]); Yap_TrueFileName(LOCAL_FileNameBuf, GLOBAL_Executable, TRUE); if (oktox(GLOBAL_Executable)) return GLOBAL_Executable; else Yap_Error(SYSTEM_ERROR_INTERNAL,MkAtomTerm(Yap_LookupAtom(GLOBAL_Executable)), "cannot find file being executed"); return NULL; }