[BACK]Return to oxlog.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kxx

Annotation of OpenXM/src/kxx/oxlog.c, Revision 1.6

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>