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

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

1.9     ! takayama    1: /*$OpenXM: OpenXM/src/kxx/oxlog.c,v 1.8 2000/06/19 07:48:01 ohara 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.8       ohara      25:
                     26: /*which("xterm", getenv("PATH"));*/
                     27: char *which(char *prog, char *path_env)
                     28: {
1.9     ! takayama   29:   extern int Debug_which ;
        !            30:   char *tok;
        !            31:   char *path;
        !            32:   char delim[] = ":";
        !            33:   char *e = alloca(strlen(path_env)+1);
        !            34:   strcpy(e, path_env);
        !            35:   tok = strtok(e, delim);
        !            36:   if (Debug_which) {
        !            37:     fprintf(stderr, "PATH=%s\n", path_env);
        !            38:   }
        !            39:   while (tok != NULL) {
        !            40:     char *path = malloc(strlen(tok)+strlen(prog)+2);
        !            41:     sprintf(path, "%s/%s", tok, prog);
        !            42:     if (access(path, X_OK&R_OK) == 0) {
        !            43:       if (Debug_which) {
        !            44:         fprintf(stderr, "Found: %s\n", path);
        !            45:       }
        !            46:       return path;
1.8       ohara      47:     }
1.9     ! takayama   48:     free(path);
        !            49:     tok = strtok(NULL, delim);
        !            50:   }
        !            51:   return NULL;
1.3       takayama   52: }
                     53:
1.8       ohara      54: char *toFullPath(char *s)
                     55: {
1.9     ! takayama   56:   extern int Debug_which;
        !            57:   char *path = "/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/openwin/bin:/usr/X/bin";
        !            58:   char *s2;
        !            59:   if (strlen(s) == 0 || strchr(s, '/') != NULL) {
        !            60:     return s;
        !            61:   }
        !            62:   s2 = which(s, getenv("PATH"));
        !            63:   if (s2 == NULL) {
        !            64:     if (Debug_which) {
        !            65:       fprintf(stderr, "Could not find arg[1] in your search path.\n");
        !            66:       fprintf(stderr, "You path is %s.\n", getenv("PATH"));
        !            67:       fprintf(stderr, "Trying to find in the path: %s\n", path);
1.8       ohara      68:     }
1.9     ! takayama   69:     s2 = which(s, path);
        !            70:     /* Why? */
        !            71:   }
        !            72:   return s2;
1.3       takayama   73: }
                     74:
1.8       ohara      75: int main(int argc, char *argv[])
1.3       takayama   76: {
1.9     ! takayama   77:   sigset_t sss;
        !            78:   int i;
        !            79:   char *oxname;
        !            80:   /* char *env[2];
        !            81:      env[0] = NULL;*/
        !            82:   sigemptyset(&sss);
        !            83:   sigaddset(&sss, SIGINT);
        !            84:   sigprocmask(SIG_BLOCK, &sss, NULL);
        !            85:   if (argc >= 2) {
        !            86:     oxname = toFullPath(argv[1]);
        !            87:     if (oxname == NULL) {
        !            88:       oxname = "NULL";
        !            89:     } /* Why? */
        !            90:     execv(oxname, argv+1);
1.8       ohara      91:
1.9     ! takayama   92:     fprintf(stderr, "\nError in oxlog: Failed to start the process.\n");
        !            93:     fprintf(stderr, "oxname=%s\n", oxname);
        !            94:     for (i=0; i<argc; i++) {
        !            95:       fprintf(stderr, "argv[%d]=%s ", i, argv[i]);
        !            96:     }
        !            97:     fprintf(stderr, "\n");
        !            98:     exit(20);
        !            99:   }else {
        !           100:     fprintf(stderr, "Error in oxlog: cannot handle argc=%d\n", argc);
        !           101:     fprintf(stderr, "oxname=???\n");
        !           102:     for (i=0; i<argc; i++) {
        !           103:       fprintf(stderr, "argv[%d]=%s ", i, argv[i]);
1.3       takayama  104:     }
1.9     ! takayama  105:     fprintf(stderr, "\n");
        !           106:     fprintf(stderr, "Usage example 1: oxlog /usr/X11R6/bin/xterm -icon -e /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir\n");
        !           107:     fprintf(stderr, "      example 2: oxlog /home/nobuki/kxx/ox -ox /home/nobuki/kxx/ox_asir >& /dev/null\n");
        !           108:     exit(10);
        !           109:   }
1.1       maekawa   110: }

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