version 1.4, 1999/12/15 11:40:23 |
version 1.8, 2000/06/19 07:48:01 |
|
|
/*$OpenXM: OpenXM/src/kxx/oxlog.c,v 1.3 1999/12/15 11:31:57 takayama Exp $*/ |
/*$OpenXM: OpenXM/src/kxx/oxlog.c, v 1.7 2000/02/09 12:24:52 takayama Exp $*/ |
#include <stdio.h> |
#include <stdio.h> |
#include <signal.h> |
#include <signal.h> |
#include <string.h> |
#include <string.h> |
|
|
-ox /home/nobuki/kxx/ox_asir >& /dev/null |
-ox /home/nobuki/kxx/ox_asir >& /dev/null |
2 3 |
2 3 |
*/ |
*/ |
char *toFullPath(char *s); |
static int Debug_which = 1; |
char *which(char *s,char *env); |
|
main(int argc, char *argv[]) { |
/*which("xterm", getenv("PATH"));*/ |
sigset_t sss; |
char *which(char *prog, char *path_env) |
int i; |
{ |
char *oxname; |
extern int Debug_which ; |
/* char *env[2]; |
char *tok; |
env[0] = NULL;*/ |
char *path; |
sigemptyset(&sss); |
char delim[] = ":"; |
sigaddset(&sss,SIGINT); |
char *e = alloca(strlen(path_env)+1); |
sigprocmask(SIG_BLOCK,&sss,NULL); |
strcpy(e, path_env); |
if (argc > 1) { |
tok = strtok(e, delim); |
oxname = argv[1]; |
if (Debug_which) { |
oxname = toFullPath(oxname); |
fprintf(stderr, "PATH=%s\n", path_env); |
} |
|
if (argc == 4) { |
|
execl(oxname,oxname,argv[2],argv[3],NULL); |
|
}else if (argc == 5) { |
|
execl(oxname,oxname,argv[2],argv[3],argv[4],NULL); |
|
}else if (argc == 6) { |
|
execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],NULL); |
|
}else if (argc == 7) { |
|
execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],NULL); |
|
}else if (argc == 8) { |
|
execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6], |
|
argv[7],NULL); |
|
}else if (argc == 9) { |
|
execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6], |
|
argv[7],argv[8],NULL); |
|
}else if (argc == 10) { |
|
execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6], |
|
argv[7],argv[8],argv[9],NULL); |
|
}else if (argc == 11) { |
|
execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6], |
|
argv[7],argv[8],argv[9],argv[10],NULL); |
|
}else if (argc == 12) { |
|
execl(oxname,oxname,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(oxname,oxname,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(oxname,oxname,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(oxname,oxname,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); |
|
}else if (argc == 16) { |
|
execl(oxname,oxname,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],argv[15],NULL); |
|
}else if (argc == 17) { |
|
execl(oxname,oxname,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],argv[15],argv[16],NULL); |
|
}else { |
|
fprintf(stderr,"Error in oxlog: cannot handle argc=%d\n",argc); |
|
fprintf(stderr,"oxname=%s\n",oxname); |
|
for (i=0; i<argc; i++) { |
|
fprintf(stderr,"argv[%d]=%s ",i,argv[i]); |
|
} |
} |
fprintf(stderr,"\n"); |
while (tok != NULL) { |
fprintf(stderr,"Usage example 1: oxlog /usr/X11R6/bin/xterm -icon -e /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir\n"); |
char *path = malloc(strlen(tok)+strlen(prog)+2); |
fprintf(stderr," example 2: oxlog /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir >& /dev/null\n"); |
sprintf(path, "%s/%s", tok, prog); |
exit(10); |
if (access(path, X_OK&R_OK) == 0) { |
} |
if (Debug_which) { |
fprintf(stderr,"\nError in oxlog: Failed to start the process.\n"); |
fprintf(stderr, "Found: %s\n", path); |
fprintf(stderr,"oxname=%s\n",oxname); |
} |
for (i=0; i<argc; i++) { |
return path; |
fprintf(stderr,"argv[%d]=%s ",i,argv[i]); |
} |
} |
free(path); |
fprintf(stderr,"\n"); |
tok = strtok(NULL, delim); |
exit(20); |
} |
|
return NULL; |
} |
} |
mainold1() { |
|
sigset_t sss; |
|
int i; |
|
/* char *env[2]; |
|
env[0] = NULL;*/ |
|
sigemptyset(&sss); |
|
sigaddset(&sss,SIGINT); |
|
sigprocmask(SIG_BLOCK,&sss,NULL); |
|
/* for (i=0; i<1000; i++) { |
|
sleep(1); |
|
printf("Hello\n"); |
|
} |
|
exit(0); */ |
|
execl("/usr/X11R6/bin/xterm","/usr/X11R6/bin/xterm", |
|
"-e","/home/nobuki/kxx/ox","-ox","/home/nobuki/kxx/ox_asir",NULL); |
|
/* execl("/home/nobuki/kxx/ox","/home/nobuki/kxx/ox","-ox","/home/nobuki/kxx/ox_asir",NULL);*/ |
|
} |
|
|
|
char *toFullPath(char *s) { |
char *toFullPath(char *s) |
if (strlen(s) == 0) { |
{ |
return(s); |
extern int Debug_which; |
} |
char *path = "/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/openwin/bin:/usr/X/bin"; |
if (strchr(s,'/') != NULL) return(s); |
char *s2; |
else { |
if (strlen(s) == 0 || strchr(s, '/') != NULL) { |
s = which(s,getenv("PATH")); |
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; |
} |
} |
|
|
/*which("xterm", getenv("PATH"));*/ |
int main(int argc, char *argv[]) |
char *which(char *prog, char *path_env) |
|
{ |
{ |
char *tok; |
sigset_t sss; |
char *path; |
int i; |
char delim[] = ":"; |
char *oxname; |
char *e = alloca(strlen(path_env)+1); |
/* char *env[2]; |
strcpy(e, path_env); |
env[0] = NULL;*/ |
tok = strtok(e, delim); |
sigemptyset(&sss); |
while (tok != NULL) { |
sigaddset(&sss, SIGINT); |
char *path = malloc(strlen(tok)+strlen(prog)+2); |
sigprocmask(SIG_BLOCK, &sss, NULL); |
sprintf(path, "%s/%s", tok, prog); |
if (argc >= 2) { |
if (access(path, X_OK&R_OK) == 0) { |
oxname = toFullPath(argv[1]); |
return path; |
if (oxname == NULL) { |
|
oxname = "NULL"; |
|
} /* Why? */ |
|
execv(oxname, argv+1); |
|
|
|
fprintf(stderr, "\nError in oxlog: Failed to start the process.\n"); |
|
fprintf(stderr, "oxname=%s\n", oxname); |
|
for (i=0; i<argc; i++) { |
|
fprintf(stderr, "argv[%d]=%s ", i, argv[i]); |
|
} |
|
fprintf(stderr, "\n"); |
|
exit(20); |
|
}else { |
|
fprintf(stderr, "Error in oxlog: cannot handle argc=%d\n", argc); |
|
fprintf(stderr, "oxname=???\n"); |
|
for (i=0; i<argc; i++) { |
|
fprintf(stderr, "argv[%d]=%s ", i, argv[i]); |
|
} |
|
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); |
} |
} |
free(path); |
|
tok = strtok(NULL, delim); |
|
} |
|
return NULL; |
|
} |
} |
|
|