diff --git a/src/cmd/ksh93/include/defs.h b/src/cmd/ksh93/include/defs.h index 568d6aee7130..f4c733584bbb 100644 --- a/src/cmd/ksh93/include/defs.h +++ b/src/cmd/ksh93/include/defs.h @@ -175,7 +175,7 @@ extern char *sh_getcwd(void); #if SHOPT_SCRIPTONLY #define is_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] & (1L << ((x) % WBITS))) ) -#define on_option(s,x) ( (x)==SH_INTERACTIVE || (x)==SH_HISTORY ? errormsg(SH_DICT,ERROR_exit(1),e_scriptonly) : ((s)->v[((x)&WMASK)/WBITS] |= (1L << ((x) % WBITS))) ) +#define on_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] |= (1L << ((x) % WBITS))) ) #define off_option(s,x) ((x)==SH_INTERACTIVE || (x)==SH_HISTORY ? 0 : ((s)->v[((x)&WMASK)/WBITS] &= ~(1L << ((x) % WBITS))) ) #else #define is_option(s,x) ((s)->v[((x)&WMASK)/WBITS] & (1L << ((x) % WBITS))) diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index 4bd97845d295..8ac7ff6614bf 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -107,7 +107,7 @@ static int sh_source(Sfio_t *iop, const char *file) #define REMOTE(m) !(m) #endif -int sh_main(int ac, char *av[], Shinit_f userinit) +int sh_mainex(int ac, char *av[], Shinit_f userinit,char *code,long codelen) { char *name; int fdin; @@ -231,6 +231,12 @@ int sh_main(int ac, char *av[], Shinit_f userinit) shell_c: iop = sfnew(NULL,sh.comdiv,strlen(sh.comdiv),0,SFIO_STRING|SFIO_READ); } + else if(code && codelen) { /* read kshcode from memory */ + sh.comdiv=code; + if (codelen == 1) codelen=strlen(code); + iop = sfnew(NULL,sh.comdiv,codelen,0,SFIO_STRING|SFIO_READ); + code=NULL; + } else { name = error_info.id; @@ -367,6 +373,26 @@ int sh_main(int ac, char *av[], Shinit_f userinit) sh_done(0); } +int sh_main(int ac, char *av[], Shinit_f userinit) +{ + return sh_mainex(ac, av, userinit, NULL , 0); +} + +int sh_maincode(int ac, char *av[], char *code) +{ + if (code) { + long len; + char *ptr; + len=strlen(code); + ptr=(char *)sh_malloc(len+8); + if (ptr) { + strcpy(ptr,code); + return sh_mainex(ac, av, NULL,ptr,len); + } + } + return 0; +} + /* * iop is not null when the input is a string * fdin is the input file descriptor