Annotation of OpenXM/src/kxx/oxlog.c, Revision 1.7
1.7 ! takayama 1: /*$OpenXM: OpenXM/src/kxx/oxlog.c,v 1.6 2000/02/09 12:02:56 takayama Exp $*/
1.1 maekawa 2: #include <stdio.h>
3: #include <signal.h>
1.3 takayama 4: #include <string.h>
5: #include <stdlib.h>
1.1 maekawa 6: #include <sys/types.h>
7: #include <sys/stat.h>
8: #include <fcntl.h>
9: /* In some distributions of linux you need to include the following file
10: #include <linux/sched.h>
11: */
12: #include <unistd.h>
13:
14: /* oxlog /usr/X11R6/bin/xterm -icon -e /home/nobuki/kxx/ox
15: 0 1 2 3 4
16: -ox /home/nobuki/kxx/ox_asir
17: 5 6
18: */
19: /* oxlog /home/nobuki/kxx/ox
20: 0 1
21: -ox /home/nobuki/kxx/ox_asir >& /dev/null
22: 2 3
23: */
1.6 takayama 24: static int Debug_which = 1;
1.3 takayama 25: char *toFullPath(char *s);
26: char *which(char *s,char *env);
1.1 maekawa 27: main(int argc, char *argv[]) {
28: sigset_t sss;
29: int i;
1.5 takayama 30: char *oxname ="???";
1.1 maekawa 31: /* char *env[2];
32: env[0] = NULL;*/
33: sigemptyset(&sss);
34: sigaddset(&sss,SIGINT);
35: sigprocmask(SIG_BLOCK,&sss,NULL);
1.6 takayama 36: if (argc >= 2) {
1.3 takayama 37: oxname = argv[1];
38: oxname = toFullPath(oxname);
1.7 ! takayama 39: if (oxname == NULL) oxname="NULL";
1.3 takayama 40: }
1.6 takayama 41: if (argc == 2) {
42: execl(oxname,oxname,NULL);
43: }else if (argc == 3) {
44: execl(oxname,oxname,argv[2],NULL);
45: }else if (argc == 4) {
1.3 takayama 46: execl(oxname,oxname,argv[2],argv[3],NULL);
1.1 maekawa 47: }else if (argc == 5) {
1.3 takayama 48: execl(oxname,oxname,argv[2],argv[3],argv[4],NULL);
1.1 maekawa 49: }else if (argc == 6) {
1.3 takayama 50: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],NULL);
1.1 maekawa 51: }else if (argc == 7) {
1.3 takayama 52: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],NULL);
1.1 maekawa 53: }else if (argc == 8) {
1.3 takayama 54: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 55: argv[7],NULL);
56: }else if (argc == 9) {
1.3 takayama 57: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 58: argv[7],argv[8],NULL);
59: }else if (argc == 10) {
1.3 takayama 60: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 61: argv[7],argv[8],argv[9],NULL);
62: }else if (argc == 11) {
1.3 takayama 63: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 64: argv[7],argv[8],argv[9],argv[10],NULL);
65: }else if (argc == 12) {
1.3 takayama 66: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 67: argv[7],argv[8],argv[9],argv[10],argv[11],NULL);
68: }else if (argc == 13) {
1.3 takayama 69: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 70: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],NULL);
71: }else if (argc == 14) {
1.3 takayama 72: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 73: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],NULL);
74: }else if (argc == 15) {
1.3 takayama 75: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 76: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],NULL);
1.2 takayama 77: }else if (argc == 16) {
1.3 takayama 78: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.2 takayama 79: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],argv[15],NULL);
80: }else if (argc == 17) {
1.3 takayama 81: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.2 takayama 82: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],argv[15],argv[16],NULL);
1.6 takayama 83: }else if (argc == 18) {
84: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
85: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],NULL);
86: }else if (argc == 19) {
87: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
88: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],NULL);
89: }else if (argc == 20) {
90: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
91: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],argv[19],NULL);
92: }else if (argc == 21) {
93: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
94: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],argv[19],argv[20],NULL);
1.1 maekawa 95: }else {
96: fprintf(stderr,"Error in oxlog: cannot handle argc=%d\n",argc);
1.7 ! takayama 97: fprintf(stderr,"oxname=%s\n",oxname);
1.1 maekawa 98: for (i=0; i<argc; i++) {
99: fprintf(stderr,"argv[%d]=%s ",i,argv[i]);
100: }
101: fprintf(stderr,"\n");
102: fprintf(stderr,"Usage example 1: oxlog /usr/X11R6/bin/xterm -icon -e /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir\n");
103: fprintf(stderr," example 2: oxlog /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir >& /dev/null\n");
104: exit(10);
105: }
106: fprintf(stderr,"\nError in oxlog: Failed to start the process.\n");
1.3 takayama 107: fprintf(stderr,"oxname=%s\n",oxname);
1.1 maekawa 108: for (i=0; i<argc; i++) {
109: fprintf(stderr,"argv[%d]=%s ",i,argv[i]);
110: }
111: fprintf(stderr,"\n");
112: exit(20);
113: }
114: mainold1() {
115: sigset_t sss;
116: int i;
117: /* char *env[2];
118: env[0] = NULL;*/
119: sigemptyset(&sss);
120: sigaddset(&sss,SIGINT);
121: sigprocmask(SIG_BLOCK,&sss,NULL);
122: /* for (i=0; i<1000; i++) {
123: sleep(1);
124: printf("Hello\n");
125: }
126: exit(0); */
127: execl("/usr/X11R6/bin/xterm","/usr/X11R6/bin/xterm",
128: "-e","/home/nobuki/kxx/ox","-ox","/home/nobuki/kxx/ox_asir",NULL);
129: /* execl("/home/nobuki/kxx/ox","/home/nobuki/kxx/ox","-ox","/home/nobuki/kxx/ox_asir",NULL);*/
1.3 takayama 130: }
131:
132: char *toFullPath(char *s) {
1.6 takayama 133: extern int Debug_which;
134: char *path ="/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/openwin/bin:/usr/X/bin";
1.7 ! takayama 135: char *s2;
1.3 takayama 136: if (strlen(s) == 0) {
137: return(s);
138: }
139: if (strchr(s,'/') != NULL) return(s);
140: else {
1.7 ! takayama 141: s2 = which(s,getenv("PATH"));
1.3 takayama 142: }
1.7 ! takayama 143: if (s2 == NULL) {
! 144: if (Debug_which) fprintf(stderr,"Could not find arg[1] in your search path.\n");
1.6 takayama 145: if (Debug_which) fprintf(stderr,"You path is %s.\n",getenv("PATH"));
146: if (Debug_which) fprintf(stderr,"Trying to find in the path: %s\n",path);
1.7 ! takayama 147: s2 = which(s,path);
1.6 takayama 148: }
1.7 ! takayama 149: return(s2);
1.3 takayama 150: }
151:
152: /*which("xterm", getenv("PATH"));*/
153: char *which(char *prog, char *path_env)
154: {
1.6 takayama 155: extern int Debug_which ;
1.3 takayama 156: char *tok;
157: char *path;
158: char delim[] = ":";
159: char *e = alloca(strlen(path_env)+1);
160: strcpy(e, path_env);
161: tok = strtok(e, delim);
1.6 takayama 162: if (Debug_which) fprintf(stderr,"PATH=%s\n",path_env);
1.3 takayama 163: while (tok != NULL) {
164: char *path = malloc(strlen(tok)+strlen(prog)+2);
165: sprintf(path, "%s/%s", tok, prog);
1.4 ohara 166: if (access(path, X_OK&R_OK) == 0) {
1.6 takayama 167: if (Debug_which) fprintf(stderr,"Found: %s\n",path);
1.3 takayama 168: return path;
169: }
170: free(path);
171: tok = strtok(NULL, delim);
172: }
173: return NULL;
1.1 maekawa 174: }
175:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>