Annotation of OpenXM/src/kxx/oxlog.c, Revision 1.4
1.4 ! ohara 1: /*$OpenXM: OpenXM/src/kxx/oxlog.c,v 1.3 1999/12/15 11:31:57 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.3 takayama 24: char *toFullPath(char *s);
25: char *which(char *s,char *env);
1.1 maekawa 26: main(int argc, char *argv[]) {
27: sigset_t sss;
28: int i;
1.3 takayama 29: char *oxname;
1.1 maekawa 30: /* char *env[2];
31: env[0] = NULL;*/
32: sigemptyset(&sss);
33: sigaddset(&sss,SIGINT);
34: sigprocmask(SIG_BLOCK,&sss,NULL);
1.3 takayama 35: if (argc > 1) {
36: oxname = argv[1];
37: oxname = toFullPath(oxname);
38: }
1.1 maekawa 39: if (argc == 4) {
1.3 takayama 40: execl(oxname,oxname,argv[2],argv[3],NULL);
1.1 maekawa 41: }else if (argc == 5) {
1.3 takayama 42: execl(oxname,oxname,argv[2],argv[3],argv[4],NULL);
1.1 maekawa 43: }else if (argc == 6) {
1.3 takayama 44: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],NULL);
1.1 maekawa 45: }else if (argc == 7) {
1.3 takayama 46: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],NULL);
1.1 maekawa 47: }else if (argc == 8) {
1.3 takayama 48: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 49: argv[7],NULL);
50: }else if (argc == 9) {
1.3 takayama 51: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 52: argv[7],argv[8],NULL);
53: }else if (argc == 10) {
1.3 takayama 54: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.1 maekawa 55: argv[7],argv[8],argv[9],NULL);
56: }else if (argc == 11) {
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],argv[9],argv[10],NULL);
59: }else if (argc == 12) {
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],argv[10],argv[11],NULL);
62: }else if (argc == 13) {
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],argv[11], argv[12],NULL);
65: }else if (argc == 14) {
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], argv[12],argv[13],NULL);
68: }else if (argc == 15) {
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],argv[13],argv[14],NULL);
1.2 takayama 71: }else if (argc == 16) {
1.3 takayama 72: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.2 takayama 73: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],argv[15],NULL);
74: }else if (argc == 17) {
1.3 takayama 75: execl(oxname,oxname,argv[2],argv[3],argv[4],argv[5],argv[6],
1.2 takayama 76: argv[7],argv[8],argv[9],argv[10],argv[11], argv[12],argv[13],argv[14],argv[15],argv[16],NULL);
1.1 maekawa 77: }else {
78: fprintf(stderr,"Error in oxlog: cannot handle argc=%d\n",argc);
1.3 takayama 79: fprintf(stderr,"oxname=%s\n",oxname);
1.1 maekawa 80: for (i=0; i<argc; i++) {
81: fprintf(stderr,"argv[%d]=%s ",i,argv[i]);
82: }
83: fprintf(stderr,"\n");
84: fprintf(stderr,"Usage example 1: oxlog /usr/X11R6/bin/xterm -icon -e /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir\n");
85: fprintf(stderr," example 2: oxlog /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir >& /dev/null\n");
86: exit(10);
87: }
88: fprintf(stderr,"\nError in oxlog: Failed to start the process.\n");
1.3 takayama 89: fprintf(stderr,"oxname=%s\n",oxname);
1.1 maekawa 90: for (i=0; i<argc; i++) {
91: fprintf(stderr,"argv[%d]=%s ",i,argv[i]);
92: }
93: fprintf(stderr,"\n");
94: exit(20);
95: }
96: mainold1() {
97: sigset_t sss;
98: int i;
99: /* char *env[2];
100: env[0] = NULL;*/
101: sigemptyset(&sss);
102: sigaddset(&sss,SIGINT);
103: sigprocmask(SIG_BLOCK,&sss,NULL);
104: /* for (i=0; i<1000; i++) {
105: sleep(1);
106: printf("Hello\n");
107: }
108: exit(0); */
109: execl("/usr/X11R6/bin/xterm","/usr/X11R6/bin/xterm",
110: "-e","/home/nobuki/kxx/ox","-ox","/home/nobuki/kxx/ox_asir",NULL);
111: /* execl("/home/nobuki/kxx/ox","/home/nobuki/kxx/ox","-ox","/home/nobuki/kxx/ox_asir",NULL);*/
1.3 takayama 112: }
113:
114: char *toFullPath(char *s) {
115: if (strlen(s) == 0) {
116: return(s);
117: }
118: if (strchr(s,'/') != NULL) return(s);
119: else {
120: s = which(s,getenv("PATH"));
121: }
122: }
123:
124: /*which("xterm", getenv("PATH"));*/
125: char *which(char *prog, char *path_env)
126: {
127: char *tok;
128: char *path;
129: char delim[] = ":";
130: char *e = alloca(strlen(path_env)+1);
131: strcpy(e, path_env);
132: tok = strtok(e, delim);
133: while (tok != NULL) {
134: char *path = malloc(strlen(tok)+strlen(prog)+2);
135: sprintf(path, "%s/%s", tok, prog);
1.4 ! ohara 136: if (access(path, X_OK&R_OK) == 0) {
1.3 takayama 137: return path;
138: }
139: free(path);
140: tok = strtok(NULL, delim);
141: }
142: return NULL;
1.1 maekawa 143: }
144:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>