[BACK]Return to shell.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Kan

Diff for /OpenXM/src/kan96xx/Kan/shell.c between version 1.6 and 1.11

version 1.6, 2003/12/04 05:29:12 version 1.11, 2004/02/23 09:03:42
Line 1 
Line 1 
 /* $OpenXM: OpenXM/src/kan96xx/Kan/shell.c,v 1.5 2003/12/04 05:27:19 takayama Exp $ */  /* $OpenXM: OpenXM/src/kan96xx/Kan/shell.c,v 1.10 2004/02/05 10:35:04 takayama Exp $ */
 #include <stdio.h>  #include <stdio.h>
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/stat.h>  #include <sys/stat.h>
Line 41  static int AfterPt=0;
Line 41  static int AfterPt=0;
 static char *AfterDeleteFile[MAXFILES];  static char *AfterDeleteFile[MAXFILES];
 static int AfterD=0;  static int AfterD=0;
   
 static int KeepTmpFiles = 1;  static int KeepTmpFiles = 0;
   
 extern int OX_P_stdin;  extern int OX_P_stdin;
 extern int OX_P_stdout;  extern int OX_P_stdout;
Line 53  struct object KoxShell(struct object ob) {
Line 53  struct object KoxShell(struct object ob) {
   
 /* A temporary help system */  /* A temporary help system */
 void KoxShellHelp(char *key,FILE *fp) {  void KoxShellHelp(char *key,FILE *fp) {
   char *keys[]={"command","export","which","redirect","@@@@gatekeeper"};    char *keys[]={"command","export","keep_tmp_files",
                   "killall","redirect","which","@@@@gatekeeper"};
   int i;    int i;
 #define HSIZE 20  #define HSIZE 20
   char *s[HSIZE];    char *s[HSIZE];
Line 89  void KoxShellHelp(char *key,FILE *fp) {
Line 90  void KoxShellHelp(char *key,FILE *fp) {
     s[2] = "Example 1: [(ls) (hoge) (2>) (stringOut://afo)] oxshell\n    afo ::";      s[2] = "Example 1: [(ls) (hoge) (2>) (stringOut://afo)] oxshell\n    afo ::";
     s[3] = "Example 2: [(cp) ] addStdoutStderr oxshell\n      [@@@stdout @@@stderr] ::";      s[3] = "Example 2: [(cp) ] addStdoutStderr oxshell\n      [@@@stdout @@@stderr] ::";
     s[4] = NULL;      s[4] = NULL;
     }else if (strcmp(key,"killall")==0) {
       s[0] = "Kill all the processes envoked by oxshell";
       s[1] = NULL;
     }else if (strcmp(key,"keep_tmp_files")==0) {
       s[0] = "keep_tmp_files value";
       s[1] = "If value is zero, then temporary files are removed after execution.";
       s[2] = NULL;
   }else{    }else{
   }    }
   i = 0;    i = 0;
Line 126  static struct object KoxShell_test1(struct object ob) 
Line 134  static struct object KoxShell_test1(struct object ob) 
     return(rob);      return(rob);
   }else if (strcmp(cmd,"export")==0) {    }else if (strcmp(cmd,"export")==0) {
     rob=oxsSetenv(ob);      rob=oxsSetenv(ob);
     }else if (strcmp(cmd,"keep_tmp_files")==0) {
       if (n != 2) errorKan1("%s\n","shell: << keep_tmp_files value >>");
       if (strcmp("0",KopString(getoa(ob,1))) == 0) {
         KeepTmpFiles = 0;
       }else{
         KeepTmpFiles = 1;
       }
       rob = KpoInteger(KeepTmpFiles);
     }else if (strcmp(cmd,"killall")==0) {
           /* It is called from ctrl-C hook of oxrfc103.sm1 */
           fprintf(stderr,"Killing all child processes (oxshell) ...");
       rob = KpoInteger(oxKillAll());
           fprintf(stderr,"\nDone.\n");
   }else{    }else{
     rob = oxsExecuteBlocked(ob);      rob = oxsExecuteBlocked(ob);
   }    }
Line 152  struct object KoxWhich(struct object cmdo,struct objec
Line 173  struct object KoxWhich(struct object cmdo,struct objec
   return(rob);    return(rob);
 }  }
   
   static int mysetenv(char *name, char *value, int overwrite);
   static int myunsetenv(char *name);
   static int mysetenv(char *name, char *value, int overwrite) {
     char *s;
     char *orig;
     s = (char *)getenv(name);
     if ((s == NULL) || overwrite) {
           s = (char *) mymalloc(strlen(name)+strlen(value)+5);
           if (s == 0) { fprintf(stderr,"No more memory.\n"); exit(10); }
       strcpy(s,name);
           strcat(s,"="); strcat(s,value);
           return(putenv(s));
     }
     return (0);
   }
   
   /* bug on Solaris. It does not unsetenv.
      libc4, libc5, glibc. It does unsetenv. */
   static myunsetenv(char *name) {
     return(putenv(name));
   }
   
 /* Example. [(export)  (PATH)  (=)  (/usr/new/bin:$PATH)] */  /* Example. [(export)  (PATH)  (=)  (/usr/new/bin:$PATH)] */
 static struct object oxsSetenv(struct object ob) {  static struct object oxsSetenv(struct object ob) {
   struct object rob;    struct object rob;
Line 176  static struct object oxsSetenv(struct object ob) {
Line 219  static struct object oxsSetenv(struct object ob) {
     /* printf("%s\n",new); */      /* printf("%s\n",new); */
     new = oxEvalEnvVar(new);      new = oxEvalEnvVar(new);
     /* printf("%s\n",new); */      /* printf("%s\n",new); */
     r = setenv(envp,new,1);      r = mysetenv(envp,new,1);
   }else{    }else{
     unsetenv(envp); r = 0;      myunsetenv(envp); r = 0;
       /* bug: On Solaris, unsetenv will not work. */
   }    }
   if (r != 0) errorKan1("%s\n","setenv failed.");    if (r != 0) errorKan1("%s\n","setenv failed.");
   new = (char *) getenv(envp);    new = (char *) getenv(envp);
Line 399  int oxsFileToVar(char *v,char *fname) {
Line 443  int oxsFileToVar(char *v,char *fname) {
   int limit;    int limit;
   int c,i;    int c,i;
   
   if (v == NULL) errorKan1("%s\n","oxsFileToVar(), v is NULL.");    if (v == NULL) {
           /* errorKan1("%s\n","oxsFileToVar(), v is NULL."); */
           fprintf(stderr,"oxsFileToVar(), v is NULL.");
           return(-1);
     }
   limit = 1024;    limit = 1024;
   fp = fopen(fname,"r");    fp = fopen(fname,"r");
   if (fp == NULL) {    if (fp == NULL) {
     fprintf(stderr,"Filename=%s\n",fname);      fprintf(stderr,"Filename=%s\n",fname);
     errorKan1("%s\n","oxsFileToVar(), the file cannot be opened.");      /* errorKan1("%s\n","oxsFileToVar(), the file cannot be opened."); */
           fprintf(stderr,"oxsFileToVar(), the file cannot be opened.");
           return(-1);
   }    }
   s = (char *)mymalloc(limit);    s = (char *)mymalloc(limit);
   if (s == NULL) errorKan1("%s\n","No more memory in oxsFileToVar().");    if (s == NULL) errorKan1("%s\n","No more memory in oxsFileToVar().");
Line 512  static struct object oxsExecuteBlocked(struct object o
Line 562  static struct object oxsExecuteBlocked(struct object o
 {  {
   int r,i,n;    int r,i,n;
   char **argv;    char **argv;
     int errorf;
   
   argv = oxsBuildArgv(ob);    argv = oxsBuildArgv(ob);
   argv = oxsBuildArgvRedirect(argv);    argv = oxsBuildArgvRedirect(argv);
Line 524  static struct object oxsExecuteBlocked(struct object o
Line 575  static struct object oxsExecuteBlocked(struct object o
     errorKan1("%s\n","ForkExecBlocked failed.");      errorKan1("%s\n","ForkExecBlocked failed.");
   }    }
   */    */
     errorf=0;
   if (AfterPt > 0) {    if (AfterPt > 0) {
     for (i=0; i< AfterPt; i++) {      for (i=0; i< AfterPt; i++) {
       oxsFileToVar(AfterSetVar[i],AfterReadFile[i]);        if (oxsFileToVar(AfterSetVar[i],AfterReadFile[i]) != 0) {
           errorf=1;
         }
     }      }
   }    }
   AfterPt = 0;    AfterPt = 0;
Line 539  static struct object oxsExecuteBlocked(struct object o
Line 593  static struct object oxsExecuteBlocked(struct object o
     }      }
   }    }
   AfterD = 0;    AfterD = 0;
     if (errorf) errorKan1("%s\n","Some errors in oxsFileToVar().");
   
   return(KpoInteger(r));    return(KpoInteger(r));
 }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.11

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