| top | | | ^ | | | | | | section top | |
static int oargc; static char **oargv;
| ^ | | | | | | section top | |
#define streq(x,y) (strcmp(x,y)==0)
int nargc = 1; char **nargv = (char**)Tcl_Alloc((argc+2)*sizeof(char*));
int keepstdin = 0;
int batch = 0;
int command = 0;
int alternateinput = 0;
oargc = argc-1; oargv = argv+1;
argc--;
nargv[0] = *argv++;
while (argc>0) {
if (streq(*argv,"-i")) {
argc -= 1; argv += 1;
keepstdin = 1;
}else if (streq(*argv,"-n")) {
argc -= 1; argv += 1;
batch = 1;
}else if (argc>1 && streq(*argv,"-s")) {
argc -= 2; argv += 2;
}else if (argc>1 && streq(*argv,"-c")) {
argc -= 2; argv += 2;
command = 1;
}else if (argc>1 && streq(*argv,"-p")) {
argc -= 2; argv += 2;
}else if (streq(*argv,"--")) {
argc -= 1; argv += 1;
while (argc>0) {
if (nargc==1) alternateinput = !streq(*argv,"-");
nargv[nargc++] = *argv++; argc--;
}
}else {
if (nargc==1) alternateinput = !streq(*argv,"-");
nargv[nargc++] = *argv++; argc--;
}
}
<stdin>
nargv[nargc] = 0;
| ^ | | | | | | section top | | 7. stdin ::
Without any wysh parameters, wysh reads commands from the standard
input (stdin) or from the specified input file until it reaches an end of
file. If a -c command
is specified, stdin is not read
unless the -i parameter is also specified.
(If an alternate input file was specified as the first argv parameter,
that is still read in any case.)
- wysh -c command [ -n ]
evaluates the command, print the result, and exit the wysh shell.
- wysh [ -i ]
accepts commands from stdin (with prompts if from the terminal) until the end of file
(unless an alternate input file was specified).
- wysh -c command -i
evaluates the command, print the result, and
then accept commands from stdin until the end of file.
It is assumed that in general commands will be enterred on the command line
or from the input device (such as the terminal), exclusively. Specifying
-c and -i allows both.
- wysh -n
runs the shell as with no commands read from stdin. Commands must
be given with -c, -s, read from ~/.tclshrc
or an alternate input file specified.
-s source files have no effect on whether stdin is read or not.
if (batch) keepstdin = 0;
if (!command && !batch) keepstdin = 1;
if (!keepstdin && !alternateinput) {
if (nargc==1) nargc = 2;
nargv[1] = "/dev/null";
}
| ^ | | | | | | section top | |
int p;
if (Tcl_VarEval(interp,"package require wyrmwif",0)!=TCL_OK) {
static char msg[] = "require wyrmwif: ";
char *result = Tcl_GetStringResult(interp);
write(2,msg,sizeof(msg)-1);
write(2,result,strlen(result));
write(2,"\n",1);
return TCL_ERROR;
}
for (p=0; p<oargc; p++) {
if (p+1<oargc && streq(oargv[p],"-s")) {
p++;
}else if (p+1<oargc && streq(oargv[p],"-c")) {
p++;
}else if (p+1<oargc && streq(oargv[p],"-p")) {
if (Tcl_VarEval(interp,"package require wyrm",oargv[p+1],0)!=TCL_OK) {
static char msg1[] = "require wyrm";
static char msg2[] = ": ";
char *result = Tcl_GetStringResult(interp);
write(2,msg1,sizeof(msg1)-1);
write(2,oargv[p+1],strlen(oargv[p+1]));
write(2,msg2,sizeof(msg2)-1);
write(2,result,strlen(result));
write(2,"\n",1);
return TCL_ERROR;
}
p++;
}else if (streq(oargv[p],"--")) {
break;
}
}
Tcl_VarEval(interp,"wyrm::mc -load [lindex $env(TCLLIBPATH) 0]/wyrmwif.msgs",0);
if (Tcl_VarEval(interp,"namespace import wyrm::*",0)!=TCL_OK) {
static char msg[] = "import wyrmwif: ";
char *result = Tcl_GetStringResult(interp);
write(2,msg,sizeof(msg)-1);
write(2,result,strlen(result));
write(2,"\n",1);
return TCL_ERROR;
}
| ^ | | | | | | section top | |
while (oargc>0) {
if (oargc>1 && streq(*oargv,"-s")) {
int rc = Tcl_EvalFile(interp,oargv[1]);
if (rc!=TCL_OK) {
static char msg1[] = "-s ";
static char msg2[] = ": error: ";
char *result = Tcl_GetStringResult(interp);
write(2,msg1,sizeof(msg1)-1);
write(2,oargv[1],strlen(oargv[1]));
write(2,msg2,sizeof(msg2)-1);
write(2,result,strlen(result));
write(2,"\n",1);
return TCL_ERROR;
}
oargc -= 2; oargv += 2;
}else if (oargc>1 && streq(*oargv,"-c")) {
int rc = Tcl_Eval(interp,oargv[1]);
char *result = Tcl_GetStringResult(interp);
if (rc==TCL_OK) {
write(1,result,strlen(result));
write(1,"\n",1);
}else {
static char msg[] = ": error: ";
char *result = Tcl_GetStringResult(interp);
write(2,oargv[1],strlen(oargv[1]));
write(2,msg,sizeof(msg)-1);
write(2,result,strlen(result));
write(2,"\n",1);
return TCL_ERROR;
}
oargc -= 2; oargv += 2;
}else if (oargc>1 && streq(*oargv,"-p")) {
oargc -= 2; oargv += 2;
}else if (streq(*oargv,"--")) {
oargc = 0;
}else {
oargv++; oargc--;
}
}
| ^ | | |
| |