=================================================================== RCS file: /home/cvs/OpenXM/src/kxx/oxlog.c,v retrieving revision 1.1.1.1 retrieving revision 1.9 diff -u -p -r1.1.1.1 -r1.9 --- OpenXM/src/kxx/oxlog.c 1999/10/08 02:12:13 1.1.1.1 +++ OpenXM/src/kxx/oxlog.c 2001/05/06 07:53:00 1.9 @@ -1,5 +1,8 @@ +/*$OpenXM: OpenXM/src/kxx/oxlog.c,v 1.8 2000/06/19 07:48:01 ohara Exp $*/ #include #include +#include +#include #include #include #include @@ -18,79 +21,90 @@ -ox /home/nobuki/kxx/ox_asir >& /dev/null 2 3 */ -main(int argc, char *argv[]) { +static int Debug_which = 1; + +/*which("xterm", getenv("PATH"));*/ +char *which(char *prog, char *path_env) +{ + extern int Debug_which ; + char *tok; + char *path; + char delim[] = ":"; + char *e = alloca(strlen(path_env)+1); + strcpy(e, path_env); + tok = strtok(e, delim); + if (Debug_which) { + fprintf(stderr, "PATH=%s\n", path_env); + } + while (tok != NULL) { + char *path = malloc(strlen(tok)+strlen(prog)+2); + sprintf(path, "%s/%s", tok, prog); + if (access(path, X_OK&R_OK) == 0) { + if (Debug_which) { + fprintf(stderr, "Found: %s\n", path); + } + return path; + } + free(path); + tok = strtok(NULL, delim); + } + return NULL; +} + +char *toFullPath(char *s) +{ + extern int Debug_which; + char *path = "/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/openwin/bin:/usr/X/bin"; + char *s2; + if (strlen(s) == 0 || strchr(s, '/') != NULL) { + return s; + } + s2 = which(s, getenv("PATH")); + if (s2 == NULL) { + if (Debug_which) { + fprintf(stderr, "Could not find arg[1] in your search path.\n"); + fprintf(stderr, "You path is %s.\n", getenv("PATH")); + fprintf(stderr, "Trying to find in the path: %s\n", path); + } + s2 = which(s, path); + /* Why? */ + } + return s2; +} + +int main(int argc, char *argv[]) +{ sigset_t sss; int i; + char *oxname; /* char *env[2]; - env[0] = NULL;*/ + env[0] = NULL;*/ sigemptyset(&sss); - sigaddset(&sss,SIGINT); - sigprocmask(SIG_BLOCK,&sss,NULL); + sigaddset(&sss, SIGINT); + sigprocmask(SIG_BLOCK, &sss, NULL); + if (argc >= 2) { + oxname = toFullPath(argv[1]); + if (oxname == NULL) { + oxname = "NULL"; + } /* Why? */ + execv(oxname, argv+1); - if (argc == 4) { - execl(argv[1],argv[1],argv[2],argv[3],NULL); - }else if (argc == 5) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],NULL); - }else if (argc == 6) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],NULL); - }else if (argc == 7) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6],NULL); - }else if (argc == 8) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6], - argv[7],NULL); - }else if (argc == 9) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6], - argv[7],argv[8],NULL); - }else if (argc == 10) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6], - argv[7],argv[8],argv[9],NULL); - }else if (argc == 11) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6], - argv[7],argv[8],argv[9],argv[10],NULL); - }else if (argc == 12) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6], - argv[7],argv[8],argv[9],argv[10],argv[11],NULL); - }else if (argc == 13) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6], - argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],NULL); - }else if (argc == 14) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6], - argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],NULL); - }else if (argc == 15) { - execl(argv[1],argv[1],argv[2],argv[3],argv[4],argv[5],argv[6], - argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],NULL); + fprintf(stderr, "\nError in oxlog: Failed to start the process.\n"); + fprintf(stderr, "oxname=%s\n", oxname); + for (i=0; i& /dev/null\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Usage example 1: oxlog /usr/X11R6/bin/xterm -icon -e /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir\n"); + fprintf(stderr, " example 2: oxlog /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir >& /dev/null\n"); exit(10); } - fprintf(stderr,"\nError in oxlog: Failed to start the process.\n"); - for (i=0; i