version 1.8, 2003/12/05 07:05:24 |
version 1.17, 2020/10/06 11:33:47 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/shell.c,v 1.7 2003/12/04 06:29:21 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/shell.c,v 1.16 2013/09/20 06:02:19 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
|
#include <string.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <fcntl.h> |
#include <fcntl.h> |
Line 63 void KoxShellHelp(char *key,FILE *fp) { |
|
Line 64 void KoxShellHelp(char *key,FILE *fp) { |
|
for (i=0; strcmp(keys[i],"@@@@gatekeeper") != 0; i++) { |
for (i=0; strcmp(keys[i],"@@@@gatekeeper") != 0; i++) { |
fprintf(fp,"%s\n",keys[i]); |
fprintf(fp,"%s\n",keys[i]); |
KoxShellHelp(keys[i],fp); |
KoxShellHelp(keys[i],fp); |
fprintf(fp,"\n",keys[i]); |
fprintf(fp,"%s\n",keys[i]); |
} |
} |
return; |
return; |
} |
} |
Line 83 void KoxShellHelp(char *key,FILE *fp) { |
|
Line 84 void KoxShellHelp(char *key,FILE *fp) { |
|
s[1] = "cmdname arg1 arg2 ... "; |
s[1] = "cmdname arg1 arg2 ... "; |
s[2] = "Example 1: /afo (Hello! ) def [(cat) (stringIn://afo)] oxshell"; |
s[2] = "Example 1: /afo (Hello! ) def [(cat) (stringIn://afo)] oxshell"; |
s[3] = "Example 2: [(polymake) (stringInOut://afo.poly) (FACETS)] oxshell"; |
s[3] = "Example 2: [(polymake) (stringInOut://afo.poly) (FACETS)] oxshell"; |
s[4] = NULL; |
s[4] = "A temporary file afo.poly* with the contents of the variable afo.poly is generated under $TMP and \"polymake $TMP FACETS\" will be executed. cf. kan96xx/trans/doPolymake.sm1, Doc/oxshell.oxw, Doc/changelog-ja.tex"; |
|
s[5] = "Example 3: [(ls) (-l) (>) (stringOut://ff)] oxshell"; |
|
s[6] = NULL; |
}else if (strcmp(key,"redirect")==0) { |
}else if (strcmp(key,"redirect")==0) { |
s[0] = "The following redirect operators are implemented."; |
s[0] = "The following redirect operators are implemented."; |
s[1] = "< > 2>"; |
s[1] = "< > 2>"; |
Line 96 void KoxShellHelp(char *key,FILE *fp) { |
|
Line 99 void KoxShellHelp(char *key,FILE *fp) { |
|
}else if (strcmp(key,"keep_tmp_files")==0) { |
}else if (strcmp(key,"keep_tmp_files")==0) { |
s[0] = "keep_tmp_files value"; |
s[0] = "keep_tmp_files value"; |
s[1] = "If value is zero, then temporary files are removed after execution."; |
s[1] = "If value is zero, then temporary files are removed after execution."; |
s[2] = NULL; |
s[2] = "Example 1: [(keep_tmp_files) (1)] oxshell ; temporary files will be kept in /tmp or $TMP or ..."; |
|
s[3] = NULL; |
}else{ |
}else{ |
} |
} |
i = 0; |
i = 0; |
Line 108 void KoxShellHelp(char *key,FILE *fp) { |
|
Line 112 void KoxShellHelp(char *key,FILE *fp) { |
|
|
|
static struct object KoxShell_test1(struct object ob) { |
static struct object KoxShell_test1(struct object ob) { |
/* A simple shell. It does not implement a parser. */ |
/* A simple shell. It does not implement a parser. */ |
struct object rob; |
struct object rob = OINIT; |
char *cmd; |
char *cmd; |
char *arg1,*arg2; |
char *arg1,*arg2; |
int i,n; |
int i,n; |
Line 125 static struct object KoxShell_test1(struct object ob) |
|
Line 129 static struct object KoxShell_test1(struct object ob) |
|
rob = testmain(ob); |
rob = testmain(ob); |
}else if (strcmp(cmd,"which")==0) { |
}else if (strcmp(cmd,"which")==0) { |
if (n == 2) { |
if (n == 2) { |
|
pathFinderErrorVerbose(0); |
rob = KoxWhich(getoa(ob,1),KpoInteger(0)); |
rob = KoxWhich(getoa(ob,1),KpoInteger(0)); |
|
pathFinderErrorVerbose(-1); |
}else if (n==3) { |
}else if (n==3) { |
|
pathFinderErrorVerbose(0); |
rob = KoxWhich(getoa(ob,1),getoa(ob,2)); |
rob = KoxWhich(getoa(ob,1),getoa(ob,2)); |
|
pathFinderErrorVerbose(-1); |
}else{ |
}else{ |
errorKan1("%s\n","shell: << which command-name >> or << which command-name path >>"); |
errorKan1("%s\n","shell: << which command-name >> or << which command-name path >>"); |
} |
} |
Line 155 static struct object KoxShell_test1(struct object ob) |
|
Line 163 static struct object KoxShell_test1(struct object ob) |
|
|
|
/* Functions for ox_shell */ |
/* Functions for ox_shell */ |
struct object KoxWhich(struct object cmdo,struct object patho) { |
struct object KoxWhich(struct object cmdo,struct object patho) { |
struct object rob; |
struct object rob = OINIT; |
char *sss; |
char *sss; |
rob = NullObject; |
rob = NullObject; |
if (cmdo.tag != Sdollar) errorKan1("%s\n","KoxWhich(str-obj,str-obj)"); |
if (cmdo.tag != Sdollar) errorKan1("%s\n","KoxWhich(str-obj,str-obj)"); |
Line 173 struct object KoxWhich(struct object cmdo,struct objec |
|
Line 181 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 int 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 = OINIT; |
int i,n; |
int i,n; |
char *envp; |
char *envp; |
char *new; |
char *new; |
Line 197 static struct object oxsSetenv(struct object ob) { |
|
Line 227 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 348 char *oxsURIgetFileName(char *s) { |
|
Line 379 char *oxsURIgetFileName(char *s) { |
|
|
|
|
|
static struct object testmain(struct object ob) { |
static struct object testmain(struct object ob) { |
struct object rob; |
struct object rob = OINIT; |
char *s; |
char *s; |
struct object ot; |
struct object ot = OINIT; |
char **av; |
char **av; |
int i; |
int i; |
rob = NullObject; |
rob = NullObject; |
Line 379 char *oxsVarToFile(char *v,char *ext,char *command,int |
|
Line 410 char *oxsVarToFile(char *v,char *ext,char *command,int |
|
FILE *fp; |
FILE *fp; |
int n,i,prevc,c; |
int n,i,prevc,c; |
char *prog; |
char *prog; |
struct object vv; |
struct object vv = OINIT; |
|
|
/*bug; winname must be automatically set by looking at command. |
/*bug; winname must be automatically set by looking at command. |
If command is win32-native-application, then winname=1; else winname=0. |
If command is win32-native-application, then winname=1; else winname=0. |
Line 420 int oxsFileToVar(char *v,char *fname) { |
|
Line 451 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 455 static char **oxsBuildArgv(struct object ob) { |
|
Line 492 static char **oxsBuildArgv(struct object ob) { |
|
char *ext, *v; |
char *ext, *v; |
int usetmp=1; |
int usetmp=1; |
int win=0; |
int win=0; |
struct object ocmd; |
struct object ocmd = OINIT; |
|
|
/* bug: win variable must be properly set on windows native. */ |
/* bug: win variable must be properly set on windows native. */ |
|
|
Line 533 static struct object oxsExecuteBlocked(struct object o |
|
Line 570 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 545 static struct object oxsExecuteBlocked(struct object o |
|
Line 583 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 560 static struct object oxsExecuteBlocked(struct object o |
|
Line 601 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)); |
} |
} |