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

Diff for /OpenXM/src/kxx/oxlog.c between version 1.8 and 1.9

version 1.8, 2000/06/19 07:48:01 version 1.9, 2001/05/06 07:53:00
Line 1 
Line 1 
 /*$OpenXM: OpenXM/src/kxx/oxlog.c, v 1.7 2000/02/09 12:24:52 takayama Exp $*/  /*$OpenXM: OpenXM/src/kxx/oxlog.c,v 1.8 2000/06/19 07:48:01 ohara Exp $*/
 #include <stdio.h>  #include <stdio.h>
 #include <signal.h>  #include <signal.h>
 #include <string.h>  #include <string.h>
Line 26  static int Debug_which = 1;
Line 26  static int Debug_which = 1;
 /*which("xterm", getenv("PATH"));*/  /*which("xterm", getenv("PATH"));*/
 char *which(char *prog, char *path_env)  char *which(char *prog, char *path_env)
 {  {
     extern int Debug_which ;    extern int Debug_which ;
     char *tok;    char *tok;
     char *path;    char *path;
     char delim[] = ":";    char delim[] = ":";
     char *e = alloca(strlen(path_env)+1);    char *e = alloca(strlen(path_env)+1);
     strcpy(e, path_env);    strcpy(e, path_env);
     tok = strtok(e, delim);    tok = strtok(e, delim);
     if (Debug_which) {    if (Debug_which) {
         fprintf(stderr, "PATH=%s\n", path_env);      fprintf(stderr, "PATH=%s\n", path_env);
     }
     while (tok != NULL) {
       char *path = malloc(strlen(tok)+strlen(prog)+2);
       sprintf(path, "%s/%s", tok, prog);
       if (access(path, X_OK&R_OK) == 0) {
         if (Debug_which) {
           fprintf(stderr, "Found: %s\n", path);
         }
         return path;
     }      }
     while (tok != NULL) {      free(path);
         char *path = malloc(strlen(tok)+strlen(prog)+2);      tok = strtok(NULL, delim);
         sprintf(path, "%s/%s", tok, prog);    }
         if (access(path, X_OK&R_OK) == 0) {    return NULL;
             if (Debug_which) {  
                 fprintf(stderr, "Found: %s\n", path);  
             }  
             return path;  
         }  
         free(path);  
         tok = strtok(NULL, delim);  
     }  
     return NULL;  
 }  }
   
 char *toFullPath(char *s)  char *toFullPath(char *s)
 {  {
     extern int Debug_which;    extern int Debug_which;
     char *path = "/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/openwin/bin:/usr/X/bin";    char *path = "/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/openwin/bin:/usr/X/bin";
     char *s2;    char *s2;
     if (strlen(s) == 0 || strchr(s, '/') != NULL) {    if (strlen(s) == 0 || strchr(s, '/') != NULL) {
         return s;      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, getenv("PATH"));      s2 = which(s, path);
     if (s2 == NULL) {      /* Why? */
         if (Debug_which) {    }
             fprintf(stderr, "Could not find arg[1] in your search path.\n");    return s2;
             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;  
 }  }
   
 int main(int argc, char *argv[])  int main(int argc, char *argv[])
 {  {
     sigset_t sss;    sigset_t sss;
     int i;    int i;
     char *oxname;    char *oxname;
     /* char *env[2];    /* char *env[2];
        env[0] = NULL;*/       env[0] = NULL;*/
     sigemptyset(&sss);    sigemptyset(&sss);
     sigaddset(&sss, SIGINT);    sigaddset(&sss, SIGINT);
     sigprocmask(SIG_BLOCK, &sss, NULL);    sigprocmask(SIG_BLOCK, &sss, NULL);
     if (argc >= 2) {    if (argc >= 2) {
         oxname = toFullPath(argv[1]);      oxname = toFullPath(argv[1]);
         if (oxname == NULL) {      if (oxname == NULL) {
             oxname = "NULL";        oxname = "NULL";
         } /* Why? */      } /* Why? */
         execv(oxname, argv+1);      execv(oxname, argv+1);
   
         fprintf(stderr, "\nError in oxlog: Failed to start the process.\n");      fprintf(stderr, "\nError in oxlog: Failed to start the process.\n");
         fprintf(stderr, "oxname=%s\n", oxname);      fprintf(stderr, "oxname=%s\n", oxname);
         for (i=0; i<argc; i++) {      for (i=0; i<argc; i++) {
             fprintf(stderr, "argv[%d]=%s ", i, argv[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);  
     }      }
       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);
     }
 }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

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