diff --git a/src/cmd/builtin/Mamfile b/src/cmd/builtin/Mamfile index b254b6553455..bec61645f831 100644 --- a/src/cmd/builtin/Mamfile +++ b/src/cmd/builtin/Mamfile @@ -106,11 +106,9 @@ make install prev ${PACKAGE_ast_INCLUDE}/shcmd.h implicit done ${PACKAGE_ast_INCLUDE}/cmdext.h prev ${PACKAGE_ast_INCLUDE}/shcmd.h - make ${PACKAGE_ast_INCLUDE}/stak.h implicit - make ${PACKAGE_ast_INCLUDE}/stk.h implicit - prev ${PACKAGE_ast_INCLUDE}/sfio.h - done ${PACKAGE_ast_INCLUDE}/stk.h - done ${PACKAGE_ast_INCLUDE}/stak.h + make ${PACKAGE_ast_INCLUDE}/stk.h implicit + prev ${PACKAGE_ast_INCLUDE}/sfio.h + done ${PACKAGE_ast_INCLUDE}/stk.h prev ${PACKAGE_ast_INCLUDE}/error.h prev ${PACKAGE_ast_INCLUDE}/ast.h done ${PACKAGE_ast_INCLUDE}/cmd.h diff --git a/src/cmd/ksh93/Mamfile b/src/cmd/ksh93/Mamfile index e58f1eb59f8b..ff7dd2e70204 100644 --- a/src/cmd/ksh93/Mamfile +++ b/src/cmd/ksh93/Mamfile @@ -190,9 +190,7 @@ make install prev ${PACKAGE_ast_INCLUDE}/shcmd.h implicit done ${PACKAGE_ast_INCLUDE}/cmdext.h prev ${PACKAGE_ast_INCLUDE}/shcmd.h - make ${PACKAGE_ast_INCLUDE}/stak.h implicit - prev ${PACKAGE_ast_INCLUDE}/stk.h - done ${PACKAGE_ast_INCLUDE}/stak.h + prev ${PACKAGE_ast_INCLUDE}/stk.h prev ${PACKAGE_ast_INCLUDE}/error.h prev ${PACKAGE_ast_INCLUDE}/ast.h done ${PACKAGE_ast_INCLUDE}/cmd.h @@ -229,9 +227,7 @@ make install prev include/shell.h prev ${PACKAGE_ast_INCLUDE}/endian.h prev include/name.h - make include/argnod.h implicit - prev ${PACKAGE_ast_INCLUDE}/stak.h - done include/argnod.h dontcare + prev include/argnod.h implicit prev ${PACKAGE_ast_INCLUDE}/cdt.h prev ${PACKAGE_ast_INCLUDE}/error.h prev ${PACKAGE_ast_INCLUDE}/sfio.h @@ -267,7 +263,6 @@ make install prev include/nval.h done include/variables.h prev ${PACKAGE_ast_INCLUDE}/error.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev include/defs.h prev shopt.h done bltins/cd_pwd.c @@ -335,7 +330,6 @@ make install prev include/variables.h prev ${PACKAGE_ast_INCLUDE}/error.h prev ${PACKAGE_ast_INCLUDE}/ls.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev include/defs.h prev shopt.h done bltins/hist.c @@ -412,7 +406,6 @@ make install prev include/history.h prev include/name.h prev include/io.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev ${PACKAGE_ast_INCLUDE}/error.h prev include/defs.h prev shopt.h @@ -575,7 +568,6 @@ make install prev ${PACKAGE_ast_INCLUDE}/sfio.h done include/fcin.h prev ${PACKAGE_ast_INCLUDE}/ls.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev ${PACKAGE_ast_INCLUDE}/sfio.h prev ${PACKAGE_ast_INCLUDE}/ast.h prev shopt.h @@ -634,7 +626,6 @@ make install make array.o make sh/array.c prev include/name.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev include/defs.h prev shopt.h done sh/array.c @@ -695,7 +686,6 @@ make install prev dirlib.h implicit dontcare virtual prev ${PACKAGE_ast_INCLUDE}/ast_lib.h done ${PACKAGE_ast_INCLUDE}/ast_dir.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev ${PACKAGE_ast_INCLUDE}/ls.h prev ${PACKAGE_ast_INCLUDE}/glob.h implicit prev ${PACKAGE_ast_INCLUDE}/ast.h @@ -786,7 +776,6 @@ make install prev ${PACKAGE_ast_INCLUDE}/regex.h prev ${PACKAGE_ast_INCLUDE}/tmx.h prev ${PACKAGE_ast_INCLUDE}/ccode.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev include/defs.h prev shopt.h done sh/init.c @@ -840,7 +829,6 @@ make install prev include/defs.h prev include/nval.h prev include/fcin.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev ${PACKAGE_ast_INCLUDE}/releaseflags.h prev ${PACKAGE_ast_INCLUDE}/ast.h prev shopt.h @@ -933,7 +921,6 @@ make install prev include/lexstates.h prev include/shtable.h prev ${PACKAGE_ast_INCLUDE}/ccode.h - prev ${PACKAGE_ast_INCLUDE}/stak.h prev include/defs.h prev ${PACKAGE_ast_INCLUDE}/ast_wchar.h prev ${PACKAGE_ast_INCLUDE}/ast.h @@ -944,7 +931,6 @@ make install make streval.o make sh/streval.c prev FEATURE/externs - prev ${PACKAGE_ast_INCLUDE}/stak.h prev ${PACKAGE_ast_INCLUDE}/error.h prev include/streval.h prev shopt.h diff --git a/src/cmd/ksh93/bltins/cd_pwd.c b/src/cmd/ksh93/bltins/cd_pwd.c index 7f9ccbaf0a62..fa765fba6472 100644 --- a/src/cmd/ksh93/bltins/cd_pwd.c +++ b/src/cmd/ksh93/bltins/cd_pwd.c @@ -28,7 +28,6 @@ #include "shopt.h" #include "defs.h" -#include #include #include "variables.h" #include "path.h" @@ -164,38 +163,37 @@ int b_cd(int argc, char *argv[],Shbltin_t *context) dp = cdpath?cdpath->name:""; cdpath = path_nextcomp(cdpath,dir,0); #if _WINIX - if(*stakptr(PATH_OFFSET+1)==':' && isalpha(*stakptr(PATH_OFFSET))) + if(*stkptr(sh.stk,PATH_OFFSET+1)==':' && isalpha(*stkptr(sh.stk,PATH_OFFSET))) { - *stakptr(PATH_OFFSET+1) = *stakptr(PATH_OFFSET); - *stakptr(PATH_OFFSET)='/'; + *stkptr(sh.stk,PATH_OFFSET+1) = *stkptr(sh.stk,PATH_OFFSET); + *stkptr(sh.stk,PATH_OFFSET)='/'; } #endif /* _WINIX */ - if(*stakptr(PATH_OFFSET)!='/') + if(*stkptr(sh.stk,PATH_OFFSET)!='/') { - char *last=(char*)stakfreeze(1); - stakseek(PATH_OFFSET); - stakputs(oldpwd); + char *last=(char*)stkfreeze(sh.stk,1); + stkseek(sh.stk,PATH_OFFSET); + sfputr(sh.stk,oldpwd,-1); /* don't add '/' if oldpwd is / itself */ if(*oldpwd!='/' || oldpwd[1]) - stakputc('/'); - stakputs(last+PATH_OFFSET); - stakputc(0); + sfputc(sh.stk,'/'); + sfputr(sh.stk,last+PATH_OFFSET,0); } if(!pflag) { char *cp; - stakseek(PATH_MAX+PATH_OFFSET); - if(*(cp=stakptr(PATH_OFFSET))=='/') + stkseek(sh.stk,PATH_MAX+PATH_OFFSET); + if(*(cp=stkptr(sh.stk,PATH_OFFSET))=='/') if(!pathcanon(cp,PATH_DOTDOT)) continue; } - if((rval=chdir(path_relative(stakptr(PATH_OFFSET)))) >= 0) + if((rval=chdir(path_relative(stkptr(sh.stk,PATH_OFFSET)))) >= 0) goto success; if(errno!=ENOENT && saverrno==0) saverrno=errno; } while(cdpath); - if(rval<0 && *dir=='/' && *(path_relative(stakptr(PATH_OFFSET)))!='/') + if(rval<0 && *dir=='/' && *(path_relative(stkptr(sh.stk,PATH_OFFSET)))!='/') rval = chdir(dir); /* use absolute chdir() if relative chdir() fails */ if(rval<0) @@ -210,16 +208,16 @@ int b_cd(int argc, char *argv[],Shbltin_t *context) dp = dir; /* print out directory for cd - */ if(pflag) { - dir = stakptr(PATH_OFFSET); + dir = stkptr(sh.stk,PATH_OFFSET); if (!(dir=pathcanon(dir,PATH_PHYSICAL))) { - dir = stakptr(PATH_OFFSET); + dir = stkptr(sh.stk,PATH_OFFSET); errormsg(SH_DICT,ERROR_system(ret),"%s:",dir); UNREACHABLE(); } - stakseek(dir-stakptr(0)); + stkseek(sh.stk,dir-stkptr(sh.stk,0)); } - dir = (char*)stakfreeze(1)+PATH_OFFSET; + dir = stkfreeze(sh.stk,1)+PATH_OFFSET; if(*dp && (*dp!='.'||dp[1]) && strchr(dir,'/')) sfputr(sfstdout,dir,'\n'); nv_putval(opwdnod,oldpwd,NV_RDONLY); @@ -290,7 +288,7 @@ int b_pwd(int argc, char *argv[],Shbltin_t *context) } if(flag) { - cp = strcpy(stakseek(strlen(cp)+PATH_MAX),cp); + cp = strcpy(stkseek(sh.stk,strlen(cp)+PATH_MAX),cp); pathcanon(cp,PATH_PHYSICAL); } sfputr(sfstdout,cp,'\n'); diff --git a/src/cmd/ksh93/bltins/enum.c b/src/cmd/ksh93/bltins/enum.c index dd82bb553846..d3755128442d 100644 --- a/src/cmd/ksh93/bltins/enum.c +++ b/src/cmd/ksh93/bltins/enum.c @@ -256,10 +256,8 @@ int b_enum(int argc, char** argv, Shbltin_t *context) error(ERROR_exit(1), "%s must name an array containing at least two elements",cp); UNREACHABLE(); } - n = staktell(); - sfprintf(stkstd,"%s.%s%c",NV_CLASS,np->nvname,0); - tp = nv_open(stakptr(n), sh.var_tree, NV_VARNAME); - stakseek(n); + sfprintf(sh.strbuf,"%s.%s",NV_CLASS,np->nvname); + tp = nv_open(sfstruse(sh.strbuf), sh.var_tree, NV_VARNAME); n = sz; i = 0; nv_onattr(tp, NV_UINT16); diff --git a/src/cmd/ksh93/bltins/hist.c b/src/cmd/ksh93/bltins/hist.c index 050692337ad4..fae42d688492 100644 --- a/src/cmd/ksh93/bltins/hist.c +++ b/src/cmd/ksh93/bltins/hist.c @@ -17,7 +17,6 @@ ***********************************************************************/ #include "shopt.h" #include "defs.h" -#include #include #include #include "variables.h" @@ -322,7 +321,7 @@ static void hist_subst(const char *command,int fd,char *replace) return; lseek(fd,0,SEEK_SET); c = (int)size; - string = stakalloc(c+1); + string = stkalloc(sh.stk,c+1); if(read(fd,string,c)!=c) return; string[c] = 0; diff --git a/src/cmd/ksh93/bltins/print.c b/src/cmd/ksh93/bltins/print.c index 6b970f2bb1e6..dbef20d9b003 100644 --- a/src/cmd/ksh93/bltins/print.c +++ b/src/cmd/ksh93/bltins/print.c @@ -27,7 +27,6 @@ #include "shopt.h" #include "defs.h" #include -#include #include "io.h" #include "name.h" #include "history.h" @@ -359,7 +358,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context) sfprintf(outfile,"%!",&pdata); } while(*pdata.nextarg && pdata.nextarg!=argv); if(pdata.nextarg == nullarg && pdata.argsize>0) - if(sfwrite(outfile,stakptr(staktell()),pdata.argsize) < 0) + if(sfwrite(outfile,stkptr(sh.stk,stktell(sh.stk)),pdata.argsize) < 0) exitval = 1; sfpool(sfstderr,pool,SF_WRITE); if (pdata.err) @@ -424,7 +423,7 @@ static int echolist(Sfio_t *outfile, int raw, char *argv[]) if(!raw && (n=fmtvecho(cp,&pdata))>=0) { if(n) - if(sfwrite(outfile,stakptr(staktell()),n) < 0) + if(sfwrite(outfile,stkptr(sh.stk,stktell(sh.stk)),n) < 0) exitval = 1; } else @@ -498,9 +497,9 @@ static char strformat(char *s) static char *genformat(char *format) { char *fp; - stakseek(0); - stakputs(format); - fp = (char*)stakfreeze(1); + stkseek(sh.stk,0); + sfputr(sh.stk,format,-1); + fp = stkfreeze(sh.stk,1); strformat(fp); return fp; } @@ -508,7 +507,7 @@ static char *genformat(char *format) static char *fmthtml(const char *string, int flags) { const char *cp = string, *op; - int c, offset = staktell(); + int c, offset = stktell(sh.stk); /* * The only multibyte locale ksh currently supports is UTF-8, which is a superset of ASCII. So, if we're on an * EBCDIC system, below we attempt to convert EBCDIC to ASCII only if we're not in a multibyte locale (mbwide()). @@ -522,19 +521,19 @@ static char *fmthtml(const char *string, int flags) if(!mbwide()) c = CCMAPC(c,CC_NATIVE,CC_ASCII); if(mbwide() && c < 0) /* invalid multibyte char */ - stakputc('?'); + sfputc(sh.stk,'?'); else if(c == 60) /* < */ - stakputs("<"); + sfputr(sh.stk,"<",-1); else if(c == 62) /* > */ - stakputs(">"); + sfputr(sh.stk,">",-1); else if(c == 38) /* & */ - stakputs("&"); + sfputr(sh.stk,"&",-1); else if(c == 34) /* " */ - stakputs("""); + sfputr(sh.stk,""",-1); else if(c == 39) /* ' (' is not HTML) */ - stakputs("'"); + sfputr(sh.stk,"'",-1); else - stakwrite(op, cp-op); + sfwrite(sh.stk, op, cp-op); } } else @@ -545,12 +544,12 @@ static char *fmthtml(const char *string, int flags) while(op = cp, c = mbchar(cp)) { if(c < 0) - stakputs("%3F"); + sfputr(sh.stk,"%3F",-1); else if(c < 128 && strchr(URI_RFC3986_UNRESERVED, c)) - stakputc(c); + sfputc(sh.stk,c); else while(c = *(unsigned char*)op++, op <= cp) - sfprintf(stkstd, "%%%02X", c); + sfprintf(sh.stk, "%%%02X", c); } } else @@ -558,14 +557,14 @@ static char *fmthtml(const char *string, int flags) while(c = *(unsigned char*)cp++) { if(strchr(URI_RFC3986_UNRESERVED, c)) - stakputc(c); + sfputc(sh.stk,c); else - sfprintf(stkstd, "%%%02X", CCMAPC(c, CC_NATIVE, CC_ASCII)); + sfprintf(sh.stk, "%%%02X", CCMAPC(c, CC_NATIVE, CC_ASCII)); } } } - stakputc(0); - return stakptr(offset); + sfputc(sh.stk,0); + return stkptr(sh.stk,offset); } static ssize_t fmtbase64(Sfio_t *iop, char *string, int alt) @@ -1013,7 +1012,7 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe) pp->argsize = n; return -1; } - value->s = stakptr(staktell()); + value->s = stkptr(sh.stk,stktell(sh.stk)); fe->size = n; } break; @@ -1087,7 +1086,7 @@ static int fmtvecho(const char *string, struct printf *pp) { const char *cp = string, *cpmax; int c; - int offset = staktell(); + int offset = stktell(sh.stk); int chlen; if(mbwide()) { @@ -1107,12 +1106,12 @@ static int fmtvecho(const char *string, struct printf *pp) return -1; c = --cp - string; if(c>0) - stakwrite(string,c); + sfwrite(sh.stk,string,c); for(; c= *cp; cp++) { if (mbwide() && ((chlen = mbsize(cp)) > 1)) { - stakwrite(cp,chlen); + sfwrite(sh.stk,cp,chlen); cp += (chlen-1); continue; } @@ -1161,11 +1160,11 @@ static int fmtvecho(const char *string, struct printf *pp) default: cp--; } - stakputc(c); + sfputc(sh.stk,c); } done: - c = staktell()-offset; - stakputc(0); - stakseek(offset); + c = stktell(sh.stk)-offset; + sfputc(sh.stk,0); + stkseek(sh.stk,offset); return c; } diff --git a/src/cmd/ksh93/bltins/read.c b/src/cmd/ksh93/bltins/read.c index 7db988172ce1..ab9a3ee0cd29 100644 --- a/src/cmd/ksh93/bltins/read.c +++ b/src/cmd/ksh93/bltins/read.c @@ -570,7 +570,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim else c = S_NL; sh.nextprompt = 2; - rel= staktell(); + rel = stktell(sh.stk); mbinit(); /* val==0 at the start of a field */ val = 0; @@ -605,13 +605,13 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim inquote = !inquote; if(val) { - stakputs(val); + sfputr(sh.stk,val,-1); use_stak = 1; *val = 0; } if(c==-1) { - stakputc('"'); + sfputc(sh.stk,'"'); c = sh.ifstable[*cp++]; } continue; @@ -623,7 +623,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim c = 0; if(val) { - stakputs(val); + sfputr(sh.stk,val,-1); use_stak = 1; was_escape = 1; *val = 0; @@ -637,7 +637,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim /* check for end of buffer */ if(val && *val) { - stakputs(val); + sfputr(sh.stk,val,-1); use_stak = 1; } val = 0; @@ -737,7 +737,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim { if(val) { - stakwrite(val,cp-(unsigned char*)val); + sfwrite(sh.stk,val,cp-(unsigned char*)val); use_stak = 1; } val = (char*)++cp; @@ -751,7 +751,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim { if(val) { - stakwrite(val,cp-(unsigned char*)val); + sfwrite(sh.stk,val,cp-(unsigned char*)val); use_stak=1; } if(cp = (unsigned char*)sfgetr(iop,delim,0)) @@ -781,9 +781,8 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim val = ""; if(use_stak) { - stakputs(val); - stakputc(0); - val = stakptr(rel); + sfputr(sh.stk,val,0); + val = stkptr(sh.stk,rel); } if(!name && *val) { @@ -810,7 +809,7 @@ int sh_readline(char **names, volatile int fd, int flags, ssize_t size, long tim del = 0; if(use_stak) { - stakseek(rel); + stkseek(sh.stk,rel); use_stak = 0; } if(array_index) diff --git a/src/cmd/ksh93/bltins/test.c b/src/cmd/ksh93/bltins/test.c index 909a9b4c150d..321bc22d86af 100644 --- a/src/cmd/ksh93/bltins/test.c +++ b/src/cmd/ksh93/bltins/test.c @@ -404,15 +404,10 @@ int test_unop(int op,const char *arg) case 'H': #ifdef S_ISCDF { - int offset = staktell(); if(test_stat(arg,&statb)>=0 && S_ISCDF(statb.st_mode)) return 1; - stakputs(arg); - stakputc('+'); - stakputc(0); - arg = (const char*)stakptr(offset); - stakseek(offset); - return test_stat(arg,&statb)>=0 && S_ISCDF(statb.st_mode); + sfputr(sh.strbuf,arg,'+'); + return test_stat(sfstruse(sh.strbuf),&statb)>=0 && S_ISCDF(statb.st_mode); } #else return 0; @@ -671,7 +666,7 @@ int sh_access(const char *name, int mode) maxgroups = (int)astconf_long(CONF_NGROUPS_MAX); } } - groups = (gid_t*)stakalloc((maxgroups+1)*sizeof(gid_t)); + groups = (gid_t*)stkalloc(sh.stk,(maxgroups+1)*sizeof(gid_t)); n = getgroups(maxgroups,groups); while(--n >= 0) { diff --git a/src/cmd/ksh93/bltins/trap.c b/src/cmd/ksh93/bltins/trap.c index 512b1c9101f9..c675cfb3c901 100644 --- a/src/cmd/ksh93/bltins/trap.c +++ b/src/cmd/ksh93/bltins/trap.c @@ -350,35 +350,35 @@ static int sig_number(const char *string) else { int c; - o = staktell(); + o = stktell(sh.stk); do { c = *string++; if(islower(c)) c = toupper(c); - stakputc(c); + sfputc(sh.stk,c); } while(c); - stakseek(o); - if(strncmp(stakptr(o),"SIG",3)==0) + stkseek(sh.stk,o); + if(strncmp(stkptr(sh.stk,o),"SIG",3)==0) { sig = 1; o += 3; - if(isdigit(*stakptr(o))) + if(isdigit(*stkptr(sh.stk,o))) { - n = strtol(stakptr(o),&last,10); + n = strtol(stkptr(sh.stk,o),&last,10); if(!*last) return n; } } - tp = sh_locate(stakptr(o),(const Shtable_t*)shtab_signals,sizeof(*shtab_signals)); + tp = sh_locate(stkptr(sh.stk,o),(const Shtable_t*)shtab_signals,sizeof(*shtab_signals)); n = tp->sh_number; if(sig==1 && (n>=(SH_TRAP-1) && n < (1<sh_name)==0) + if(strcmp(stkptr(sh.stk,o),tp->sh_name)==0) n = tp->sh_number; } if((n>>SH_SIGBITS)&SH_SIGRUNTIME) @@ -389,7 +389,7 @@ static int sig_number(const char *string) if(n < SH_TRAP) n--; } - if(n<0 && sh.sigruntime[1] && (name=stakptr(o)) && *name++=='R' && *name++=='T') + if(n<0 && sh.sigruntime[1] && (name=stkptr(sh.stk,o)) && *name++=='R' && *name++=='T') { /* Real-time signals */ if(name[0]=='M' && name[1]=='I' && name[2]=='N' && name[3]=='+') /* MIN+ */ @@ -522,7 +522,7 @@ static void sig_list(int flag) { sname = sig_name(sig,name,1); if(flag) - sname = stakcopy(sname); + sname = stkcopy(sh.stk,sname); } if(flag) names[sig] = sname; diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index 8d6f35abcafb..602a2ffcdad8 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -233,7 +233,7 @@ int b_typeset(int argc,char *argv[],Shbltin_t *context) } else if(argv[0][0] != 't') /* not ypeset */ { - char **new_argv = (char **)stakalloc((argc + 2) * sizeof(char*)); + char **new_argv = (char **)stkalloc(sh.stk, (argc + 2) * sizeof(char*)); error_info.id = new_argv[0] = SYSTYPESET->nvname; if(argv[0][0] == 'a') /* utoload == typeset -fu */ new_argv[1] = "-fu"; diff --git a/src/cmd/ksh93/bltins/whence.c b/src/cmd/ksh93/bltins/whence.c index 140d815a7d3a..b06d0b80a869 100644 --- a/src/cmd/ksh93/bltins/whence.c +++ b/src/cmd/ksh93/bltins/whence.c @@ -218,8 +218,8 @@ static int whence(char **argv, int flags) pp = 0; while(!path_search(name,&pp,3) && pp && (pp = pp->next)) ; - if(*stakptr(PATH_OFFSET)=='/') - sfprintf(sfstdout,sh_translate(e_autoloadfrom),sh_fmtq(stakptr(PATH_OFFSET))); + if(*stkptr(sh.stk,PATH_OFFSET)=='/') + sfprintf(sfstdout,sh_translate(e_autoloadfrom),sh_fmtq(stkptr(sh.stk,PATH_OFFSET))); } else sfprintf(sfstdout,sh_translate(is_function)); @@ -272,7 +272,7 @@ static int whence(char **argv, int flags) } else { - cp = stakptr(PATH_OFFSET); + cp = stkptr(sh.stk,PATH_OFFSET); if(*cp==0) cp = 0; } @@ -294,7 +294,7 @@ static int whence(char **argv, int flags) else if(flags&V_FLAG) { sfprintf(sfstdout,sh_translate(is_ufunction)); - sfprintf(sfstdout,sh_translate(e_autoloadfrom),sh_fmtq(stakptr(PATH_OFFSET))); + sfprintf(sfstdout,sh_translate(e_autoloadfrom),sh_fmtq(stkptr(sh.stk,PATH_OFFSET))); } sfputc(sfstdout,'\n'); } diff --git a/src/cmd/ksh93/builtins.mm b/src/cmd/ksh93/builtins.mm index 7568a2546d76..7bfe1bf8b2cb 100644 --- a/src/cmd/ksh93/builtins.mm +++ b/src/cmd/ksh93/builtins.mm @@ -273,7 +273,7 @@ int b_hello(int argc, char *argv[], void *context) .P The best thing to do is to include the header file \f5\fP. This header file causes the \f5\fP header, the -\f5\fP header and the \f5\fP +\f5\fP header and the \f5\fP header to be included as well as defining prototypes for functions that you can call to get shell services for your builtins. @@ -295,7 +295,7 @@ int b_hello(int argc, char *argv[], void *context) these headers. The \f5\fP header provides the interface to the error and option parsing routines defined below. -The \f5\fP header provides the interface to the memory +The \f5\fP header provides the interface to the memory allocation routines described below. .P Programs that want to use the information in \f5\fP @@ -465,15 +465,15 @@ int optget(char *\fIargv\fP[], const char *\fIoptstring\fP) interrupt and the memory will not be freed. .P The best way to allocate variable sized storage is -through calls to the \fBstak\fP library +through calls to the \fBstk\fP library which is included in \fBlibast\fP and which is used extensively by \f5ksh\fP itself. -Objects allocated with the \f5stakalloc()\fP +Objects allocated with the \f5stkalloc()\fP function are freed when you function completes or aborts. -The \fBstak\fP library provides a convenient way to +The \fBstk\fP library provides a convenient way to build variable length strings and other objects dynamically. -The man page for the \fBstak\fP library is contained +The man page for the \fBstk\fP library is contained in the Appendix. .P Before \f5ksh\fP calls each built-in command, it saves @@ -490,13 +490,13 @@ int optget(char *\fIargv\fP[], const char *\fIoptstring\fP) { char *savebase; int saveoffset; - if(saveoffset=staktell()) - savebase = stakfreeze(0); + if(saveoffset=stktell(stkstd)) + savebase = stkfreeze(stkstd,0); \fR...\fP if(saveoffset) - stakset(savebase,saveoffset); + stkset(stkstd,savebase,saveoffset); else - stakseek(0); + stkseek(stkstd,0); } .EE .H 1 "CALLING \f5ksh\fP SERVICES" diff --git a/src/cmd/ksh93/edit/completion.c b/src/cmd/ksh93/edit/completion.c index 5c9662ab3ab8..bc6ae9c4cfbd 100644 --- a/src/cmd/ksh93/edit/completion.c +++ b/src/cmd/ksh93/edit/completion.c @@ -41,7 +41,7 @@ static char *fmtx(const char *string) int n,c; int pos = 0; unsigned char *state = (unsigned char*)sh_lexstates[2]; - int offset = staktell(); + int offset = stktell(sh.stk); char hc[3]; #if SHOPT_HISTEXPAND const char hexp = sh_isoption(SH_HISTEXPAND)!=0; @@ -51,28 +51,28 @@ static char *fmtx(const char *string) const char hexp = 0; #endif /* SHOPT_HISTEXPAND */ if((!hexp || (*cp!=hc[0] && *cp!=hc[2])) && (*cp=='#' || *cp=='~')) - stakputc('\\'); + sfputc(sh.stk,'\\'); mbinit(); while((c=mbchar(cp)),((c>UCHAR_MAX)||(n=state[c])==0 || n==S_EPAT) && (!hexp || ((c!=hc[0]) && (c!=hc[2] || string[0]!=hc[2]))) && c!='~') ; if(n==S_EOF && *string!='#') return (char*)string; - stakwrite(string,--cp-string); + sfwrite(sh.stk,string,--cp-string); for(string=cp;c=mbchar(cp);string=cp) { if((n=cp-string)==1) { if(((n=state[c]) && n!=S_EPAT) || (hexp && ((c==hc[0]) || (c==hc[2] && !pos)))) - stakputc('\\'); - stakputc(c); + sfputc(sh.stk,'\\'); + sfputc(sh.stk,c); } else - stakwrite(string,n); + sfwrite(sh.stk,string,n); pos++; } - stakputc(0); - return stakptr(offset); + sfputc(sh.stk,0); + return stkptr(sh.stk,offset); } #if !SHOPT_GLOBCASEDET @@ -275,12 +275,12 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) } else { - stakset(ep->e_stkptr,ep->e_stkoff); + stkset(sh.stk,ep->e_stkptr,ep->e_stkoff); ep->e_nlist = 0; } } - comptr = (struct comnod*)stakalloc(sizeof(struct comnod)); - ap = (struct argnod*)stakseek(ARGVAL); + comptr = (struct comnod*)stkalloc(sh.stk,sizeof(struct comnod)); + ap = (struct argnod*)stkseek(sh.stk,ARGVAL); #if SHOPT_MULTIBYTE { int c = *cur; @@ -289,7 +289,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) cp = (genchar *)outbuff + *cur; c = *cp; *cp = 0; - *cur = ed_external((genchar*)outbuff,(char*)stakptr(0)); + *cur = ed_external((genchar*)outbuff,(char*)stkptr(sh.stk,0)); *cp = c; *eol = ed_external((genchar*)outbuff,outbuff); } @@ -332,9 +332,9 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) else if(var=='$') { /* expand ${!varname@} to complete variable name(s) */ - stakputs("${!"); - stakwrite(out,last-out); - stakputs("@}"); + sfputr(sh.stk,"${!",-1); + sfwrite(sh.stk,out,last-out); + sfputr(sh.stk,"@}",-1); out = last; } else @@ -352,7 +352,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) strip = 0; dir = out+1; } - stakputc(c); + sfputc(sh.stk,c); out++; } } @@ -368,8 +368,9 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) else if(!strchr(begin,'/')) addstar = 0; } - stakputc(addstar); - ap = (struct argnod*)stakfreeze(1); + if(addstar) + sfputc(sh.stk,addstar); + ap = (struct argnod*)stkfreeze(sh.stk,1); } if(mode!='*') sh_onoption(SH_MARKDIRS); @@ -474,7 +475,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) } /* save remainder of the buffer */ if(*out) - left=stakcopy(out); + left=stkcopy(sh.stk,out); if(cmd_completion && mode=='\\') out = strcopy(begin,path_basename(cp= *com++)); else if(mode=='*') @@ -568,7 +569,7 @@ int ed_expand(Edit_t *ep, char outbuff[],int *cur,int *eol,int mode, int count) sh_offstate(SH_FCOMPLETE); sh_offstate(SH_NOTILDEXP); if(!ep->e_nlist) - stakset(ep->e_stkptr,ep->e_stkoff); + stkset(sh.stk,ep->e_stkptr,ep->e_stkoff); if(nomarkdirs) sh_offoption(SH_MARKDIRS); #if SHOPT_MULTIBYTE diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c index aca2e7904aae..32e1e835dfc2 100644 --- a/src/cmd/ksh93/edit/edit.c +++ b/src/cmd/ksh93/edit/edit.c @@ -461,8 +461,8 @@ void ed_setup(Edit_t *ep, int fd, int reedit) ep->nhlist = 0; ep->hoff = 0; #endif /* SHOPT_EDPREDICT */ - ep->e_stkoff = staktell(); - ep->e_stkptr = stakfreeze(0); + ep->e_stkoff = stktell(sh.stk); + ep->e_stkptr = stkfreeze(sh.stk,0); #if SHOPT_MULTIBYTE ep->e_savedwidth = 0; #endif /* SHOPT_MULTIBYTE */ diff --git a/src/cmd/ksh93/edit/emacs.c b/src/cmd/ksh93/edit/emacs.c index fc03a6f2a2ab..5d3697cbf4f8 100644 --- a/src/cmd/ksh93/edit/emacs.c +++ b/src/cmd/ksh93/edit/emacs.c @@ -735,7 +735,7 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit) tty_cooked(ERRIO); if(ed->e_nlist) ed->e_nlist = 0; - stakset(ed->e_stkptr,ed->e_stkoff); + stkset(sh.stk,ed->e_stkptr,ed->e_stkoff); if(c == '\n') { out[eol++] = '\n'; diff --git a/src/cmd/ksh93/edit/hexpand.c b/src/cmd/ksh93/edit/hexpand.c index 5638bd94a622..c8eb9e76162f 100644 --- a/src/cmd/ksh93/edit/hexpand.c +++ b/src/cmd/ksh93/edit/hexpand.c @@ -43,7 +43,7 @@ NoN(hexpand) static char *modifiers = "htrepqxs&"; static int mod_flags[] = { 0, 0, 0, 0, HIST_PRINT, HIST_QUOTE, HIST_QUOTE|HIST_QUOTE_BR, 0, 0 }; -#define DONE { stakseek(0); goto done; } +#define DONE { stkseek(sh.stk,0); goto done; } #define ERROROUT { flag |= HIST_ERROR; DONE; } struct subst @@ -68,7 +68,7 @@ static char *parse_subst(const char *s, struct subst *sb) int off,n = 0; /* build the strings on the stack, mainly for '&' substitution in "new" */ - off = staktell(); + off = stktell(sh.stk); /* init "new" with empty string */ if(sb->str[1]) @@ -85,14 +85,14 @@ static char *parse_subst(const char *s, struct subst *sb) if(*cp == del || *cp == '\n' || *cp == '\0') { /* delimiter or EOL */ - if(staktell() != off) + if(stktell(sh.stk) != off) { /* dupe string on stack and rewind stack */ - stakputc('\0'); + sfputc(sh.stk,'\0'); if(sb->str[n]) free(sb->str[n]); - sb->str[n] = sh_strdup(stakptr(off)); - stakseek(off); + sb->str[n] = sh_strdup(stkptr(sh.stk,off)); + stkseek(sh.stk,off); } n++; @@ -104,27 +104,27 @@ static char *parse_subst(const char *s, struct subst *sb) { if(*(cp+1) == del) /* quote delimiter */ { - stakputc(del); + sfputc(sh.stk,del); cp++; } else if(*(cp+1) == '&' && n == 1) { /* quote '&' only in "new" */ - stakputc('&'); + sfputc(sh.stk,'&'); cp++; } else - stakputc('\\'); + sfputc(sh.stk,'\\'); } else if(*cp == '&' && n == 1 && sb->str[0]) /* substitute '&' with "old" in "new" */ - stakputs(sb->str[0]); + sfputr(sh.stk,sb->str[0],-1); else - stakputc(*cp); + sfputc(sh.stk,*cp); cp++; } /* rewind stack */ - stakseek(off); + stkseek(sh.stk,off); return cp; } @@ -190,8 +190,8 @@ int hist_expand(const char *ln, char **xp) hist_setchars(hc); /* save shell stack */ - if(off = staktell()) - sp = stakfreeze(0); + if(off = stktell(sh.stk)) + sp = stkfreeze(sh.stk,0); cp = (char*)ln; @@ -202,14 +202,14 @@ int hist_expand(const char *ln, char **xp) || (*cp == hc[1] && cp != ln)) { if(*cp == '\\') /* skip escaped designators */ - stakputc(*cp++); + sfputc(sh.stk,*cp++); else if(*cp == '\'') /* skip quoted designators */ { do - stakputc(*cp); + sfputc(sh.stk,*cp); while(*++cp && *cp != '\''); } - stakputc(*cp++); + sfputc(sh.stk,*cp++); continue; } @@ -218,10 +218,10 @@ int hist_expand(const char *ln, char **xp) if(cp == ln || is_wordboundary(cp[-1])) { /* word begins with history comment character; skip rest of line */ - stakputs(cp); + sfputr(sh.stk,cp,0); DONE; } - stakputc(*cp++); + sfputc(sh.stk,*cp++); continue; } @@ -250,15 +250,15 @@ int hist_expand(const char *ln, char **xp) case '\0': case '=': case '(': - stakputc(hc[0]); + sfputc(sh.stk,hc[0]); continue; case '#': /* the line up to current position */ flag |= HIST_HASH; cp++; - n = staktell(); /* terminate string and dup */ - stakputc('\0'); - cc = sh_strdup(stakptr(0)); - stakseek(n); /* remove null byte again */ + n = stktell(sh.stk); /* terminate string and dup */ + sfputc(sh.stk,'\0'); + cc = sh_strdup(stkptr(sh.stk,0)); + stkseek(sh.stk,n); /* remove null byte again */ ref = sfopen(ref, cc, "s"); /* open as file */ n = 0; /* skip history file referencing */ break; @@ -685,7 +685,7 @@ int hist_expand(const char *ln, char **xp) sfseek(tmp, 0, SEEK_SET); if(flag & HIST_QUOTE) - stakputc('\''); + sfputc(sh.stk,'\''); while((c = sfgetc(tmp)) > 0) { @@ -704,30 +704,21 @@ int hist_expand(const char *ln, char **xp) c = (flag & HIST_NEWLINE) ? '\n' : ' '; if(flag & HIST_QUOTE_BR) - { - stakputc('\''); - stakputc(c); - stakputc('\''); - } + sfprintf(sh.stk,"'%c'",c); else - stakputc(c); + sfputc(sh.stk,c); } else if((c == '\'') && (flag & HIST_QUOTE)) - { - stakputc('\''); - stakputc('\\'); - stakputc(c); - stakputc('\''); - } + sfprintf(sh.stk,"'\\%c'",c); else - stakputc(c); + sfputc(sh.stk,c); } if(flag & HIST_QUOTE) - stakputc('\''); + sfputc(sh.stk,'\''); } } - stakputc('\0'); + sfputc(sh.stk,'\0'); done: if(cc && (flag&HIST_HASH)) @@ -739,14 +730,14 @@ int hist_expand(const char *ln, char **xp) } /* error? */ - if(staktell() && !(flag & HIST_ERROR)) - *xp = sh_strdup(stakfreeze(1)); + if(stktell(sh.stk) && !(flag & HIST_ERROR)) + *xp = sh_strdup(stkfreeze(sh.stk,1)); /* restore shell stack */ if(off) - stakset(sp,off); + stkset(sh.stk,sp,off); else - stakseek(0); + stkseek(sh.stk,0); /* drop temporary files */ diff --git a/src/cmd/ksh93/edit/history.c b/src/cmd/ksh93/edit/history.c index f4ec2390a798..c49c23244d00 100644 --- a/src/cmd/ksh93/edit/history.c +++ b/src/cmd/ksh93/edit/history.c @@ -214,13 +214,12 @@ int sh_histinit(void) return 1; if(!(histname = nv_getval(HISTFILE))) { - int offset = staktell(); + int offset = stktell(sh.stk); if(cp=nv_getval(HOME)) - stakputs(cp); - stakputs(hist_fname); - stakputc(0); - stakseek(offset); - histname = stakptr(offset); + sfputr(sh.stk,cp,-1); + sfputr(sh.stk,hist_fname,0); + stkseek(sh.stk,offset); + histname = stkptr(sh.stk,offset); } retry: cp = path_relative(histname); @@ -783,13 +782,13 @@ static ssize_t hist_write(Sfio_t *iop,const void *buff,size_t insize,Sfdisc_t* h if(acctfd) { int timechars, offset; - offset = staktell(); - stakputs(buff); - stakseek(staktell() - 1); - timechars = sfprintf(staksp, "\t%s\t%x\n",logname,time(NULL)); + offset = stktell(sh.stk); + sfputr(sh.stk,buff,-1); + stkseek(sh.stk,stktell(sh.stk) - 1); + timechars = sfprintf(sh.stk, "\t%s\t%x\n",logname,time(NULL)); lseek(acctfd, 0, SEEK_END); - write(acctfd, stakptr(offset), size - 2 + timechars); - stakseek(offset); + write(acctfd, stkptr(sh.stk,offset), size - 2 + timechars); + stkseek(sh.stk,offset); } #endif /* SHOPT_ACCTFILE */ diff --git a/src/cmd/ksh93/edit/vi.c b/src/cmd/ksh93/edit/vi.c index b46a9c6af683..bfc4787d0d44 100644 --- a/src/cmd/ksh93/edit/vi.c +++ b/src/cmd/ksh93/edit/vi.c @@ -338,7 +338,7 @@ int ed_viread(void *context, int fd, char *shbuf, int nchar, int reedit) tty_cooked(ERRIO); if(ed->e_nlist) ed->e_nlist = 0; - stakset(ed->e_stkptr,ed->e_stkoff); + stkset(sh.stk,ed->e_stkptr,ed->e_stkoff); if( vp->addnl ) { virtual[++last_virt] = '\n'; diff --git a/src/cmd/ksh93/features/externs b/src/cmd/ksh93/features/externs index 5a7c12b103ce..81d4b500714c 100644 --- a/src/cmd/ksh93/features/externs +++ b/src/cmd/ksh93/features/externs @@ -47,7 +47,7 @@ tst note{ determining default number of extra bytes per argument for arguments l #include #include #include - #include + #include #include int main(int argc,char *argv[]) @@ -80,7 +80,7 @@ tst note{ determining default number of extra bytes per argument for arguments l int bytec; error_info.id="_arg_extrabytes test (child)"; - argv = (char **)stakalloc((argmax / 2 + 1) * sizeof(char*)); + argv = (char **)stkalloc(stkstd, (argmax / 2 + 1) * sizeof(char*)); argc = bytec = 0; while(bytec < argmax) { diff --git a/src/cmd/ksh93/include/argnod.h b/src/cmd/ksh93/include/argnod.h index e2054448fa1f..58aa5867aa90 100644 --- a/src/cmd/ksh93/include/argnod.h +++ b/src/cmd/ksh93/include/argnod.h @@ -22,8 +22,6 @@ * */ -#include - struct ionod { unsigned iofile; @@ -57,7 +55,7 @@ struct slnod /* struct for linked list of stacks */ { struct slnod *slnext; struct slnod *slchild; - Stak_t *slptr; + Sfio_t *slptr; /* slpad aligns struct functnod = struct slnod + 1 on some architectures */ struct slnod *slpad; }; diff --git a/src/cmd/ksh93/sh/arith.c b/src/cmd/ksh93/sh/arith.c index f35173092e34..22c509d592a7 100644 --- a/src/cmd/ksh93/sh/arith.c +++ b/src/cmd/ksh93/sh/arith.c @@ -77,9 +77,9 @@ static Namval_t *scope(Namval_t *np,struct lval *lvalue,int assign) int c = cp[flag]; cp[flag] = 0; if((!(np = nv_open(cp,sh.var_tree,assign|NV_VARNAME|NV_NOADD|NV_NOFAIL)) || nv_isnull(np)) - && sh_macfun(cp, offset = staktell())) + && sh_macfun(cp, offset = stktell(sh.stk))) { - Fun = sh_arith(sub=stakptr(offset)); + Fun = sh_arith(sub=stkptr(sh.stk,offset)); FunNode.nvalue.ldp = &Fun; nv_onattr(&FunNode,NV_NOFREE|NV_LDOUBLE|NV_RDONLY); cp[flag] = c; @@ -323,8 +323,8 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl np = L_ARGNOD; else { - int offset = staktell(); - char *saveptr = stakfreeze(0); + int offset = stktell(sh.stk); + char *saveptr = stkfreeze(sh.stk,0); Dt_t *root = (lvalue->emode&ARITH_COMP)?sh.var_base:sh.var_tree; *str = c; cp = str; @@ -369,10 +369,10 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl lvalue->value = (char*)*ptr; lvalue->flag = str-lvalue->value; } - if(saveptr != stakptr(0)) - stakset(saveptr,offset); + if(saveptr != stkptr(sh.stk,0)) + stkset(sh.stk,saveptr,offset); else - stakseek(offset); + stkseek(sh.stk,offset); } *str = c; if(!np && lvalue->value) diff --git a/src/cmd/ksh93/sh/array.c b/src/cmd/ksh93/sh/array.c index 7aec0a937849..ebd848b21e34 100644 --- a/src/cmd/ksh93/sh/array.c +++ b/src/cmd/ksh93/sh/array.c @@ -27,7 +27,6 @@ #include "shopt.h" #include "defs.h" -#include #include "name.h" #define NUMSIZE 11 @@ -881,11 +880,9 @@ static struct index_array *array_grow(Namval_t *np, struct index_array *arp,int int nv_atypeindex(Namval_t *np, const char *tname) { Namval_t *tp; - int offset = staktell(); size_t n = strlen(tname)-1; - sfprintf(stkstd,"%s.%.*s%c",NV_CLASS,n,tname,0); - tp = nv_open(stakptr(offset), sh.var_tree, NV_NOADD|NV_VARNAME|NV_NOFAIL); - stakseek(offset); + sfprintf(sh.strbuf,"%s.%.*s",NV_CLASS,n,tname); + tp = nv_open(sfstruse(sh.strbuf), sh.var_tree, NV_NOADD|NV_VARNAME|NV_NOFAIL); if(tp) { struct index_array *ap = (struct index_array*)nv_arrayptr(np); @@ -1504,9 +1501,9 @@ char *nv_endsubscript(Namval_t *np, char *cp, int mode) if(quoted) { /* strip escape characters */ - count = staktell(); - stakwrite(sp,1+cp-sp); - sh_trim(sp=stakptr(count)); + count = stktell(sh.stk); + sfwrite(sh.stk,sp,1+cp-sp); + sh_trim(sp=stkptr(sh.stk,count)); } if(mode && np) { @@ -1541,7 +1538,7 @@ char *nv_endsubscript(Namval_t *np, char *cp, int mode) nv_putsub(np, sp, ((mode&NV_ADD)?ARRAY_ADD:0)|(cp[1]&&(mode&NV_ADD)?ARRAY_FILL:mode&ARRAY_FILL)); } if(quoted) - stakseek(count); + stkseek(sh.stk,count); *cp++ = c; return cp; } diff --git a/src/cmd/ksh93/sh/expand.c b/src/cmd/ksh93/sh/expand.c index 610c4bb7e2cf..8669aaf14148 100644 --- a/src/cmd/ksh93/sh/expand.c +++ b/src/cmd/ksh93/sh/expand.c @@ -29,7 +29,6 @@ #include "test.h" #include #include -#include #include #include "io.h" #include "path.h" @@ -123,9 +122,9 @@ static int scantree(Dt_t *tree, const char *pattern, struct argnod **arghead) { if(strmatch(cp=nv_name(np),pattern)) { - (void)stakseek(ARGVAL); - stakputs(cp); - ap = (struct argnod*)stakfreeze(1); + (void)stkseek(sh.stk,ARGVAL); + sfputr(sh.stk,cp,-1); + ap = (struct argnod*)stkfreeze(sh.stk,1); ap->argbegin = NULL; ap->argchn.ap = *arghead; ap->argflag = ARG_RAW|ARG_MAKE; @@ -343,13 +342,13 @@ int path_generate(struct argnod *todo, struct argnod **arghead) brace = *cp; *cp = 0; sh_sigcheck(); - ap = (struct argnod*)stakseek(ARGVAL); + ap = (struct argnod*)stkseek(sh.stk,ARGVAL); ap->argflag = ARG_RAW; ap->argchn.ap = todo; - stakputs(apin->argval); - stakputs(pat); - stakputs(rescan); - todo = ap = (struct argnod*)stakfreeze(1); + sfputr(sh.stk,apin->argval,-1); + sfputr(sh.stk,pat,-1); + sfputr(sh.stk,rescan,-1); + todo = ap = (struct argnod*)stkfreeze(sh.stk,1); if(brace == '}') break; if(!range) diff --git a/src/cmd/ksh93/sh/fault.c b/src/cmd/ksh93/sh/fault.c index 3090eee9d4f2..54c267bbfb77 100644 --- a/src/cmd/ksh93/sh/fault.c +++ b/src/cmd/ksh93/sh/fault.c @@ -494,8 +494,8 @@ int sh_trap(const char *trap, int mode) int was_verbose = sh_isstate(SH_VERBOSE); char was_no_trapdontexec = !sh.st.trapdontexec; char save_chldexitsig = sh.chldexitsig; - int staktop = staktell(); - char *savptr = stakfreeze(0); + int staktop = stktell(sh.stk); + char *savptr = stkfreeze(sh.stk,0); struct checkpt buff; Fcin_t savefc; fcsave(&savefc); @@ -541,7 +541,7 @@ int sh_trap(const char *trap, int mode) savxit_return = sh.exitval; if(jmpval!=SH_JMPEXIT && jmpval!=SH_JMPFUN) sh.exitval=savxit; - stakset(savptr,staktop); + stkset(sh.stk,savptr,staktop); fcrestore(&savefc); if(was_history) sh_onstate(SH_HISTORY); diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 38638cf9f726..fbd3e207b5ba 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -29,7 +29,6 @@ #include "shopt.h" #include "defs.h" -#include #include #include #include @@ -229,7 +228,7 @@ static int shlvl; static int rand_shift; /* - * Exception callback routine for stk(3)/stak(3) and sh_*alloc wrappers. + * Exception callback routine for stk(3) and sh_*alloc wrappers. */ static noreturn char *nomemory(size_t s) { @@ -1102,7 +1101,7 @@ static char *setdisc_any(Namval_t *np, const char *event, Namval_t *action, Namf { Namval_t *mp,fake; char *name; - int getname=0, off=staktell(); + int getname=0, off=stktell(sh.stk); fake.nvname = nv_name(np); if(!event) { @@ -1113,13 +1112,11 @@ static char *setdisc_any(Namval_t *np, const char *event, Namval_t *action, Namf } getname = 1; } - stakputs(fake.nvname); - stakputc('.'); - stakputs(event); - stakputc(0); - name = stakptr(off); + sfputr(sh.stk,fake.nvname,'.'); + sfputr(sh.stk,event,0); + name = stkptr(sh.stk,off); mp = nv_search(name, sh.fun_tree, action?NV_ADD:0); - stakseek(off); + stkseek(sh.stk,off); if(getname) return mp ? (char*)dtnext(sh.fun_tree,mp) : 0; if(action==np) @@ -1146,10 +1143,9 @@ static int newconf(const char *name, const char *path, const char *value) if(*(arg = path_pwd())=='/') chdir(arg); /* clear out old tracked alias */ - stakseek(0); - stakputs(nv_getval(PATHNOD)); - stakputc(0); - nv_putval(PATHNOD,stakseek(0),NV_RDONLY); + stkseek(sh.stk,0); + sfputr(sh.stk,nv_getval(PATHNOD),0); + nv_putval(PATHNOD,stkseek(sh.stk,0),NV_RDONLY); } return 1; } @@ -1336,7 +1332,7 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) sh_ioinit(); /* initialize signal handling */ sh_siginit(); - stakinstall(NULL,nomemory); + stkinstall(NULL,nomemory); /* set up memory for name-value pairs */ sh.init_context = nv_init(); /* initialize shell type */ @@ -1377,13 +1373,12 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit) sh.shpath = sh_strdup(cp); else if(cp = nv_getval(PWDNOD)) { - int offset = staktell(); - stakputs(cp); - stakputc('/'); - stakputs(argv[0]); - pathcanon(stakptr(offset),PATH_DOTDOT); - sh.shpath = sh_strdup(stakptr(offset)); - stakseek(offset); + int offset = stktell(sh.stk); + sfputr(sh.stk,cp,'/'); + sfputr(sh.stk,argv[0],-1); + pathcanon(stkptr(sh.stk,offset),PATH_DOTDOT); + sh.shpath = sh_strdup(stkptr(sh.stk,offset)); + stkseek(sh.stk,offset); } } } @@ -2119,7 +2114,7 @@ struct Mapchar static void put_trans(Namval_t* np,const char *val,int flags,Namfun_t *fp) { struct Mapchar *mp = (struct Mapchar*)fp; - int c,offset = staktell(),off=offset; + int c, offset = stktell(sh.stk), off = offset; if(val) { if(mp->lctype!=lctype) @@ -2132,14 +2127,14 @@ static void put_trans(Namval_t* np,const char *val,int flags,Namfun_t *fp) while(c = mbchar(val)) { c = towctrans(c,mp->trans); - stakseek(off+c); - stakseek(off); - c = mbconv(stakptr(off),c); + stkseek(sh.stk,off+c); + stkseek(sh.stk,off); + c = mbconv(stkptr(sh.stk,off),c); off += c; - stakseek(off); + stkseek(sh.stk,off); } - stakputc(0); - val = stakptr(offset); + sfputc(sh.stk,0); + val = stkptr(sh.stk,offset); } else { @@ -2147,12 +2142,12 @@ static void put_trans(Namval_t* np,const char *val,int flags,Namfun_t *fp) nv_disc(np,fp,NV_POP); if(!(fp->nofree&1)) free(fp); - stakseek(offset); + stkseek(sh.stk,offset); return; } skip: nv_putv(np,val,flags,fp); - stakseek(offset); + stkseek(sh.stk,offset); } static const Namdisc_t TRANS_disc = { sizeof(struct Mapchar), put_trans }; diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index 0ca173ecffcc..130b03682736 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -1082,23 +1082,22 @@ static char *io_usename(char *name, int *perm, int fno, int mode) name=path; name[fd] = 0; } - stakseek(1); - stakputs(name); - stakputc(0); - pathcanon(stakptr(1),PATH_PHYSICAL); - sp = ep = stakptr(1); + stkseek(sh.stk,1); + sfputr(sh.stk,name,0); + pathcanon(stkptr(sh.stk,1),PATH_PHYSICAL); + sp = ep = stkptr(sh.stk,1); if(ep = strrchr(sp,'/')) { - memmove(stakptr(0),sp,++ep-sp); - stakseek(ep-sp); + memmove(stkptr(sh.stk,0),sp,++ep-sp); + stkseek(sh.stk,ep-sp); } else { ep = sp; - stakseek(0); + stkseek(sh.stk,0); } - sfprintf(stkstd, ".<#%lld_%d{;.tmp", (Sflong_t)sh.current_pid, fno); - tname = stakfreeze(1); + sfprintf(sh.stk, ".<#%lld_%d{;.tmp", (Sflong_t)sh.current_pid, fno); + tname = stkfreeze(sh.stk,1); switch(mode) { case 1: @@ -1161,7 +1160,7 @@ int sh_redirect(struct ionod *iop, int flag) { if(iof&IOLSEEK) { - struct argnod *ap = (struct argnod*)stakalloc(ARGVAL+strlen(iop->ioname)); + struct argnod *ap = (struct argnod*)stkalloc(sh.stk,ARGVAL+strlen(iop->ioname)); memset(ap, 0, ARGVAL); ap->argflag = ARG_MAC; strcpy(ap->argval,iop->ioname); @@ -1173,7 +1172,7 @@ int sh_redirect(struct ionod *iop, int flag) if((iof&IOPROCSUB) && !(iof&IOLSEEK)) { /* handle process substitution passed to redirection */ - struct argnod *ap = (struct argnod*)stakalloc(ARGVAL+strlen(iop->ioname)); + struct argnod *ap = (struct argnod*)stkalloc(sh.stk,ARGVAL+strlen(iop->ioname)); memset(ap, 0, ARGVAL); if(iof&IOPUT) ap->argflag = ARG_RAW; @@ -2171,10 +2170,10 @@ static int io_prompt(Sfio_t *iop,int flag) { /* PS2 prompt. Save stack state to avoid corrupting command substitutions * in case we're executing a PS2.get discipline function at parse time. */ - int savestacktop = staktell(); - char *savestackptr = stakfreeze(0); + int savestacktop = stktell(sh.stk); + char *savestackptr = stkfreeze(sh.stk,0); cp = nv_getval(sh_scoped(PS2NOD)); - stakset(savestackptr, savestacktop); + stkset(sh.stk, savestackptr, savestacktop); break; } case 3: diff --git a/src/cmd/ksh93/sh/lex.c b/src/cmd/ksh93/sh/lex.c index dcef4cdfa0f6..a132497812d4 100644 --- a/src/cmd/ksh93/sh/lex.c +++ b/src/cmd/ksh93/sh/lex.c @@ -28,7 +28,6 @@ #include "shopt.h" #include #include -#include #include #include #include "defs.h" @@ -99,7 +98,7 @@ static void refvar(Lex_t *lp, int type) off = offset + (fcseek(0)-(type+1)) - fcfirst(); if(lp->lexd.kiaoff < offset) { - /* variable starts on stak, copy remainder */ + /* variable starts on stack, copy remainder */ if(off>offset) sfwrite(sh.stk,fcfirst()+type,off-offset); n = stktell(sh.stk)-lp->lexd.kiaoff; @@ -239,7 +238,7 @@ int sh_lex(Lex_t *lp) #endif /* - * Get the next word and put it on the top of the stak + * Get the next word and put it on the top of the stack * A pointer to the current word is stored in lp->arg * Returns the token type */ @@ -1680,7 +1679,7 @@ static int comsub(Lex_t *lp, int endtok) /* * here-doc nested in $(...) - * allocate ionode with delimiter filled in without disturbing stak + * allocate ionode with delimiter filled in without disturbing the stack */ static void nested_here(Lex_t *lp) { @@ -2049,10 +2048,10 @@ static char *fmttoken(Lex_t *lp, int sym) return (char*)sh_translate(e_endoffile); if(sym==NL) return (char*)sh_translate(e_newline); - stakfreeze(0); - stakputc(sym); + stkfreeze(sh.stk,0); + sfputc(sh.stk,sym); if(sym&SYMREP) - stakputc(sym); + sfputc(sh.stk,sym); else { switch(sym&SYMMASK) @@ -2073,16 +2072,16 @@ static char *fmttoken(Lex_t *lp, int sym) sym = '#'; break; case SYMSEMI: - if(*stakptr(0)=='<') - stakputc('>'); + if(*stkptr(sh.stk,0)=='<') + sfputc(sh.stk,'>'); sym = ';'; break; default: sym = 0; } - stakputc(sym); + sfputc(sh.stk,sym); } - return stakfreeze(1); + return stkfreeze(sh.stk,1); } /* @@ -2140,11 +2139,11 @@ static unsigned char *stack_shift(unsigned char *sp, unsigned char *dp) } /* - * Assumes that current word is unfrozen on top of the stak + * Assumes that current word is unfrozen on top of the stack * If is zero, gets rid of quoting and consider argument as string * and returns pointer to frozen arg * If mode==1, just replace $"..." strings with international strings - * The result is left on the stak + * The result is left on the stack * If mode==2, the each $"" string is printed on standard output */ static struct argnod *endword(int mode) diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index db2e4fabae48..d006d497593a 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -1506,7 +1506,7 @@ static int varsub(Mac_t *mp) v = nv_getval(np); mp->atmode = (v && mp->quoted && mode=='@'); } - if(savptr==stakptr(0)) + if(savptr==stkptr(sh.stk,0)) stkseek(stkp,offset); else stkset(stkp,savptr,offset); @@ -2669,38 +2669,38 @@ static int charlen(const char *string,int len) static void tilde_expand2(int offset) { char *cp = NULL; /* character pointer for tilde expansion result */ - char *stakp = stakptr(0); /* current stack object (&stakp[offset] is tilde string) */ - int curoff = staktell(); /* current offset of current stack object */ + char *stakp = stkptr(sh.stk,0); /* current stack object (&stakp[offset] is tilde string) */ + int curoff = stktell(sh.stk); /* current offset of current stack object */ static char block; /* for disallowing tilde expansion in .get/.set to change ${.sh.tilde} */ /* * Allow overriding tilde expansion with a .sh.tilde.set or .get discipline function. */ if(!block && SH_TILDENOD->nvfun && SH_TILDENOD->nvfun->disc) { - stakfreeze(1); /* terminate current stack object to avoid data corruption */ + stkfreeze(sh.stk,1); /* terminate current stack object to avoid data corruption */ block++; nv_putval(SH_TILDENOD, &stakp[offset], 0); cp = nv_getval(SH_TILDENOD); block--; if(cp[0]=='\0' || cp[0]=='~') cp = NULL; /* do not use empty or unexpanded result */ - stakset(stakp,curoff); /* restore stack to state on function entry */ + stkset(sh.stk,stakp,curoff); /* restore stack to state on function entry */ } /* * Perform default tilde expansion unless overridden. * Write the result to the stack, if any. */ - stakputc(0); + sfputc(sh.stk,0); if(!cp) cp = sh_tilde(&stakp[offset]); if(cp) { - stakseek(offset); + stkseek(sh.stk,offset); if(!(cp[0]=='/' && !cp[1] && fcpeek(0)=='/')) - stakputs(cp); /* for ~ == /, avoid ~/foo -> //foo */ + sfputr(sh.stk,cp,-1); /* for ~ == /, avoid ~/foo -> //foo */ } else - stakseek(curoff); + stkseek(sh.stk,curoff); } /* @@ -2743,18 +2743,18 @@ static char *sh_tilde(const char *string) if(fcgetc(c)=='/') { char *str; - int n=0,offset=staktell(); - stakputs(string); + int n=0,offset=stktell(sh.stk); + sfputr(sh.stk,string,-1); do { - stakputc(c); + sfputc(sh.stk,c); n++; } while (fcgetc(c) && c!='/'); - stakputc(0); + sfputc(sh.stk,0); if(c) fcseek(-1); - str = stakseek(offset); + str = stkseek(sh.stk,offset); Skip = n; if(logins_tree && (np=nv_search(str,logins_tree,0))) return nv_getval(np); diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index cf6eda22da99..38ae36655c91 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -28,7 +28,6 @@ #include "shopt.h" #include #include -#include #include #include #include "defs.h" @@ -97,7 +96,7 @@ static int sh_source(Sfio_t *iop, const char *file) } oid = error_info.id; nid = error_info.id = sh_strdup(file); - sh.st.filename = path_fullname(stakptr(PATH_OFFSET)); + sh.st.filename = path_fullname(stkptr(sh.stk,PATH_OFFSET)); REGRESS(source, "sh_source", ("%s", file)); exfile(iop, fd); error_info.id = oid; @@ -294,7 +293,7 @@ int sh_main(int ac, char *av[], Shinit_f userinit) if(fdin < 0 && !strchr(name,'/')) { if(path_absolute(name,NULL,0)) - sp = stakptr(PATH_OFFSET); + sp = stkptr(sh.stk,PATH_OFFSET); if(sp) { if((fdin=sh_open(sp,O_RDONLY,0))>=0) @@ -478,7 +477,7 @@ static void exfile(Sfio_t *iop,int fno) { sh.nextprompt = 1; sh_freeup(); - stakset(NULL,0); + stkset(sh.stk,NULL,0); sh_offstate(SH_STOPOK); sh_offstate(SH_ERREXIT); sh_offstate(SH_VERBOSE); @@ -642,8 +641,8 @@ static void chkmail(char *files) char *cp,*sp,*qp; char save; struct argnod *arglist=0; - int offset = staktell(); - char *savstak=stakptr(0); + int offset = stktell(sh.stk); + char *savstak = stkptr(sh.stk,0); struct stat statb; if(*(cp=files) == 0) return; @@ -710,7 +709,7 @@ static void chkmail(char *files) cp = sp; } while(save); - stakset(savstak,offset); + stkset(sh.stk,savstak,offset); } #undef EXECARGS @@ -758,8 +757,8 @@ static void fixargs(char **argv, int mode) command_len = st.command_length; return; } - stakseek(command_len+2); - buff = stakseek(0); + stkseek(sh.stk,command_len+2); + buff = stkseek(sh.stk,0); if(command_len==0) return; while((cp = *argv++) && offset < command_len) @@ -772,7 +771,7 @@ static void fixargs(char **argv, int mode) } offset--; memset(&buff[offset], 0, command_len - offset + 1); - un.pst_command = stakptr(0); + un.pst_command = stkptr(sh.stk,0); pstat(PSTAT_SETCMD,un,0,0,0); # elif _lib_setproctitle # define CMDMAXLEN 255 diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index 739a930adec7..71171068db6e 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -121,13 +121,13 @@ static char *getbuf(size_t len) void nv_outname(Sfio_t *out, char *name, int len) { const char *cp=name, *sp; - int c, offset = staktell(); + int c, offset = stktell(sh.stk); while(sp= strchr(cp,'[')) { if(len>0 && cp+len <= sp) break; sfwrite(out,cp,++sp-cp); - stakseek(offset); + stkseek(sh.stk,offset); while(c= *sp++) { if(c==']') @@ -137,10 +137,10 @@ void nv_outname(Sfio_t *out, char *name, int len) if(*sp=='[' || *sp==']' || *sp=='\\') c = *sp++; } - stakputc(c); + sfputc(sh.stk,c); } - stakputc(0); - sfputr(out,sh_fmtq(stakptr(offset)),-1); + sfputc(sh.stk,0); + sfputr(out,sh_fmtq(stkptr(sh.stk,offset)),-1); if(len>0) { sfputc(out,']'); @@ -155,7 +155,7 @@ void nv_outname(Sfio_t *out, char *name, int len) else sfputr(out,cp,-1); } - stakseek(offset); + stkseek(sh.stk,offset); } /* @@ -283,7 +283,7 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ) } else { - stakseek(0); + stkseek(sh.stk,0); if(*arg->argval==0 && arg->argchn.ap && !(arg->argflag&~(ARG_APPEND|ARG_QUOTED|ARG_MESSAGE|ARG_ARRAY))) { int flag = (NV_VARNAME|NV_ARRAY|NV_ASSIGN); @@ -316,9 +316,9 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ) { if(nv_isvtree(np) && !nv_isarray(np)) { - stakputc('.'); - stakputs(cp); - cp = stakfreeze(1); + sfputc(sh.stk,'.'); + sfputr(sh.stk,cp,-1); + cp = stkfreeze(sh.stk,1); } } } @@ -439,7 +439,7 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ) if(tp->tre.tretyp!=TLST && !tp->com.comnamp && tp->com.comset && tp->com.comset->argval[0]==0 && tp->com.comset->argchn.ap) { if(prefix || np) - cp = stakcopy(nv_name(np)); + cp = stkcopy(sh.stk,nv_name(np)); sh.prefix = cp; if(tp->com.comset->argval[1]=='[') { @@ -456,7 +456,7 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ) } if(*cp!='.' && *cp!='[' && strchr(cp,'[')) { - cp = stakcopy(nv_name(np)); + cp = stkcopy(sh.stk,nv_name(np)); if(!(arg->argflag&ARG_APPEND)) flag &= ~NV_ARRAY; if(sh.prefix_root = sh.first_root) @@ -496,12 +496,12 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ) skip: if(sub>0) { - sfprintf(stkstd,"%s[%d]",prefix?nv_name(np):cp,sub); - sh.prefix = stakfreeze(1); + sfprintf(sh.stk,"%s[%d]",prefix?nv_name(np):cp,sub); + sh.prefix = stkfreeze(sh.stk,1); nv_putsub(np,NULL,ARRAY_ADD|ARRAY_FILL|sub); } else if(prefix) - sh.prefix = stakcopy(nv_name(np)); + sh.prefix = stkcopy(sh.stk,nv_name(np)); else sh.prefix = cp; sh.last_table = 0; @@ -509,8 +509,8 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ) { if(*sh.prefix=='_' && sh.prefix[1]=='.' && nv_isref(L_ARGNOD)) { - sfprintf(stkstd,"%s%s",nv_name(L_ARGNOD->nvalue.nrp->np),sh.prefix+1); - sh.prefix = stkfreeze(stkstd,1); + sfprintf(sh.stk,"%s%s",nv_name(L_ARGNOD->nvalue.nrp->np),sh.prefix+1); + sh.prefix = stkfreeze(sh.stk,1); } memset(&nr,0,sizeof(nr)); memcpy(&node,L_ARGNOD,sizeof(node)); @@ -648,14 +648,14 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ) static void stak_subscript(const char *sub, int last) { int c; - stakputc('['); + sfputc(sh.stk,'['); while(c= *sub++) { if(c=='[' || c==']' || c=='\\') - stakputc('\\'); - stakputc(c); + sfputc(sh.stk,'\\'); + sfputc(sh.stk,c); } - stakputc(last); + sfputc(sh.stk,last); } /* @@ -663,31 +663,31 @@ static void stak_subscript(const char *sub, int last) */ static char *copystack(const char *prefix, const char *name, const char *sub) { - int last=0,offset = staktell(); + int last=0,offset = stktell(sh.stk); if(prefix) { - stakputs(prefix); - if(*stakptr(staktell()-1)=='.') - stakseek(staktell()-1); + sfputr(sh.stk,prefix,-1); + if(*stkptr(sh.stk,stktell(sh.stk)-1)=='.') + stkseek(sh.stk,stktell(sh.stk)-1); if(*name=='.' && name[1]=='[') - last = staktell()+2; + last = stktell(sh.stk)+2; if(*name!='[' && *name!='.' && *name!='=' && *name!='+') - stakputc('.'); + sfputc(sh.stk,'.'); if(*name=='.' && (name[1]=='=' || name[1]==0)) - stakputc('.'); + sfputc(sh.stk,'.'); } if(last) { - stakputs(name); - if(sh_checkid(stakptr(last),NULL)) - stakseek(staktell()-2); + sfputr(sh.stk,name,-1); + if(sh_checkid(stkptr(sh.stk,last),NULL)) + stkseek(sh.stk,stktell(sh.stk)-2); } if(sub) stak_subscript(sub,']'); if(!last) - stakputs(name); - stakputc(0); - return stakptr(offset); + sfputr(sh.stk,name,-1); + sfputc(sh.stk,0); + return stkptr(sh.stk,offset); } /* @@ -697,10 +697,10 @@ static char *copystack(const char *prefix, const char *name, const char *sub) static char *stack_extend(const char *cname, char *cp, int n) { char *name = (char*)cname; - int offset = name - stakptr(0); + int offset = name - stkptr(sh.stk,0); int m = cp-name; - stakseek(offset + strlen(name)+n+1); - name = stakptr(offset); + stkseek(sh.stk,offset + strlen(name)+n+1); + name = stkptr(sh.stk,offset); cp = name + m; m = strlen(cp)+1; while(m-->0) @@ -1310,7 +1310,7 @@ Namval_t *nv_open(const char *name, Dt_t *root, int flags) int append=0; const char *msg = e_varname; char *fname = 0; - int offset = staktell(); + int offset = stktell(sh.stk); Dt_t *funroot = NULL; #if NVCACHE struct Cache_entry *xp; @@ -1543,7 +1543,7 @@ Namval_t *nv_open(const char *name, Dt_t *root, int flags) UNREACHABLE(); } if(fun.nofree&1) - stakseek(offset); + stkseek(sh.stk,offset); return np; } @@ -1935,11 +1935,10 @@ void nv_putval(Namval_t *np, const char *string, int flags) append = strlen(up->cp); if(!tofree || size) { - offset = staktell(); - stakputs(up->cp); - stakputs(sp); - stakputc(0); - sp = stakptr(offset); + offset = stktell(sh.stk); + sfputr(sh.stk,up->cp,-1); + sfputr(sh.stk,sp,0); + sp = stkptr(sh.stk,offset); dot += append; append = 0; } @@ -1992,7 +1991,7 @@ void nv_putval(Namval_t *np, const char *string, int flags) ja_restore(); } if(flags&NV_APPEND) - stakseek(offset); + stkseek(sh.stk,offset); if(tofree && tofree!=Empty && tofree!=AltEmpty) free((void*)tofree); } @@ -2109,7 +2108,7 @@ static void ja_restore(void) static char *staknam(Namval_t *np, char *value) { char *p,*q; - q = stakalloc(strlen(nv_name(np))+(value?strlen(value):0)+2); + q = stkalloc(sh.stk,strlen(nv_name(np))+(value?strlen(value):0)+2); p=strcopy(q,nv_name(np)); if(value) { @@ -2188,12 +2187,12 @@ char **sh_envgen(void) data.attsize = 6; namec = nv_scan(sh.var_tree,nullscan,NULL,NV_EXPORT,NV_EXPORT); namec += sh.nenv; - er = (char**)stakalloc((namec+4)*sizeof(char*)); + er = (char**)stkalloc(sh.stk,(namec+4)*sizeof(char*)); data.argnam = (er+=2) + sh.nenv; if(sh.nenv) memcpy(er,environ,sh.nenv*sizeof(char*)); nv_scan(sh.var_tree, pushnam,&data,NV_EXPORT, NV_EXPORT); - *data.argnam = (char*)stakalloc(data.attsize); + *data.argnam = (char*)stkalloc(sh.stk,data.attsize); /* Export variable attributes into env var named by e_envmarker, unless POSIX mode is on */ cp = data.attval = strcopy(*data.argnam,e_envmarker); if(!sh_isoption(SH_POSIX)) @@ -2481,9 +2480,9 @@ void _nv_unset(Namval_t *np,int flags) } if(slp->slptr) { - Stak_t *sp = slp->slptr; + Stk_t *sp = slp->slptr; slp->slptr = NULL; - stakdelete(sp); + stkclose(sp); } free(np->nvalue.ip); np->nvalue.ip = 0; diff --git a/src/cmd/ksh93/sh/nvdisc.c b/src/cmd/ksh93/sh/nvdisc.c index 0a65a52eccc2..c1b49ca6e5cb 100644 --- a/src/cmd/ksh93/sh/nvdisc.c +++ b/src/cmd/ksh93/sh/nvdisc.c @@ -425,7 +425,7 @@ static char* lookup(Namval_t *np, int type, Sfdouble_t *dp,Namfun_t *handle) *dp = nv_getnum(SH_VALNOD); } else if(cp = nv_getval(SH_VALNOD)) - cp = stkcopy(stkstd,cp); + cp = stkcopy(sh.stk,cp); _nv_unset(SH_VALNOD,NV_RDONLY); if(!nv_isnull(&node)) { @@ -1029,7 +1029,7 @@ Namval_t *nv_search(const char *name, Dt_t *root, int mode) */ Namval_t *nv_bfsearch(const char *name, Dt_t *root, Namval_t **var, char **last) { - int c,offset = staktell(); + int c,offset = stktell(sh.stk); char *sp, *cp=0; Namval_t *np, *nq; char *dname=0; @@ -1059,15 +1059,14 @@ Namval_t *nv_bfsearch(const char *name, Dt_t *root, Namval_t **var, char **last) } if(!cp) return var ? nv_search(name,root,0) : 0; - stakputs(name); - stakputc(0); + sfputr(sh.stk,name,0); dname = cp+1; - cp = stakptr(offset) + (cp-name); + cp = stkptr(sh.stk,offset) + (cp-name); if(last) *last = cp; c = *cp; *cp = 0; - nq=nv_open(stakptr(offset),0,NV_VARNAME|NV_NOADD|NV_NOFAIL); + nq=nv_open(stkptr(sh.stk,offset),0,NV_VARNAME|NV_NOADD|NV_NOFAIL); *cp = c; if(!nq) { @@ -1082,7 +1081,7 @@ Namval_t *nv_bfsearch(const char *name, Dt_t *root, Namval_t **var, char **last) *var = nq; if(c=='[') nv_endsubscript(nq, cp,NV_NOADD); - stakseek(offset); + stkseek(sh.stk,offset); #if SHOPT_NAMESPACE if(nv_istable(nq)) { @@ -1090,12 +1089,11 @@ Namval_t *nv_bfsearch(const char *name, Dt_t *root, Namval_t **var, char **last) if(last==0) return nv_search(name,root,0); sh.namespace = 0; - stakputs(nv_name(nq)); + sfputr(sh.stk,nv_name(nq),-1); sh.namespace = nsp; - stakputs(dname-1); - stakputc(0); - np = nv_search(stakptr(offset),root,0); - stakseek(offset); + sfputr(sh.stk,dname-1,0); + np = nv_search(stkptr(sh.stk,offset),root,0); + stkseek(sh.stk,offset); return np; } #endif /* SHOPT_NAMESPACE */ @@ -1103,7 +1101,7 @@ Namval_t *nv_bfsearch(const char *name, Dt_t *root, Namval_t **var, char **last) nq = (Namval_t*)nq->nvenv; return (Namval_t*)nv_setdisc(nq,dname,nq,(Namfun_t*)nq); done: - stakseek(offset); + stkseek(sh.stk,offset); return np; } @@ -1121,22 +1119,21 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra) const char *name; char *cp; Namval_t *np, *nq=0; - int offset=staktell(); + int offset=stktell(sh.stk); if(extra==(void*)1) name = path; else if((name = path_basename(path))==path && bltin!=b_typeset && (nq=nv_bfsearch(name,sh.bltin_tree,NULL,&cp))) - path = name = stakptr(offset); + path = name = stkptr(sh.stk,offset); else if(sh.bltin_dir && extra!=(void*)1) { - stakputs(sh.bltin_dir); - stakputc('/'); - stakputs(name); - path = stakptr(offset); + sfputr(sh.stk,sh.bltin_dir,'/'); + sfputr(sh.stk,name,0); + path = stkptr(sh.stk,offset); } if(np = nv_search(name,sh.bltin_tree,0)) { /* exists without a path */ - stakseek(offset); + stkseek(sh.stk,offset); if(extra == (void*)1) { if(nv_isattr(np,BLT_SPC)) @@ -1174,7 +1171,7 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra) } if(!np && !(np = nv_search(path,sh.bltin_tree,bltin?NV_ADD:0))) return NULL; - stakseek(offset); + stkseek(sh.stk,offset); if(nv_isattr(np,BLT_SPC)) { if(extra) diff --git a/src/cmd/ksh93/sh/nvtree.c b/src/cmd/ksh93/sh/nvtree.c index 584bb5c9b0d0..9405a79f9fd1 100644 --- a/src/cmd/ksh93/sh/nvtree.c +++ b/src/cmd/ksh93/sh/nvtree.c @@ -941,8 +941,8 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) struct Walk walk; Sfio_t *outfile; Sfoff_t off = 0; - int len, savtop = staktell(); - char *savptr = stakfreeze(0); + int len, savtop = stktell(sh.stk); + char *savptr = stkfreeze(sh.stk,0); struct argnod *ap=0; struct argnod *arglist=0; char *name,*cp, **argv; @@ -952,7 +952,7 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) Namarr_t *arp = nv_arrayptr(np); Dt_t *save_tree = sh.var_tree; Namval_t *mp=0; - char *xpname = xp?stakcopy(nv_name(xp)):0; + char *xpname = xp?stkcopy(sh.stk,nv_name(xp)):0; if(xp) { sh.last_root = sh.prev_root; @@ -962,18 +962,15 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) sh.last_root = nv_dict(sh.last_table); if(sh.last_root) sh.var_tree = sh.last_root; - stakputs(nv_name(np)); + sfputr(sh.stk,nv_name(np),-1); if(arp && !(arp->nelem&ARRAY_SCAN) && (subscript = nv_getsub(np))) { mp = nv_opensub(np); - stakputc('['); - stakputs(subscript); - stakputc(']'); - stakputc('.'); + sfprintf(sh.stk,"[%s].",subscript); } - else if(*stakptr(staktell()-1) == ']') + else if(*stkptr(sh.stk,stktell(sh.stk)-1) == ']') mp = np; - name = stakfreeze(1); + name = stkfreeze(sh.stk,1); len = strlen(name); sh.last_root = 0; dir = nv_diropen(mp,name); @@ -993,12 +990,11 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) nq = nv_open(cp,walk.root,NV_VARNAME|NV_NOADD|NV_NOFAIL); if(!nq && (flags&NV_MOVE)) nq = nv_search(cp,walk.root,NV_NOADD); - stakseek(0); - stakputs(xpname); - stakputs(cp+len); - stakputc(0); + stkseek(sh.stk,0); + sfputr(sh.stk,xpname,-1); + sfputr(sh.stk,cp+len,0); sh.var_tree = save_tree; - mq = nv_open(stakptr(0),sh.prev_root,NV_VARNAME|NV_NOFAIL); + mq = nv_open(stkptr(sh.stk,0),sh.prev_root,NV_VARNAME|NV_NOFAIL); sh.var_tree = dp; if(nq && mq) { @@ -1008,9 +1004,9 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) } continue; } - stakseek(ARGVAL); - stakputs(cp); - ap = (struct argnod*)stakfreeze(1); + stkseek(sh.stk,ARGVAL); + sfputr(sh.stk,cp,-1); + ap = (struct argnod*)stkfreeze(sh.stk,1); ap->argflag = ARG_RAW; ap->argchn.ap = arglist; n++; @@ -1022,7 +1018,7 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) sh.var_tree = save_tree; return NULL; } - argv = (char**)stakalloc((n+1)*sizeof(char*)); + argv = (char**)stkalloc(sh.stk,(n+1)*sizeof(char*)); argv += n; *argv = 0; for(; ap; ap=ap->argchn.ap) @@ -1042,7 +1038,7 @@ static char *walk_tree(Namval_t *np, Namval_t *xp, int flags) walk.array = 0; walk.flags = flags; genvalue(argv,name,0,&walk); - stakset(savptr,savtop); + stkset(sh.stk,savptr,savtop); sh.var_tree = save_tree; if(!outfile) return NULL; diff --git a/src/cmd/ksh93/sh/nvtype.c b/src/cmd/ksh93/sh/nvtype.c index 22e742be6398..4373598203a9 100644 --- a/src/cmd/ksh93/sh/nvtype.c +++ b/src/cmd/ksh93/sh/nvtype.c @@ -346,7 +346,7 @@ static Namfun_t *clone_type(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp) int i; Namval_t *nq, *nr; size_t size = fp->dsize; - int save, offset=staktell(); + int save, offset=stktell(sh.stk); char *cp; Dt_t *root = sh.last_root; Namval_t *last_table = sh.last_table; @@ -395,16 +395,14 @@ static Namfun_t *clone_type(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp) cp = nv_name(np); else cp = nv_name(mp); - stakputs(cp); - stakputc('.'); - stakputs(nq->nvname); - stakputc(0); + sfputr(sh.stk,cp,'.'); + sfputr(sh.stk,nq->nvname,0); root = nv_dict(mp); save = fp->nofree; fp->nofree = 1; - nr = nv_create(stakptr(offset),root,NV_VARNAME|NV_NOADD,fp); + nr = nv_create(stkptr(sh.stk,offset),root,NV_VARNAME|NV_NOADD,fp); fp->nofree = save; - stakseek(offset); + stkseek(sh.stk,offset); if(nr) { if(nv_isattr(nq,NV_RDONLY) && (nq->nvalue.cp || nv_isattr(nq,NV_INTEGER))) @@ -594,15 +592,13 @@ static int typeinfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp) char *cp,**help,buffer[256]; Namtype_t *dp; Namval_t *np,*nq,*tp; - int n, i, offset=staktell(); + int n, i, offset=stktell(sh.stk); Sfio_t *sp; np = *(Namval_t**)(fp+1); - stakputs(NV_CLASS); - stakputc('.'); - stakputs(np->nvname); - stakputc(0); - np = nv_open(cp=stakptr(offset), sh.var_tree, NV_NOADD|NV_VARNAME); - stakseek(offset); + sfputr(sh.stk,NV_CLASS,'.'); + sfputr(sh.stk,np->nvname,0); + np = nv_open(cp=stkptr(sh.stk,offset), sh.var_tree, NV_NOADD|NV_VARNAME); + stkseek(sh.stk,offset); if(!np) return -1; if(!(dp=(Namtype_t*)nv_hasdisc(np,&type_disc))) @@ -680,19 +676,16 @@ static int typeinfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp) sfprintf(out,"}\n"); if(dp->ndisc>0) { - stakseek(offset); - stakputs(NV_CLASS); - stakputc('.'); - stakputs(np->nvname); - stakputc('.'); - n = staktell(); + stkseek(sh.stk,offset); + sfputr(sh.stk,NV_CLASS,'.'); + sfputr(sh.stk,np->nvname,'.'); + n = stktell(sh.stk); sfprintf(out,"[+?\b%s\b defines the following discipline functions:]{\n",np->nvname); for(i=0; i < dp->ndisc; i++) { - stakputs(dp->names[i]); - stakputc(0); + sfputr(sh.stk,dp->names[i],0); cp = 0; - if((nq = nv_search(stakptr(offset),sh.fun_tree,0)) && nq->nvalue.cp) + if((nq = nv_search(stkptr(sh.stk,offset),sh.fun_tree,0)) && nq->nvalue.cp) cp = nq->nvalue.rp->help; if(nq && nv_isattr(nq,NV_STATICF)) sfprintf(out,"\t[+%s?:static:%s]\n",dp->names[i],cp?cp:Empty); @@ -700,11 +693,11 @@ static int typeinfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp) sfprintf(out,"\t[+%s?%s]\n",dp->names[i],cp?cp:Empty); if(cp) sfputc(out,'.'); - stakseek(n); + stkseek(sh.stk,n); } sfprintf(out,"}\n"); } - stakseek(offset); + stkseek(sh.stk,offset); sfclose(sp); return 0; } @@ -1186,13 +1179,11 @@ Namval_t *nv_mkinttype(char *name, size_t size, int sign, const char *help, Namd Namval_t *mp; Namfun_t *fp; Namdisc_t *dp; - int offset=staktell(); - stakputs(NV_CLASS); - stakputc('.'); - stakputs(name); - stakputc(0); - mp = nv_open(stakptr(offset), sh.var_tree, NV_VARNAME); - stakseek(offset); + int offset=stktell(sh.stk); + sfputr(sh.stk,NV_CLASS,'.'); + sfputr(sh.stk,name,0); + mp = nv_open(stkptr(sh.stk,offset), sh.var_tree, NV_VARNAME); + stkseek(sh.stk,offset); offset = size + sizeof(Namdisc_t); fp = sh_newof(NULL, Namfun_t, 1, offset); fp->type = mp; diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index 7b5c257a5a49..fadae7e4e5a9 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -68,7 +68,7 @@ static unsigned dcl_recursion; static int opt_get; -#define getnode(type) ((Shnode_t*)stakalloc(sizeof(struct type))) +#define getnode(type) ((Shnode_t*)stkalloc(sh.stk,sizeof(struct type))) #if SHOPT_KIA /* @@ -523,17 +523,17 @@ void sh_funstaks(struct slnod *slp,int flag) { /* * Since we're dealing with a linked list of stacks, slpold may be inside the allocated region - * pointed to by slpold->slptr, meaning the stakdelete() call may invalidate slpold as well as - * slpold->slptr. So if we do 'stakdelete(slpold->slptr); slpold->slptr = NULL' as may + * pointed to by slpold->slptr, meaning the stkclose() call may invalidate slpold as well as + * slpold->slptr. So if we do 'stkclose(slpold->slptr); slpold->slptr = NULL' as may * seem obvious, the assignment may be a use-after-free of slpold. Therefore, save the pointer * value and reset the pointer before closing/freeing the stack. */ - Stak_t *sp = slpold->slptr; + Stk_t *sp = slpold->slptr; slpold->slptr = NULL; - stakdelete(sp); + stkclose(sp); } else - staklink(slpold->slptr); + stklink(slpold->slptr); } } } @@ -668,7 +668,7 @@ static struct regnod* syncase(Lex_t *lexp,int esym) struct regnod *r; if(tok==esym) return NULL; - r = (struct regnod*)stakalloc(sizeof(struct regnod)); + r = (struct regnod*)stkalloc(sh.stk,sizeof(struct regnod)); r->regptr=0; r->regflag=0; if(tok==LPAREN) @@ -718,7 +718,6 @@ static Shnode_t *arithfor(Lex_t *lexp,Shnode_t *tf) int offset; struct argnod *argp; int n; - Stk_t *stkp = sh.stk; int argflag = lexp->arg->argflag; Fcin_t sav_input; /* save current input */ @@ -728,7 +727,7 @@ static Shnode_t *arithfor(Lex_t *lexp,Shnode_t *tf) for(n=0; ; n++) { int c; - argp = (struct argnod*)stkseek(stkp,ARGVAL); + argp = (struct argnod*)stkseek(sh.stk,ARGVAL); argp->argnxt.ap = 0; argp->argchn.cp = 0; argp->argflag = argflag; @@ -736,20 +735,20 @@ static Shnode_t *arithfor(Lex_t *lexp,Shnode_t *tf) break; /* copy up to ; onto the stack */ sh_lexskip(lexp,';',1,ST_NESTED); - offset = stktell(stkp)-1; + offset = stktell(sh.stk)-1; if((c=fcpeek(-1))!=';') break; /* remove trailing white space */ - while(offset>ARGVAL && ((c= *stkptr(stkp,offset-1)),isspace(c))) + while(offset>ARGVAL && ((c= *stkptr(sh.stk,offset-1)),isspace(c))) offset--; /* check for empty initialization expression */ if(offset==ARGVAL && n==0) continue; - stkseek(stkp,offset); + stkseek(sh.stk,offset); /* check for empty condition and treat as while((1)) */ if(offset==ARGVAL) - sfputc(stkp,'1'); - argp = (struct argnod*)stkfreeze(stkp,1); + sfputc(sh.stk,'1'); + argp = (struct argnod*)stkfreeze(sh.stk,1); t = getanode(lexp,argp); if(n==0) tf = makelist(lexp,TLST,t,tw); @@ -758,8 +757,8 @@ static Shnode_t *arithfor(Lex_t *lexp,Shnode_t *tf) } while((offset=fcpeek(0)) && isspace(offset)) fcseek(1); - stakputs(fcseek(0)); - argp = (struct argnod*)stakfreeze(1); + sfputr(sh.stk,fcseek(0),-1); + argp = (struct argnod*)stkfreeze(sh.stk,1); fcrestore(&sav_input); if(n<2) { @@ -791,7 +790,7 @@ static Shnode_t *funct(Lex_t *lexp) Shnode_t *t; int flag; struct slnod *volatile slp=0; - Stak_t *volatile savstak=0; + Stk_t *volatile savstak=0; Sfoff_t first, last; struct functnod *volatile fp; Sfio_t *iop; @@ -890,10 +889,10 @@ static Shnode_t *funct(Lex_t *lexp) jmpval = sigsetjmp(buff.buff,0); if(jmpval == 0) { - /* create a new stak frame to compile the command */ - savstak = stakcreate(STAK_SMALL); - savstak = stakinstall(savstak, 0); - slp = (struct slnod*)stakalloc(sizeof(struct slnod)+sizeof(struct functnod)); + /* create a new stack frame to compile the command */ + savstak = stkopen(STK_SMALL); + savstak = stkinstall(savstak, 0); + slp = (struct slnod*)stkalloc(sh.stk,sizeof(struct slnod)+sizeof(struct functnod)); slp->slchild = 0; slp->slnext = sh.st.staklist; sh.st.staklist = 0; @@ -908,10 +907,10 @@ static Shnode_t *funct(Lex_t *lexp) fp->functargs = 0; fp->functline = t->funct.functline; if(sh.st.filename) - fp->functnam = stakcopy(sh.st.filename); + fp->functnam = stkcopy(sh.stk,sh.st.filename); if(size) { - struct dolnod *dp = (struct dolnod*)stakalloc(size); + struct dolnod *dp = (struct dolnod*)stkalloc(sh.stk,size); char *cp, *sp, **argv, **old = ((struct dolnod*)t->funct.functargs->comarg)->dolval+1; argv = ((char**)(dp->dolval))+1; dp->dolnum = ((struct dolnod*)t->funct.functargs->comarg)->dolnum; @@ -927,7 +926,7 @@ static Shnode_t *funct(Lex_t *lexp) { /* functname() simple_command: copy current word token to current stack frame */ size_t sz = ARGVAL + strlen(lexp->arg->argval) + 1; /* include terminating 0 */ - struct argnod *ap = (struct argnod*)stakalloc(sz); + struct argnod *ap = (struct argnod*)stkalloc(sh.stk,sz); memcpy(ap,lexp->arg,sz); lexp->arg = ap; } @@ -940,7 +939,7 @@ static Shnode_t *funct(Lex_t *lexp) /* restore the old stack */ if(slp) { - slp->slptr = stakinstall(savstak,0); + slp->slptr = stkinstall(savstak,0); slp->slchild = sh.st.staklist; } #if SHOPT_KIA @@ -950,10 +949,10 @@ static Shnode_t *funct(Lex_t *lexp) { if(slp && slp->slptr) { - Stak_t *slptr_save = slp->slptr; + Stk_t *slptr_save = slp->slptr; sh.st.staklist = slp->slnext; slp->slptr = NULL; - stakdelete(slptr_save); + stkclose(slptr_save); } siglongjmp(*sh.jmplist,jmpval); } @@ -1009,7 +1008,6 @@ static struct argnod *assign(Lex_t *lexp, struct argnod *ap, int type) int n; Shnode_t *t, **tp; struct comnod *ac; - Stk_t *stkp = sh.stk; int array=0, index=0; Namval_t *np; lexp->assignlevel++; @@ -1055,16 +1053,16 @@ static struct argnod *assign(Lex_t *lexp, struct argnod *ap, int type) ac->comline = sh_getlineno(lexp); while(n==LPAREN) { - ar = (struct argnod*)stkseek(stkp,ARGVAL); + ar = (struct argnod*)stkseek(sh.stk,ARGVAL); ar->argflag= ARG_ASSIGN; - sfprintf(stkp,"[%d]=",index++); + sfprintf(sh.stk,"[%d]=",index++); if(aq=ac->comarg) { ac->comarg = aq->argnxt.ap; - sfprintf(stkp,"%s",aq->argval); + sfprintf(sh.stk,"%s",aq->argval); ar->argflag |= aq->argflag; } - ar = (struct argnod*)stkfreeze(stkp,1); + ar = (struct argnod*)stkfreeze(sh.stk,1); ar->argnxt.ap = 0; if(!aq) ar = assign(lexp,ar,0); @@ -1075,11 +1073,11 @@ static struct argnod *assign(Lex_t *lexp, struct argnod *ap, int type) continue; while((n = skipnl(lexp,0))==0) { - ar = (struct argnod*)stkseek(stkp,ARGVAL); + ar = (struct argnod*)stkseek(sh.stk,ARGVAL); ar->argflag= ARG_ASSIGN; - sfprintf(stkp,"[%d]=",index++); - stakputs(lexp->arg->argval); - ar = (struct argnod*)stkfreeze(stkp,1); + sfprintf(sh.stk,"[%d]=",index++); + sfputr(sh.stk,lexp->arg->argval,-1); + ar = (struct argnod*)stkfreeze(sh.stk,1); ar->argnxt.ap = 0; ar->argflag = lexp->arg->argflag; *settail = ar; @@ -1433,7 +1431,6 @@ static Shnode_t *simple(Lex_t *lexp,int flag, struct ionod *io) struct comnod *t; struct argnod *argp; int tok; - Stk_t *stkp = sh.stk; struct argnod **argtail; struct argnod **settail; int cmdarg = 0; @@ -1486,9 +1483,9 @@ static Shnode_t *simple(Lex_t *lexp,int flag, struct ionod *io) last = strchr(argp->argval,'='); if(last && (last[-1]==']'|| (last[-1]=='+' && last[-2]==']')) && (cp=strchr(argp->argval,'[')) && (cp < last) && cp[-1]!='.') last = cp; - stkseek(stkp,ARGVAL); - sfwrite(stkp,argp->argval,last-argp->argval); - ap=(struct argnod*)stkfreeze(stkp,1); + stkseek(sh.stk,ARGVAL); + sfwrite(sh.stk,argp->argval,last-argp->argval); + ap=(struct argnod*)stkfreeze(sh.stk,1); ap->argflag = ARG_RAW; ap->argchn.ap = 0; } @@ -1684,7 +1681,6 @@ static struct ionod *inout(Lex_t *lexp,struct ionod *lastio,int flag) { int iof = lexp->digits, token=lexp->token; struct ionod *iop; - Stk_t *stkp = sh.stk; char *iovname=0; int errout=0; /* return if a process substitution is found without a redirection */ @@ -1741,13 +1737,13 @@ static struct ionod *inout(Lex_t *lexp,struct ionod *lastio,int flag) return lastio; } lexp->digits=0; - iop=(struct ionod*) stkalloc(stkp,sizeof(struct ionod)); + iop=(struct ionod*) stkalloc(sh.stk,sizeof(struct ionod)); iop->iodelim = 0; if(token=sh_lex(lexp)) { if(token==RPAREN && (iof&IOLSEEK) && lexp->comsub) { - lexp->arg = (struct argnod*)stkalloc(stkp,sizeof(struct argnod)+3); + lexp->arg = (struct argnod*)stkalloc(sh.stk,sizeof(struct argnod)+3); strcpy(lexp->arg->argval,"CUR"); lexp->arg->argflag = ARG_RAW; iof |= IOARITH; @@ -1818,7 +1814,7 @@ static struct ionod *inout(Lex_t *lexp,struct ionod *lastio,int flag) if(errout) { /* redirect standard output to standard error */ - ioq = (struct ionod*)stkalloc(stkp,sizeof(struct ionod)); + ioq = (struct ionod*)stkalloc(sh.stk,sizeof(struct ionod)); memset(ioq,0,sizeof(*ioq)); ioq->ioname = "1"; ioq->iolst = 0; @@ -1879,7 +1875,7 @@ static struct argnod *qscan(struct comnod *ac,int argn) errormsg(SH_DICT,ERROR_warn(0),message,ac->comline); } /* leave space for an extra argument at the front */ - dp = (struct dolnod*)stakalloc((unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*)); + dp = (struct dolnod*)stkalloc(sh.stk,(unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) + argn*sizeof(char*)); cp = dp->dolval+ARG_SPARE; dp->dolnum = argn; dp->dolbot = ARG_SPARE; @@ -2056,22 +2052,21 @@ static Shnode_t *test_primary(Lex_t *lexp) */ unsigned long kiaentity(Lex_t *lexp,const char *name,int len,int type,int first,int last,unsigned long parent, int pkind, int width, const char *attr) { - Stk_t *stkp = sh.stk; Namval_t *np; - long offset = stktell(stkp); - sfputc(stkp,type); + long offset = stktell(sh.stk); + sfputc(sh.stk,type); if(len>0) - sfwrite(stkp,name,len); + sfwrite(sh.stk,name,len); else { if(type=='p') - sfputr(stkp,path_basename(name),0); + sfputr(sh.stk,path_basename(name),0); else - sfputr(stkp,name,0); + sfputr(sh.stk,name,0); } - sfputc(stkp,'\0'); /* terminate name while writing database output */ - np = nv_search(stakptr(offset),lexp->entity_tree,NV_ADD); - stkseek(stkp,offset); + sfputc(sh.stk,'\0'); /* terminate name while writing database output */ + np = nv_search(stkptr(sh.stk,offset),lexp->entity_tree,NV_ADD); + stkseek(sh.stk,offset); np->nvalue.i = pkind; nv_setsize(np,width); if(!nv_isattr(np,NV_TAGGED) && first>=0) diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index 2e2b05acfcb6..31a11a44f006 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -304,10 +304,10 @@ static char *dotpaths_lib(Pathcomp_t *pp, char *path) pcomp.len = 0; if(last) pcomp.len = last-path; - memcpy(save, stakptr(PATH_OFFSET+pcomp.len),sizeof(save)); + memcpy(save, stkptr(sh.stk,PATH_OFFSET+pcomp.len),sizeof(save)); if(checkdotpaths(NULL,NULL,&pcomp,PATH_OFFSET)) - return stakfreeze(1); - memcpy(stakptr(PATH_OFFSET+pcomp.len),save,sizeof(save)); + return stkfreeze(sh.stk,1); + memcpy(stkptr(sh.stk,PATH_OFFSET+pcomp.len),save,sizeof(save)); } return NULL; } @@ -344,10 +344,10 @@ static void checkdup(Pathcomp_t *pp) pp->flags |= flag; if(((pp->flags&(PATH_PATH|PATH_SKIP))==PATH_PATH)) { - int offset = staktell(); - stakputs(name); + int offset = stktell(sh.stk); + sfputr(sh.stk,name,0); checkdotpaths(first,0,pp,offset); - stakseek(offset); + stkseek(sh.stk,offset); } } @@ -359,7 +359,7 @@ static void checkdup(Pathcomp_t *pp) Pathcomp_t *path_nextcomp(Pathcomp_t *pp, const char *name, Pathcomp_t *last) { Pathcomp_t *ppnext; - stakseek(PATH_OFFSET); + stkseek(sh.stk,PATH_OFFSET); if(*name=='/') pp = 0; else @@ -381,16 +381,15 @@ Pathcomp_t *path_nextcomp(Pathcomp_t *pp, const char *name, Pathcomp_t *last) { if(*pp->name!='/') { - stakputs(path_pwd()); - if(*stakptr(staktell()-1)!='/') - stakputc('/'); + sfputr(sh.stk,path_pwd(),-1); + if(*stkptr(sh.stk,stktell(sh.stk)-1)!='/') + sfputc(sh.stk,'/'); } - stakwrite(pp->name,pp->len); + sfwrite(sh.stk,pp->name,pp->len); if(pp->name[pp->len-1]!='/') - stakputc('/'); + sfputc(sh.stk,'/'); } - stakputs(name); - stakputc(0); + sfputr(sh.stk,name,0); while(pp && pp!=last && (pp=pp->next)) { if(!(pp->flags&PATH_SKIP)) @@ -473,7 +472,7 @@ static int opentype(const char *name, Pathcomp_t *pp, int fun) continue; if(fun && (!pp || !(pp->flags&PATH_FPATH))) continue; - if((fd = sh_open(path_relative(stakptr(PATH_OFFSET)),O_RDONLY,0)) >= 0) + if((fd = sh_open(path_relative(stkptr(sh.stk,PATH_OFFSET)),O_RDONLY,0)) >= 0) { if(fstat(fd,&statb)<0 || S_ISDIR(statb.st_mode)) { @@ -543,7 +542,7 @@ static void funload(int fno, const char *name) static Dt_t *loopdetect_tree; struct Ufunction *rp,*rpfirst; int savestates = sh_getstate(), oldload=sh.funload, savelineno = sh.inlineno; - pname = path_fullname(stakptr(PATH_OFFSET)); + pname = path_fullname(stkptr(sh.stk,PATH_OFFSET)); if(sh.fpathdict && (rp = dtmatch(sh.fpathdict,pname))) { Dt_t *funtree = sh_subfuntree(1); @@ -594,7 +593,7 @@ static void funload(int fno, const char *name) #endif /* SHOPT_NAMESPACE */ np = nv_search(name,sh.fun_tree,0); if(!np || !np->nvalue.ip) - pname = stakcopy(sh.st.filename); + pname = stkcopy(sh.stk,sh.st.filename); else pname = 0; free(sh.st.filename); @@ -640,22 +639,21 @@ int path_search(const char *name,Pathcomp_t **oldpp, int flag) if(name && strchr(name,'/')) { char *pwd; - stakseek(PATH_OFFSET); - stakputs(name); - if(canexecute(stakptr(PATH_OFFSET),0)<0) + stkseek(sh.stk,PATH_OFFSET); + sfputr(sh.stk,name,0); + if(canexecute(stkptr(sh.stk,PATH_OFFSET),0)<0) { - *stakptr(PATH_OFFSET) = 0; + *stkptr(sh.stk,PATH_OFFSET) = 0; return 0; } if(*name=='/') return 1; - stakseek(PATH_OFFSET); + stkseek(sh.stk,PATH_OFFSET); pwd = path_pwd(); if(pwd[1]) /* if pwd=="/", avoid starting with "//" */ - stakputs(pwd); - stakputc('/'); - stakputs(name); - stakputc(0); + sfputr(sh.stk,pwd,-1); + sfputc(sh.stk,'/'); + sfputr(sh.stk,name,0); return 0; } if(!sh_isstate(SH_DEFPATH) && !sh.pathlist) @@ -666,11 +664,11 @@ int path_search(const char *name,Pathcomp_t **oldpp, int flag) if(!(flag & 1) && (np = path_gettrackedalias(name))) { pp = (Pathcomp_t*)np->nvalue.cp; - stakseek(PATH_OFFSET); + stkseek(sh.stk,PATH_OFFSET); path_nextcomp(pp,name,pp); if(oldpp) *oldpp = pp; - stakputc(0); + sfputc(sh.stk,0); return 0; } pp = path_absolute(name,oldpp?*oldpp:NULL,flag); @@ -679,7 +677,7 @@ int path_search(const char *name,Pathcomp_t **oldpp, int flag) if(!pp && (np=nv_search(name,sh.fun_tree,0))&&np->nvalue.ip) return 1; if(!pp) - *stakptr(PATH_OFFSET) = 0; + *stkptr(sh.stk,PATH_OFFSET) = 0; } if(flag==0 || !pp || (pp->flags&PATH_FPATH)) { @@ -695,7 +693,7 @@ int path_search(const char *name,Pathcomp_t **oldpp, int flag) funload(fno,name); return 1; } - *stakptr(PATH_OFFSET) = 0; + *stkptr(sh.stk,PATH_OFFSET) = 0; return 0; } else if(pp && *name!='/' && flag<3) @@ -747,22 +745,21 @@ Pathcomp_t *path_absolute(const char *name, Pathcomp_t *pp, int flag) int n; #endif /* Handle default path-bound builtins */ - if(!sh_isstate(SH_XARG) && *stakptr(PATH_OFFSET)=='/' && nv_search(stakptr(PATH_OFFSET),sh.bltin_tree,0)) + if(!sh_isstate(SH_XARG) && *stkptr(sh.stk,PATH_OFFSET)=='/' && nv_search(stkptr(sh.stk,PATH_OFFSET),sh.bltin_tree,0)) return oldpp; #if SHOPT_DYNAMIC /* Load builtins from dynamic libraries */ - n = staktell(); - stakputs("b_"); - stakputs(name); - stakputc(0); - if((addr = sh_getlib(stakptr(n), oldpp)) && - (np = sh_addbuiltin(stakptr(PATH_OFFSET),addr,NULL)) && + n = stktell(sh.stk); + sfputr(sh.stk,"b_",-1); + sfputr(sh.stk,name,0); + if((addr = sh_getlib(stkptr(sh.stk,n), oldpp)) && + (np = sh_addbuiltin(stkptr(sh.stk,PATH_OFFSET),addr,NULL)) && nv_isattr(np,NV_BLTINOPT)) { sh.bltin_dir = 0; return oldpp; } - stakseek(n); + stkseek(sh.stk,n); while(bp = oldpp->blib) { char *fp; @@ -779,26 +776,21 @@ Pathcomp_t *path_absolute(const char *name, Pathcomp_t *pp, int flag) fp = oldpp->bbuf; oldpp->blib = oldpp->bbuf = 0; } - n = staktell(); - stakputs("b_"); - stakputs(name); - stakputc(0); - m = staktell(); + n = stktell(sh.stk); + sfputr(sh.stk,"b_",-1); + sfputr(sh.stk,name,0); + m = stktell(sh.stk); sh.bltin_dir = oldpp->name; if(*bp!='/') - { - stakputs(oldpp->name); - stakputc('/'); - } - stakputs(bp); - stakputc(0); - if(cp = strrchr(stakptr(m),'/')) + sfputr(sh.stk,oldpp->name,'/'); + sfputr(sh.stk,bp,0); + if(cp = strrchr(stkptr(sh.stk,m),'/')) cp++; else - cp = stakptr(m); + cp = stkptr(sh.stk,m); if(!strcmp(cp,LIBCMD) && - (addr=(Shbltin_f)dlllook(NULL,stakptr(n))) && - (np = sh_addbuiltin(stakptr(PATH_OFFSET),addr,NULL)) && + (addr=(Shbltin_f)dlllook(NULL,stkptr(sh.stk,n))) && + (np = sh_addbuiltin(stkptr(sh.stk,PATH_OFFSET),addr,NULL)) && nv_isattr(np,NV_BLTINOPT)) { found: @@ -807,27 +799,27 @@ Pathcomp_t *path_absolute(const char *name, Pathcomp_t *pp, int flag) sh.bltin_dir = 0; return oldpp; } - if (dll = dllplugin(SH_ID, stakptr(m), NULL, SH_PLUGIN_VERSION, NULL, RTLD_LAZY, NULL, 0)) - sh_addlib(dll,stakptr(m),oldpp); + if (dll = dllplugin(SH_ID, stkptr(sh.stk,m), NULL, SH_PLUGIN_VERSION, NULL, RTLD_LAZY, NULL, 0)) + sh_addlib(dll,stkptr(sh.stk,m),oldpp); if(dll && - (addr=(Shbltin_f)dlllook(dll,stakptr(n))) && - (!(np = sh_addbuiltin(stakptr(PATH_OFFSET),NULL,NULL)) || funptr(np)!=addr) && - (np = sh_addbuiltin(stakptr(PATH_OFFSET),addr,NULL))) + (addr=(Shbltin_f)dlllook(dll,stkptr(sh.stk,n))) && + (!(np = sh_addbuiltin(stkptr(sh.stk,PATH_OFFSET),NULL,NULL)) || funptr(np)!=addr) && + (np = sh_addbuiltin(stkptr(sh.stk,PATH_OFFSET),addr,NULL))) { np->nvenv = dll; goto found; } - if(*stakptr(PATH_OFFSET)=='/' && nv_search(stakptr(PATH_OFFSET),sh.bltin_tree,0)) + if(*stkptr(sh.stk,PATH_OFFSET)=='/' && nv_search(stkptr(sh.stk,PATH_OFFSET),sh.bltin_tree,0)) goto found; if(fp) free(fp); - stakseek(n); + stkseek(sh.stk,n); } #endif /* SHOPT_DYNAMIC */ } sh.bltin_dir = 0; sh_stats(STAT_PATHS); - f = canexecute(stakptr(PATH_OFFSET),isfun); + f = canexecute(stkptr(sh.stk,PATH_OFFSET),isfun); if(isfun && f>=0 && (cp = strrchr(name,'.'))) { *cp = 0; @@ -850,16 +842,15 @@ Pathcomp_t *path_absolute(const char *name, Pathcomp_t *pp, int flag) } else if(f>=0 && (oldpp->flags & PATH_STD_DIR)) { - int n = staktell(); - stakputs("/bin/"); - stakputs(name); - stakputc(0); - np = nv_search(stakptr(n),sh.bltin_tree,0); - stakseek(n); + int n = stktell(sh.stk); + sfputr(sh.stk,"/bin/",-1); + sfputr(sh.stk,name,0); + np = nv_search(stkptr(sh.stk,n),sh.bltin_tree,0); + stkseek(sh.stk,n); if(np) { n = np->nvflag; - np = sh_addbuiltin(stakptr(PATH_OFFSET),funptr(np),nv_context(np)); + np = sh_addbuiltin(stkptr(sh.stk,PATH_OFFSET),funptr(np),nv_context(np)); np->nvflag = n; } } @@ -873,7 +864,7 @@ Pathcomp_t *path_absolute(const char *name, Pathcomp_t *pp, int flag) sh.path_err = (noexec?noexec:ENOENT); return NULL; } - stakputc(0); + sfputc(sh.stk,0); return oldpp; } @@ -909,15 +900,15 @@ static int canexecute(char *path, int isfun) char *cp; if(errno==ENOENT && (!(cp=strrchr(path,'.')) || strlen(cp)>4 || strchr(cp,'/'))) { - int offset = staktell()-1; - stakseek(offset); - stakputs(".bat"); - path = stakptr(PATH_OFFSET); + int offset = stktell(sh.stk)-1; + stkseek(sh.stk,offset); + sfputr(sh.stk,".bat",0); + path = stkptr(sh.stk,PATH_OFFSET); if(stat(path,&statb) < 0) { if(errno!=ENOENT) goto err; - memcpy(stakptr(offset),".sh",4); + memcpy(stkptr(sh.stk,offset),".sh",4); if(stat(path,&statb) < 0) goto err; } @@ -996,7 +987,7 @@ noreturn void path_exec(const char *arg0,char *argv[],struct argnod *local) if(libpath=pp) { pp = path_nextcomp(pp,arg0,0); - opath = stakfreeze(1)+PATH_OFFSET; + opath = stkfreeze(sh.stk,1)+PATH_OFFSET; } else opath = arg0; @@ -1062,10 +1053,10 @@ pid_t path_spawn(const char *opath,char **argv, char **envp, Pathcomp_t *libpath envp--; #if _lib_readlink /* save original pathname */ - stakseek(PATH_OFFSET); - pidsize = sfprintf(stkstd, "*%lld*", (Sflong_t)(spawn ? sh.current_pid : sh.current_ppid)); - stakputs(opath); - opath = stakfreeze(1)+PATH_OFFSET+pidsize; + stkseek(sh.stk,PATH_OFFSET); + pidsize = sfprintf(sh.stk, "*%lld*", (Sflong_t)(spawn ? sh.current_pid : sh.current_ppid)); + sfputr(sh.stk,opath,-1); + opath = stkfreeze(sh.stk,1)+PATH_OFFSET+pidsize; np = path_gettrackedalias(argv[0]); while(libpath && !libpath->lib) libpath=libpath->next; @@ -1074,9 +1065,9 @@ pid_t path_spawn(const char *opath,char **argv, char **envp, Pathcomp_t *libpath /* check for symlink and use symlink name */ char buff[PATH_MAX+1]; char save[PATH_MAX+1]; - stakseek(PATH_OFFSET); - stakputs(opath); - path = stakptr(PATH_OFFSET); + stkseek(sh.stk,PATH_OFFSET); + sfputr(sh.stk,opath,0); + path = stkptr(sh.stk,PATH_OFFSET); while((n=readlink(path,buff,PATH_MAX))>0) { buff[n] = 0; @@ -1090,10 +1081,9 @@ pid_t path_spawn(const char *opath,char **argv, char **envp, Pathcomp_t *libpath r = 0; n += (v+1-path); } - stakseek(n); - stakputs(buff); - stakputc(0); - path = stakptr(PATH_OFFSET); + stkseek(sh.stk,n); + sfputr(sh.stk,buff,0); + path = stkptr(sh.stk,PATH_OFFSET); if(v && buff[0]=='.' && buff[1]=='.') { pathcanon(path, 0); @@ -1106,7 +1096,7 @@ pid_t path_spawn(const char *opath,char **argv, char **envp, Pathcomp_t *libpath if(libenv = dotpaths_lib(libpath,path)) break; } - stakseek(0); + stkseek(sh.stk,0); } #endif if(libenv && (v = strchr(libenv,'='))) @@ -1116,13 +1106,13 @@ pid_t path_spawn(const char *opath,char **argv, char **envp, Pathcomp_t *libpath np = nv_open(libenv,sh.var_tree,0); *v = '='; s = nv_getval(np); - stakputs(libenv); + sfputr(sh.stk,libenv,-1); if(s) { - stakputc(':'); - stakputs(s); + sfputc(sh.stk,':'); + sfputr(sh.stk,s,-1); } - v = stakfreeze(1); + v = stkfreeze(sh.stk,1); r = 1; xp = envp + 1; while (s = *xp++) @@ -1142,7 +1132,7 @@ pid_t path_spawn(const char *opath,char **argv, char **envp, Pathcomp_t *libpath } } if(!opath) - opath = stakptr(PATH_OFFSET); + opath = stkptr(sh.stk,PATH_OFFSET); envp[0] = (char*)opath-(PATH_OFFSET+pidsize); envp[0][0] = '_'; envp[0][1] = '='; @@ -1421,16 +1411,16 @@ static noreturn void exscript(char *path,char *argv[],char **envp) static Pathcomp_t *path_addcomp(Pathcomp_t *first, Pathcomp_t *old,const char *name, int flag) { Pathcomp_t *pp, *oldpp; - int len, offset=staktell(); + int len, offset=stktell(sh.stk); if(!(flag&PATH_BFPATH)) { const char *cp = name; while(*cp && *cp!=':') - stakputc(*cp++); - len = staktell()-offset; - stakputc(0); - stakseek(offset); - name = (const char*)stakptr(offset); + sfputc(sh.stk,*cp++); + len = stktell(sh.stk)-offset; + sfputc(sh.stk,0); + stkseek(sh.stk,offset); + name = (const char*)stkptr(sh.stk,offset); } else len = strlen(name); @@ -1475,11 +1465,11 @@ static int checkdotpaths(Pathcomp_t *first, Pathcomp_t* old,Pathcomp_t *pp, int struct stat statb; int k,m,n,fd; char *sp,*cp,*ep; - stakseek(offset+pp->len); - if(pp->len==1 && *stakptr(offset)=='/') - stakseek(offset); - stakputs("/.paths"); - if((fd=open(stakptr(offset),O_RDONLY))>=0) + stkseek(sh.stk,offset+pp->len); + if(pp->len==1 && *stkptr(sh.stk,offset)=='/') + stkseek(sh.stk,offset); + sfputr(sh.stk,"/.paths",0); + if((fd=open(stkptr(sh.stk,offset),O_RDONLY))>=0) { fstat(fd,&statb); if(!S_ISREG(statb.st_mode)) @@ -1489,8 +1479,8 @@ static int checkdotpaths(Pathcomp_t *first, Pathcomp_t* old,Pathcomp_t *pp, int return 0; } n = statb.st_size; - stakseek(offset+pp->len+n+2); - sp = stakptr(offset+pp->len); + stkseek(sh.stk,offset+pp->len+n+2); + sp = stkptr(sh.stk,offset+pp->len); *sp++ = '/'; n=read(fd,cp=sp,n); sp[n] = 0; @@ -1515,10 +1505,10 @@ static int checkdotpaths(Pathcomp_t *first, Pathcomp_t* old,Pathcomp_t *pp, int { if(first) { - char *ptr = stakptr(offset+pp->len+1); + char *ptr = stkptr(sh.stk,offset+pp->len+1); if(ep) memmove(ptr,ep,strlen(ep)+1); - path_addcomp(first,old,stakptr(offset),PATH_FPATH|PATH_BFPATH); + path_addcomp(first,old,stkptr(sh.stk,offset),PATH_FPATH|PATH_BFPATH); } } else if(m==11 && strncmp(sp,"PLUGIN_LIB=",m)==0) @@ -1531,14 +1521,14 @@ static int checkdotpaths(Pathcomp_t *first, Pathcomp_t* old,Pathcomp_t *pp, int { pp->lib = (char*)sh_malloc(cp-sp+pp->len+2); memcpy(pp->lib,sp,m); - memcpy(&pp->lib[m],stakptr(offset),pp->len); + memcpy(&pp->lib[m],stkptr(sh.stk,offset),pp->len); pp->lib[k=m+pp->len] = '/'; strcpy(&pp->lib[k+1],ep); pathcanon(&pp->lib[m],0); if(!first) { - stakseek(0); - stakputs(pp->lib); + stkseek(sh.stk,0); + sfputr(sh.stk,pp->lib,-1); free(pp->lib); return 1; } @@ -1555,7 +1545,7 @@ Pathcomp_t *path_addpath(Pathcomp_t *first, const char *path,int type) { const char *cp; Pathcomp_t *old=0; - int offset = staktell(); + int offset = stktell(sh.stk); char *savptr; if(!path && type!=PATH_PATH) return first; @@ -1565,7 +1555,7 @@ Pathcomp_t *path_addpath(Pathcomp_t *first, const char *path,int type) first = 0; } if(offset) - savptr = stakfreeze(0); + savptr = stkfreeze(sh.stk,0); if(path) while(*(cp=path)) { if(*cp==':') @@ -1596,9 +1586,9 @@ Pathcomp_t *path_addpath(Pathcomp_t *first, const char *path,int type) path_delete(old); } if(offset) - stakset(savptr,offset); + stkset(sh.stk,savptr,offset); else - stakseek(0); + stkseek(sh.stk,0); return first; } @@ -1657,9 +1647,9 @@ void path_newdir(Pathcomp_t *first) if((pp->flags&(PATH_PATH|PATH_SKIP))==PATH_PATH) { /* try to insert .paths component */ - int offset = staktell(); - stakputs(pp->name); - stakseek(offset); + int offset = stktell(sh.stk); + sfputr(sh.stk,pp->name,0); + stkseek(sh.stk,offset); next = pp->next; pp->next = 0; checkdotpaths(first,NULL,pp,offset); @@ -1737,7 +1727,7 @@ static char *talias_get(Namval_t *np, Namfun_t *nvp) return NULL; sh.last_table = 0; path_nextcomp(pp,nv_name(np),pp); - ptr = stakfreeze(0); + ptr = stkfreeze(sh.stk,0); return ptr+PATH_OFFSET; } @@ -1779,7 +1769,7 @@ void path_settrackedalias(const char *name, Pathcomp_t *pp) pp->refcount++; nv_setattr(np,NV_TAGGED|NV_NOFREE); path_nextcomp(pp,name,pp); - sp = stakptr(PATH_OFFSET); + sp = stkptr(sh.stk,PATH_OFFSET); if(sp && lstat(sp,&statb)>=0 && S_ISLNK(statb.st_mode)) nv_setsize(np,statb.st_size+1); else diff --git a/src/cmd/ksh93/sh/shcomp.c b/src/cmd/ksh93/sh/shcomp.c index acbd3e658c98..fcf120e140d2 100644 --- a/src/cmd/ksh93/sh/shcomp.c +++ b/src/cmd/ksh93/sh/shcomp.c @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) error_info.id = script_id; while(1) { - stakset(NULL,0); + stkset(sh.stk,NULL,0); if(t = (Shnode_t*)sh_parse(in,0)) { if((t->tre.tretyp&(COMMSK|COMSCAN))==0 && t->com.comnamp && strcmp(nv_name((Namval_t*)t->com.comnamp),"alias")==0) diff --git a/src/cmd/ksh93/sh/streval.c b/src/cmd/ksh93/sh/streval.c index 792680686bf7..82db3b65d26c 100644 --- a/src/cmd/ksh93/sh/streval.c +++ b/src/cmd/ksh93/sh/streval.c @@ -31,7 +31,6 @@ #include "streval.h" #include #include -#include #include "FEATURE/externs" #ifndef ERROR_dictionary @@ -54,9 +53,9 @@ #define pow2size(x) ((x)<=2?2:(x)<=4?4:(x)<=8?8:(x)<=16?16:(x)<=32?32:64) #define round(x,size) (((x)+(size)-1)&~((size)-1)) -#define stakpush(v,val,type) ((((v)->offset=round(staktell(),pow2size(sizeof(type)))),\ - stakseek((v)->offset+sizeof(type)), \ - *((type*)stakptr((v)->offset)) = (val)),(v)->offset) +#define stkpush(stk,v,val,type) ((((v)->offset=round(stktell(stk),pow2size(sizeof(type)))),\ + stkseek(stk,(v)->offset+sizeof(type)), \ + *((type*)stkptr(stk,(v)->offset)) = (val)),(v)->offset) #define roundptr(ep,cp,type) (((unsigned char*)(ep))+round(cp-((unsigned char*)(ep)),pow2size(sizeof(type)))) struct vars /* vars stacked per invocation */ @@ -173,7 +172,7 @@ Sfdouble_t arith_exec(Arith_t *ep) if(ep->staksize < SMALL_STACK) sp = small_stack; else - sp = (Sfdouble_t*)stakalloc(ep->staksize*(sizeof(Sfdouble_t)+1)); + sp = (Sfdouble_t*)stkalloc(sh.stk,ep->staksize*(sizeof(Sfdouble_t)+1)); tp = (char*)(sp+ep->staksize); tp--,sp--; while(c = *cp++) @@ -602,7 +601,7 @@ static int expr(struct vars *vp,int precedence) common: if(!expr(vp,c)) return 0; - stakputc(op); + sfputc(sh.stk,op); break; default: vp->nextchr = vp->errchr; @@ -645,12 +644,12 @@ static int expr(struct vars *vp,int precedence) if(vp->staksize++>=vp->stakmaxsize) vp->stakmaxsize = vp->staksize; if(op==A_EQ || op==A_NEQ) - stakputc(A_ENUM); - stakputc(assignop.value?A_ASSIGNOP1:A_PUSHV); - stakpush(vp,lvalue.value,char*); + sfputc(sh.stk,A_ENUM); + sfputc(sh.stk,assignop.value?A_ASSIGNOP1:A_PUSHV); + stkpush(sh.stk,vp,lvalue.value,char*); if(lvalue.flag<0) lvalue.flag = 0; - stakpush(vp,lvalue.flag,short); + stkpush(sh.stk,vp,lvalue.flag,short); if(vp->nextchr==0) ERROR(vp,e_number); if(!(strval_precedence[op]&SEQPOINT)) @@ -686,12 +685,12 @@ static int expr(struct vars *vp,int precedence) vp->infun++; else { - stakputc(A_POP); + sfputc(sh.stk,A_POP); vp->staksize--; } if(!expr(vp,c)) { - stakseek(staktell()-1); + stkseek(sh.stk,stktell(sh.stk)-1); return 0; } lvalue.value = 0; @@ -716,9 +715,9 @@ static int expr(struct vars *vp,int precedence) userfun = T_BINARY; else if((int)lvalue.nargs&040) userfun = T_NOFLOAT; - stakputc(A_PUSHF); - stakpush(vp,fun,Math_f); - stakputc(1); + sfputc(sh.stk,A_PUSHF); + stkpush(sh.stk,vp,fun,Math_f); + sfputc(sh.stk,1); } else vp->infun = 0; @@ -736,7 +735,7 @@ static int expr(struct vars *vp,int precedence) ERROR(vp,e_argcount); if((vp->staksize+=nargs)>=vp->stakmaxsize) vp->stakmaxsize = vp->staksize+nargs; - stakputc(A_CALL1F+userfun+nargs+x); + sfputc(sh.stk,A_CALL1F+userfun+nargs+x); vp->staksize -= nargs; } vp->infun = infun; @@ -756,33 +755,33 @@ static int expr(struct vars *vp,int precedence) ERROR(vp,e_notlvalue); if(op==A_ASSIGN) { - stakputc(A_STORE); - stakpush(vp,lvalue.value,char*); - stakpush(vp,lvalue.flag,short); + sfputc(sh.stk,A_STORE); + stkpush(sh.stk,vp,lvalue.value,char*); + stkpush(sh.stk,vp,lvalue.flag,short); vp->staksize--; } else - stakputc(op); + sfputc(sh.stk,op); lvalue.value = 0; break; case A_QUEST: { int offset1,offset2; - stakputc(A_JMPZ); - offset1 = stakpush(vp,0,short); - stakputc(A_POP); + sfputc(sh.stk,A_JMPZ); + offset1 = stkpush(sh.stk,vp,0,short); + sfputc(sh.stk,A_POP); if(!expr(vp,1)) return 0; if(gettok(vp)!=A_COLON) ERROR(vp,e_questcolon); - stakputc(A_JMP); - offset2 = stakpush(vp,0,short); - *((short*)stakptr(offset1)) = staktell(); - stakputc(A_POP); + sfputc(sh.stk,A_JMP); + offset2 = stkpush(sh.stk,vp,0,short); + *((short*)stkptr(sh.stk,offset1)) = stktell(sh.stk); + sfputc(sh.stk,A_POP); if(!expr(vp,3)) return 0; - *((short*)stakptr(offset2)) = staktell(); + *((short*)stkptr(sh.stk,offset2)) = stktell(sh.stk); lvalue.value = 0; wasop = 0; break; @@ -801,14 +800,14 @@ static int expr(struct vars *vp,int precedence) op = A_JMPZ; else op = A_JMPNZ; - stakputc(op); - offset = stakpush(vp,0,short); - stakputc(A_POP); + sfputc(sh.stk,op); + offset = stkpush(sh.stk,vp,0,short); + sfputc(sh.stk,A_POP); if(!expr(vp,c)) return 0; - *((short*)stakptr(offset)) = staktell(); + *((short*)stkptr(sh.stk,offset)) = stktell(sh.stk); if(op!=A_QCOLON) - stakputc(A_NOTNOT); + sfputc(sh.stk,A_NOTNOT); lvalue.value = 0; wasop=0; break; @@ -820,7 +819,7 @@ static int expr(struct vars *vp,int precedence) case A_PLUS: case A_MINUS: case A_TIMES: case A_DIV: case A_EQ: case A_NEQ: case A_LT: case A_LE: case A_GT: case A_GE: case A_POW: - stakputc(op|T_BINARY); + sfputc(sh.stk,op|T_BINARY); vp->staksize--; break; case A_NOT: case A_TILDE: @@ -861,11 +860,11 @@ static int expr(struct vars *vp,int precedence) } if(op==A_DIG || op==A_LIT) { - stakputc(A_PUSHN); + sfputc(sh.stk,A_PUSHN); if(vp->staksize++>=vp->stakmaxsize) vp->stakmaxsize = vp->staksize; - stakpush(vp,d,Sfdouble_t); - stakputc(lvalue.isfloat); + stkpush(sh.stk,vp,d,Sfdouble_t); + sfputc(sh.stk,lvalue.isfloat); } /* check for function call */ if(lvalue.fun) @@ -879,9 +878,9 @@ static int expr(struct vars *vp,int precedence) vp->stakmaxsize = vp->staksize; if(assignop.flag<0) assignop.flag = 0; - stakputc(c&1?A_ASSIGNOP:A_STORE); - stakpush(vp,assignop.value,char*); - stakpush(vp,assignop.flag,short); + sfputc(sh.stk,c&1?A_ASSIGNOP:A_STORE); + stkpush(sh.stk,vp,assignop.value,char*); + stkpush(sh.stk,vp,assignop.flag,short); } } done: @@ -900,22 +899,22 @@ Arith_t *arith_compile(const char *string,char **last,Sfdouble_t(*fun)(const cha cur.emode = emode; cur.errmsg.value = 0; cur.errmsg.emode = emode; - stakseek(sizeof(Arith_t)); + stkseek(sh.stk,sizeof(Arith_t)); if(!expr(&cur,0) && cur.errmsg.value) { if(cur.errstr) string = cur.errstr; if((*fun)( &string , &cur.errmsg, MESSAGE, 0) < 0) { - stakseek(0); + stkseek(sh.stk,0); *last = (char*)Empty; return NULL; } cur.nextchr = cur.errchr; } - stakputc(0); - offset = staktell(); - ep = (Arith_t*)stakfreeze(0); + sfputc(sh.stk,0); + offset = stktell(sh.stk); + ep = (Arith_t*)stkfreeze(sh.stk,0); ep->expr = string; ep->elen = strlen(string); ep->code = (unsigned char*)(ep+1); @@ -946,12 +945,12 @@ Sfdouble_t arith_strval(const char *s, char **end, Sfdouble_t(*convert)(const ch Sfdouble_t d; char *sp=0; int offset; - if(offset=staktell()) - sp = stakfreeze(1); + if(offset=stktell(sh.stk)) + sp = stkfreeze(sh.stk,1); ep = arith_compile(s,end,convert,emode); ep->emode = emode; d = arith_exec(ep); - stakset(sp?sp:(char*)ep,offset); + stkset(sh.stk,sp?sp:(char*)ep,offset); return d; } diff --git a/src/cmd/ksh93/sh/string.c b/src/cmd/ksh93/sh/string.c index 0cfdb1492db8..f169d34157a7 100644 --- a/src/cmd/ksh93/sh/string.c +++ b/src/cmd/ksh93/sh/string.c @@ -24,7 +24,6 @@ #include #include #include "defs.h" -#include #include #include "shtable.h" #include "lexstates.h" @@ -184,7 +183,7 @@ char *sh_substitute(const char *string,const char *oldsp,char *newsp) const char *sp = string; const char *cp; const char *savesp = 0; - stakseek(0); + stkseek(sh.stk,0); if(*sp==0) return NULL; if(*(cp=oldsp) == 0) @@ -202,7 +201,7 @@ char *sh_substitute(const char *string,const char *oldsp,char *newsp) sp++; while(c-- > 0) #endif /* SHOPT_MULTIBYTE */ - stakputc(*sp++); + sfputc(sh.stk,*sp++); } if(*sp == 0) return NULL; @@ -223,10 +222,10 @@ char *sh_substitute(const char *string,const char *oldsp,char *newsp) found: /* copy new */ - stakputs(newsp); + sfputr(sh.stk,newsp,-1); /* copy rest of string */ - stakputs(sp); - return stakfreeze(1); + sfputr(sh.stk,sp,-1); + return stkfreeze(sh.stk,1); } /* @@ -274,29 +273,29 @@ static char *sh_fmtcsv(const char *string) int offset; if(!cp) return NULL; - offset = staktell(); + offset = stktell(sh.stk); while((c=mbchar(cp)),isaname(c)); if(c==0) return (char*)string; - stakputc('"'); - stakwrite(string,cp-string); + sfputc(sh.stk,'"'); + sfwrite(sh.stk,string,cp-string); if(c=='"') - stakputc('"'); + sfputc(sh.stk,'"'); string = cp; while(c=mbchar(cp)) { if(c=='"') { - stakwrite(string,cp-string); + sfwrite(sh.stk,string,cp-string); string = cp; - stakputc('"'); + sfputc(sh.stk,'"'); } } if(--cp>string) - stakwrite(string,cp-string); - stakputc('"'); - stakputc(0); - return stakptr(offset); + sfwrite(sh.stk,string,cp-string); + sfputc(sh.stk,'"'); + sfputc(sh.stk,0); + return stkptr(sh.stk,offset); } /* @@ -339,7 +338,7 @@ char *sh_fmtq(const char *string) if(!cp) return NULL; mbinit(); - offset = staktell(); + offset = stktell(sh.stk); state = ((c= mbchar(cp))==0); if(isaletter(c)) { @@ -353,7 +352,7 @@ char *sh_fmtq(const char *string) if(*cp=='=') cp++; c = cp - string; - stakwrite(string,c); + sfwrite(sh.stk,string,c); string = cp; c = mbchar(cp); } @@ -370,15 +369,15 @@ char *sh_fmtq(const char *string) if(state<2) { if(state==1) - stakputc('\''); + sfputc(sh.stk,'\''); if(c = --cp - string) - stakwrite(string,c); + sfwrite(sh.stk,string,c); if(state==1) - stakputc('\''); + sfputc(sh.stk,'\''); } else { - stakwrite("$'",2); + sfwrite(sh.stk,"$'",2); cp = string; while(op = cp, c= mbchar(cp)) { @@ -422,14 +421,14 @@ char *sh_fmtq(const char *string) if(!sh_isprint(c)) { /* Unicode hex code */ - sfprintf(staksp,"\\u[%x]",c); + sfprintf(sh.stk,"\\u[%x]",c); continue; } } else if(!isprint(c)) { quote_one_byte: - sfprintf(staksp, isxdigit(*cp) ? "\\x[%.2x]" : "\\x%.2x", c); + sfprintf(sh.stk, isxdigit(*cp) ? "\\x[%.2x]" : "\\x%.2x", c); continue; } state=0; @@ -437,16 +436,16 @@ char *sh_fmtq(const char *string) } if(state) { - stakputc('\\'); - stakputc(c); + sfputc(sh.stk,'\\'); + sfputc(sh.stk,c); } else - stakwrite(op, cp-op); + sfwrite(sh.stk,op, cp-op); } - stakputc('\''); + sfputc(sh.stk,'\''); } - stakputc(0); - return stakptr(offset); + sfputc(sh.stk,0); + return stkptr(sh.stk,offset); } /* @@ -473,7 +472,7 @@ char *sh_fmtqf(const char *string, int single, int fold) return sh_fmtcsv(cp); if (!cp || !*cp || !fold || fold && strlen(string) < fold) return sh_fmtq(cp); - offset = staktell(); + offset = stktell(sh.stk); single = single ? 1 : 3; c = mbchar(string); a = isaletter(c) ? '=' : 0; @@ -502,7 +501,7 @@ char *sh_fmtqf(const char *string, int single, int fold) q = 1; else if (c == a) { - stakwrite(bp, cp - bp); + sfwrite(sh.stk,bp, cp - bp); bp = cp; vp = cp + 1; a = 0; @@ -512,8 +511,8 @@ char *sh_fmtqf(const char *string, int single, int fold) } if (q & 2) { - stakputc('$'); - stakputc('\''); + sfputc(sh.stk,'$'); + sfputc(sh.stk,'\''); cp = bp; n = fold - 3; q = 1; @@ -562,10 +561,10 @@ char *sh_fmtqf(const char *string, int single, int fold) { if ((n -= 4) <= 0) { - stakwrite("'\\\n$'", 5); + sfwrite(sh.stk,"'\\\n$'", 5); n = fold - 7; } - sfprintf(staksp, "\\%03o", c); + sfprintf(sh.stk, "\\%03o", c); continue; } q = 0; @@ -575,26 +574,26 @@ char *sh_fmtqf(const char *string, int single, int fold) { if (!q) { - stakputc('\''); + sfputc(sh.stk,'\''); cp = bp; break; } - stakwrite("'\\\n$'", 5); + sfwrite(sh.stk,"'\\\n$'", 5); n = fold - 5; } if (q) - stakputc('\\'); + sfputc(sh.stk,'\\'); else q = 1; - stakputc(c); + sfputc(sh.stk,c); bp = cp; } if (!c) - stakputc('\''); + sfputc(sh.stk,'\''); } else if (q & 1) { - stakputc('\''); + sfputc(sh.stk,'\''); cp = bp; n = fold ? (fold - 2) : 0; while (c = mbchar(cp)) @@ -604,32 +603,32 @@ char *sh_fmtqf(const char *string, int single, int fold) else if (n && --n <= 0) { n = fold - 2; - stakwrite(bp, --cp - bp); + sfwrite(sh.stk,bp, --cp - bp); bp = cp; - stakwrite("'\\\n'", 4); + sfwrite(sh.stk,"'\\\n'", 4); } else if (n == 1 && *cp == '\'') { n = fold - 5; - stakwrite(bp, --cp - bp); + sfwrite(sh.stk,bp, --cp - bp); bp = cp; - stakwrite("'\\\n\\''", 6); + sfwrite(sh.stk,"'\\\n\\''", 6); } else if (c == '\'') { - stakwrite(bp, cp - bp - 1); + sfwrite(sh.stk,bp, cp - bp - 1); bp = cp; if (n && (n -= 4) <= 0) { n = fold - 5; - stakwrite("'\\\n\\''", 6); + sfwrite(sh.stk,"'\\\n\\''", 6); } else - stakwrite("'\\''", 4); + sfwrite(sh.stk,"'\\''", 4); } } - stakwrite(bp, cp - bp - 1); - stakputc('\''); + sfwrite(sh.stk,bp, cp - bp - 1); + sfputc(sh.stk,'\''); } else if (n = fold) { @@ -639,23 +638,23 @@ char *sh_fmtqf(const char *string, int single, int fold) if (--n <= 0) { n = fold; - stakwrite(bp, --cp - bp); + sfwrite(sh.stk,bp, --cp - bp); bp = cp; - stakwrite("\\\n", 2); + sfwrite(sh.stk,"\\\n", 2); } } - stakwrite(bp, cp - bp - 1); + sfwrite(sh.stk,bp, cp - bp - 1); } else - stakwrite(bp, cp - bp); + sfwrite(sh.stk,bp, cp - bp); if (c) { - stakputc('\\'); - stakputc('\n'); + sfputc(sh.stk,'\\'); + sfputc(sh.stk,'\n'); } } while (c); - stakputc(0); - return stakptr(offset); + sfputc(sh.stk,0); + return stkptr(sh.stk,offset); } /* diff --git a/src/cmd/ksh93/sh/trestore.c b/src/cmd/ksh93/sh/trestore.c index f02dbdddea49..455b87a6c2ae 100644 --- a/src/cmd/ksh93/sh/trestore.c +++ b/src/cmd/ksh93/sh/trestore.c @@ -128,15 +128,15 @@ static Shnode_t *r_tree(void) break; case TFUN: { - Stak_t *savstak; + Stk_t *savstak; struct slnod *slp; struct functnod *fp; t = getnode(functnod); t->funct.functloc = -1; t->funct.functline = sfgetu(infile); t->funct.functnam = r_string(); - savstak = stakcreate(STAK_SMALL); - savstak = stakinstall(savstak, 0); + savstak = stkopen(STK_SMALL); + savstak = stkinstall(savstak, 0); slp = (struct slnod*)stkalloc(sh.stk,sizeof(struct slnod)+sizeof(struct functnod)); slp->slchild = 0; slp->slnext = sh.st.staklist; @@ -149,7 +149,7 @@ static Shnode_t *r_tree(void) t->funct.functtre = r_tree(); t->funct.functstak = slp; t->funct.functargs = (struct comnod*)r_tree(); - slp->slptr = stakinstall(savstak,0); + slp->slptr = stkinstall(savstak,0); slp->slchild = sh.st.staklist; break; } diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index ac43f9396ae4..3c526a99dcd8 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -1411,7 +1411,7 @@ int sh_exec(const Shnode_t *t, int flags) sh_funstaks(slp->slchild,-1); if(slp->slptr) { - Stak_t *sp = slp->slptr; + Stk_t *sp = slp->slptr; slp->slptr = NULL; stkclose(sp); } @@ -2447,7 +2447,7 @@ int sh_exec(const Shnode_t *t, int flags) sh_funstaks(slp->slchild,-1); if(slp->slptr) { - Stak_t *sp = slp->slptr; + Stk_t *sp = slp->slptr; slp->slptr = NULL; stkclose(sp); } diff --git a/src/lib/libast/Mamfile b/src/lib/libast/Mamfile index e511656e619b..5704dfd9212b 100644 --- a/src/lib/libast/Mamfile +++ b/src/lib/libast/Mamfile @@ -2798,9 +2798,7 @@ make install prev include/regex.h prev include/error.h prev include/ast_dir.h - make include/stak.h implicit - prev include/stk.h - done include/stak.h + prev include/stk.h prev include/ls.h prev include/ast.h done misc/glob.c @@ -2913,7 +2911,7 @@ make install done tempnam.o generated make wordexp.o make comp/wordexp.c - prev include/stak.h + prev include/stk.h make comp/wordexp.h implicit prev ast_common.h done comp/wordexp.h @@ -4593,10 +4591,6 @@ make install prev man/spawnveg.3 exec - ${STDCMP} 2>/dev/null -s man/spawnveg.3 ${INSTALLROOT}/man/man3/spawnveg.3 || { ${STDMV} ${INSTALLROOT}/man/man3/spawnveg.3 ${INSTALLROOT}/man/man3/spawnveg.3.old 2>/dev/null || true; ${STDCP} man/spawnveg.3 ${INSTALLROOT}/man/man3/spawnveg.3 ;} done ${INSTALLROOT}/man/man3/spawnveg.3 generated - make ${INSTALLROOT}/man/man3/stak.3 - prev man/stak.3 - exec - ${STDCMP} 2>/dev/null -s man/stak.3 ${INSTALLROOT}/man/man3/stak.3 || { ${STDMV} ${INSTALLROOT}/man/man3/stak.3 ${INSTALLROOT}/man/man3/stak.3.old 2>/dev/null || true; ${STDCP} man/stak.3 ${INSTALLROOT}/man/man3/stak.3 ;} - done ${INSTALLROOT}/man/man3/stak.3 generated make ${INSTALLROOT}/man/man3/stk.3 prev man/stk.3 exec - ${STDCMP} 2>/dev/null -s man/stk.3 ${INSTALLROOT}/man/man3/stk.3 || { ${STDMV} ${INSTALLROOT}/man/man3/stk.3 ${INSTALLROOT}/man/man3/stk.3.old 2>/dev/null || true; ${STDCP} man/stk.3 ${INSTALLROOT}/man/man3/stk.3 ;} @@ -4983,12 +4977,6 @@ make install exec - then ${STDCP} include/stack.h ${INSTALLROOT}/include/ast/stack.h exec - fi done ${INSTALLROOT}/include/ast/stack.h generated - make ${INSTALLROOT}/include/ast/stak.h - prev include/stak.h - exec - if ! cmp -s include/stak.h ${INSTALLROOT}/include/ast/stak.h - exec - then ${STDCP} include/stak.h ${INSTALLROOT}/include/ast/stak.h - exec - fi - done ${INSTALLROOT}/include/ast/stak.h generated make ${INSTALLROOT}/include/ast/stk.h prev include/stk.h exec - if ! cmp -s include/stk.h ${INSTALLROOT}/include/ast/stk.h diff --git a/src/lib/libast/comp/wordexp.c b/src/lib/libast/comp/wordexp.c index 89d9d68f9b9c..4dc489b7c1d8 100644 --- a/src/lib/libast/comp/wordexp.c +++ b/src/lib/libast/comp/wordexp.c @@ -23,7 +23,7 @@ #include #include -#include +#include struct list { @@ -66,8 +66,8 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) int c,quoted=0,literal=0,ac=0; int offset; char *savebase,**av; - if(offset=staktell()) - savebase = stakfreeze(0); + if(offset=stktell(stkstd)) + savebase = stkfreeze(stkstd,0); if(flags&WRDE_REUSE) wordfree(wdarg); else if(!(flags&WRDE_APPEND)) @@ -76,12 +76,12 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) wdarg->we_wordc = 0; } if(flags&WRDE_UNDEF) - stakwrite("set -u\n",7); + sfwrite(stkstd,"set -u\n",7); if(!(flags&WRDE_SHOWERR)) - stakwrite("exec 2> /dev/null\n",18); - stakwrite("print -f \"%q\\n\" ",16); + sfwrite(stkstd,"exec 2> /dev/null\n",18); + sfwrite(stkstd,"print -f \"%q\\n\" ",16); if(*cp=='#') - stakputc('\\'); + sfputc(stkstd,'\\'); while(c = *cp++) { if(c=='\'' && !quoted) @@ -90,7 +90,7 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) { if(c=='\\' && (!quoted || strchr("\\\"`\n$",c))) { - stakputc('\\'); + sfputc(stkstd,'\\'); if(c= *cp) cp++; else @@ -106,7 +106,7 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) goto err; } /* only the shell can parse the rest */ - stakputs(cp-1); + sfputr(stkstd,cp-1,-1); break; } else if(!quoted && strchr("|&\n;<>"+ac,c)) @@ -117,15 +117,15 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) else if(c=='(') /* allow | and & inside pattern */ ac=2; } - stakputc(c); + sfputc(stkstd,c); } - stakputc(0); - if(!(iop = sfpopen(NULL,stakptr(0),"r"))) + sfputc(stkstd,0); + if(!(iop = sfpopen(NULL,stkptr(stkstd,0),"r"))) { c = WRDE_NOSHELL; goto err; } - stakseek(0); + stkseek(stkstd,0); ac = 0; while((c=sfgetc(iop)) != EOF) { @@ -136,7 +136,7 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) ac++; c = 0; } - stakputc(c); + sfputc(stkstd,c); } if(c=sfclose(iop)) { @@ -160,7 +160,7 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) } if(!av) return WRDE_NOSPACE; - c = staktell(); + c = stktell(stkstd); if(!(cp = (char*)malloc(sizeof(char*)+c))) { c=WRDE_NOSPACE; @@ -175,7 +175,7 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) wdarg->we_wordc += ac; if(flags&WRDE_DOOFFS) av += wdarg->we_offs; - memcpy(cp,stakptr(offset),c); + memcpy(cp,stkptr(stkstd,offset),c); while(ac-- > 0) { *av++ = cp; @@ -186,9 +186,9 @@ int wordexp(const char *string, wordexp_t *wdarg, int flags) c=0; err: if(offset) - stakset(savebase,offset); + stkset(stkstd,savebase,offset); else - stakseek(0); + stkseek(stkstd,0); return c; } diff --git a/src/lib/libast/include/stak.h b/src/lib/libast/include/stak.h deleted file mode 100644 index 836f6948dc80..000000000000 --- a/src/lib/libast/include/stak.h +++ /dev/null @@ -1,51 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* * -***********************************************************************/ -/* - * David Korn - * AT&T Research - * - * Interface definitions for a stack-like storage library - * - */ - -#ifndef _STAK_H -#define _STAK_H - -#include - -#define Stak_t Sfio_t -#define staksp stkstd -#define STAK_SMALL STK_SMALL - -#define stakptr(n) stkptr(stkstd,n) -#define staktell() stktell(stkstd) -#define stakputc(c) sfputc(stkstd,(c)) -#define stakwrite(b,n) sfwrite(stkstd,(b),(n)) -#define stakputs(s) (sfputr(stkstd,(s),0),--stkstd->_next) -#define stakseek(n) stkseek(stkstd,n) -#define stakcreate(n) stkopen(n) -#define stakinstall(s,f) stkinstall(s,f) -#define stakdelete(s) stkclose(s) -#define staklink(s) stklink(s) -#define stakalloc(n) stkalloc(stkstd,n) -#define stakcopy(s) stkcopy(stkstd,s) -#define stakset(c,n) stkset(stkstd,c,n) -#define stakfreeze(n) stkfreeze(stkstd,n) - -#endif diff --git a/src/lib/libast/man/stak.3 b/src/lib/libast/man/stak.3 deleted file mode 100644 index 390c66e30b40..000000000000 --- a/src/lib/libast/man/stak.3 +++ /dev/null @@ -1,185 +0,0 @@ -.fp 5 CW -.TH STAK 3 -.SH NAME -\fBstak\fR \- data stack storage library (obsolete: use \fBstk\fR instead) -.SH SYNOPSIS -.ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i -.PP -.nf -\f3 -#include - -Stak_t *stakcreate(int \fIflags\fP); -Stak_t *stakinstall(Stak_t *\fIstack\fP, char *(\fIoverflow\fP)(size_t)); -int stakdelete(Stak_t *\fIstack\fP); -unsigned int staklink(Stak_t *\fIstack\fP) - -char *stakalloc(unsigned \fIsize\fP); -char *stakcopy(const char *\fIstring\fP); -char *stakset(char *\fIaddress\fP, unsigned \fIoffset\fP); - -char *stakseek(unsigned \fIoffset\fP); -int stakputc(int \fIc\fP); -int stakputs(const char *\fIstring\fP); -int stakwrite(const char *\fIaddress\fP, unsigned \fIsize\fP); -int staktell(void); -char *stakptr(unsigned \fIoffset\fP); -char *stakfreeze(unsigned \fIextra\fP); -\fR -.fi -.SH DESCRIPTION -.PP -(This interface is obsolete; it is now simply a set of macros -that translate these calls into \f3stk\fP(3) and \f3sfio\fP(3) calls -using \f3stkstd\fP. -The following description should continue to apply to the old calls.) -.PP -\f3stak\fP is a package of routines designed to provide efficient -stack oriented dynamic storage. -A stack abstraction consists of an ordered list of contiguous -memory regions, called stack frames, that can hold objects of -arbitrary size. -A stack is represented by the type \f3Stak_t\fP -defined in header \f3\fP. -.PP -At any instant there is one active stack. -Variable size objects can be -added to the active stack -and programs can reference these objects directly with pointers. -.PP -In addition, the last object on the stack -(referred to here as the current object) -can be built incrementally. -The current object has an associated offset that determines its -current size. -While the current object is being built incrementally, -its location might -change so that it is necessary to reference the object with -relative offsets ranging from zero to the current offset of the object. -.PP -There is a preset initial active stack. -To use an additional stack, it is necessary to create it and to -install it as the active stack. -.PP -A stack is created with the \f3stakcreate\fP() function. -The \fIflags\fP argument is an options bitmask. -If the \f3STAK_SMALL\fP bit is set, the stack allocates memory in -small blocks, optimizing for memory usage at the expense of performance. -If successful, -\f3stakcreate\fP() returns a pointer to a stack whose reference -count is 1. -Otherwise, \f3stakcreate\fP() returns a null pointer. -.PP -The \f3staklink\fP() function increases the reference count for the -given \fIstack\fP and returns the increased count. -.PP -The \f3stakinstall\fP() function -makes the specified \fIstack\fP the active stack and returns a pointer -to the previous active stack. -When the \fIoverflow\fP argument is not null, -it specifies a function that will -be called whenever \f3malloc\fP(3) fails while trying to grow the -stack. -The \fIoverflow\fP function will be called with the size that was passed -to \f3malloc\fP(3). -The \fIoverflow\fP function can call \f3exit\fP(3), call \f3longjmp\fP(3) -or return. -If the \f3overflow\fP function returns, -it must return a pointer to a memory region of the given size. -The default action is to write an error to standard error and to -call \f3exit\fP(2) with a non-zero exit value. -When \fIstack\fP is a null pointer, -the active stack is not changed -but the \fIoverflow\fP function for the active stack can be changed -and a pointer to the active stack is returned. -.PP -The \f3stakdelete\fP() function decrements the reference count and -frees the memory associated with -the specified stack -when the reference count is zero. -The effect of subsequent references to objects -on the stack are undefined. -.PP -The -\f3stakalloc\fP() function returns an aligned pointer to space on the -active stack that can be used to hold any object of the given \fIsize\fP. -\f3stakalloc\fP() is similar to \f3malloc\fP(3) except that individual -items returned by \f3stakalloc\fP() can not be freed. -\f3stakalloc\fP() causes the offset of the current object to be set to -zero. -.PP -The -\f3stakcopy\fP() function copies the given string onto the stack -and returns a pointer to the \fIstring\fP on the stack. -\f3stakcopy\fP() causes the offset of the current object to be set to -zero. -.PP -The \f3stakset\fP() function finds the frame containing the given -\fIaddress\fP, frees all frames that were created after the one containing -the given \fIaddress\fP, and sets the current object to the given -\fIaddress\fP. -The top of the current object is set to \fIoffset\fP bytes from -current object. -If \fIaddress\fP is null, the stack is reset to the beginning. -If it is non-null, but is not the address of an object on the -stack, the program aborts and dumps core. -.PP -The remaining functions are used to build the current object incrementally. -An object that is built incrementally on the stack will -always occupy contiguous memory within a stack frame but -until \f3stakfreeze\fP() is called, -the location in memory for the object can change. -There is a current offset associated with the current object that -determines where subsequent operations apply. -Initially, this offset is zero, and the offset changes as a result -of the operations you specify. -.PP -The \f3stakseek\fP() function is used set the offset for the -current object. -The \fIoffset\fP argument to \f3stakseek\fP() specifies the new -offset for the current object. -The frame will be extended or moved -if \f3offset\fP causes the new current offset to extend beyond the -current frame. -\f3stakseek\fP() returns a pointer to the beginning of the current object. -.PP -The \f3staktell\fP() function gives the offset of the current object. -.PP -The \f3stakputc\fP() function adds a given character to the current object -on the stack. -The current offset is advanced by 1. -.PP -The \f3stakputs\fP() function appends the given \fIstring\fP onto the current -object in the stack and returns the length of the string. -The current offset is advanced by the length of the string. -.PP -The \f3stakwrite\fP() function appends the given \fIsize\fP byte memory -region starting at \fIaddress\fP onto the current -object in the stack and advances the current offset by \fIsize\fP. -The current offset is returned. -.PP -The \f3stakptr\fP() function converts the given \f3offset\fP -for the current object into a memory address on the stack. -This address is only valid until another stack operation is given. -The result is not defined if \fIoffset\fP exceeds the size of the current -object. -.PP -The \f3stakfreeze\fP() -function terminates the current object on the -stack and returns a pointer to the beginning of this object. -If \fIextra\fP is non-zero, \fIextra\fP bytes are added to the stack -before the current object is terminated. The first added byte will -contain zero and the contents of the remaining bytes are undefined. -.SH HISTORY -The -\f3stak\fP -interface was derived from similar routines in the KornShell code -that is used for building parse trees and carrying out expansions. -It provides an efficient mechanism for grouping dynamically allocated -objects so that they can be freed all at once rather than individually. -.SH AUTHOR - David Korn -.SH SEE ALSO -\f3exit(2)\fP -\f3longjmp(3)\fP -\f3malloc(3)\fP diff --git a/src/lib/libast/misc/glob.c b/src/lib/libast/misc/glob.c index f38c3097153a..97abda06bb8e 100644 --- a/src/lib/libast/misc/glob.c +++ b/src/lib/libast/misc/glob.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -59,7 +59,7 @@ typedef int (*GL_stat_f)(const char*, struct stat*); char* gl_nextpath; \ globlist_t* gl_rescan; \ globlist_t* gl_match; \ - Stak_t* gl_stak; \ + Stk_t* gl_stak; \ int re_flags; \ int re_first; \ regex_t* gl_ignore; \ @@ -158,7 +158,7 @@ static char* gl_nextdir(glob_t* gp, char* dir) { if (!(dir = gp->gl_nextpath)) - dir = gp->gl_nextpath = stakcopy(pathbin()); + dir = gp->gl_nextpath = stkcopy(stkstd,pathbin()); switch (*gp->gl_nextpath) { case 0: @@ -237,46 +237,46 @@ addmatch(glob_t* gp, const char* dir, const char* pat, const char* rescan, char* int offset; int type; - stakseek(MATCHPATH(gp)); + stkseek(stkstd,MATCHPATH(gp)); if (dir) { - stakputs(dir); - stakputc(gp->gl_delim); + sfputr(stkstd,dir,-1); + sfputc(stkstd,gp->gl_delim); } if (endslash) *endslash = 0; - stakputs(pat); + sfputr(stkstd,pat,-1); if (rescan) { - if ((*gp->gl_type)(gp, stakptr(MATCHPATH(gp)), 0) != GLOB_DIR) + if ((*gp->gl_type)(gp, stkptr(stkstd,MATCHPATH(gp)), 0) != GLOB_DIR) return; - stakputc(gp->gl_delim); - offset = staktell(); + sfputc(stkstd,gp->gl_delim); + offset = stktell(stkstd); /* if null, reserve room for . */ if (*rescan) - stakputs(rescan); + sfputr(stkstd,rescan,-1); else - stakputc(0); - stakputc(0); - rescan = stakptr(offset); - ap = (globlist_t*)stakfreeze(0); + sfputc(stkstd,0); + sfputc(stkstd,0); + rescan = stkptr(stkstd,offset); + ap = (globlist_t*)stkfreeze(stkstd,0); ap->gl_begin = (char*)rescan; ap->gl_next = gp->gl_rescan; gp->gl_rescan = ap; } else { - if (!endslash && (gp->gl_flags & GLOB_MARK) && (type = (*gp->gl_type)(gp, stakptr(MATCHPATH(gp)), 0))) + if (!endslash && (gp->gl_flags & GLOB_MARK) && (type = (*gp->gl_type)(gp, stkptr(stkstd,MATCHPATH(gp)), 0))) { if ((gp->gl_flags & GLOB_COMPLETE) && type != GLOB_EXE) { - stakseek(0); + stkseek(stkstd,0); return; } else if (type == GLOB_DIR && (gp->gl_flags & GLOB_MARK)) - stakputc(gp->gl_delim); + sfputc(stkstd,gp->gl_delim); } - ap = (globlist_t*)stakfreeze(1); + ap = (globlist_t*)stkfreeze(stkstd,1); ap->gl_next = gp->gl_match; gp->gl_match = ap; gp->gl_pathc++; @@ -598,7 +598,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t globlist_t* ap; char* pat; globlist_t* top; - Stak_t* oldstak; + Stk_t* oldstak; char** argv; char** av; size_t skip; @@ -690,14 +690,14 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t } if (gp->gl_flags & GLOB_STACK) gp->gl_stak = 0; - else if (!(gp->gl_stak = stakcreate(0))) + else if (!(gp->gl_stak = stkopen(0))) return GLOB_NOSPACE; if ((gp->gl_flags & GLOB_COMPLETE) && !gp->gl_nextdir) gp->gl_nextdir = gl_nextdir; } skip = gp->gl_pathc; if (gp->gl_stak) - oldstak = stakinstall(gp->gl_stak, 0); + oldstak = stkinstall(gp->gl_stak, 0); if (flags & GLOB_DOOFFS) extra += gp->gl_offs; if (gp->gl_suffix) @@ -761,7 +761,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t break; } } - top = ap = (globlist_t*)stakalloc((optlen ? 2 : 1) * strlen(pattern) + sizeof(globlist_t) + suflen + gp->gl_extra); + top = ap = (globlist_t*)stkalloc(stkstd,(optlen ? 2 : 1) * strlen(pattern) + sizeof(globlist_t) + suflen + gp->gl_extra); ap->gl_next = 0; ap->gl_flags = 0; ap->gl_begin = ap->gl_path + gp->gl_extra; @@ -799,7 +799,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t gp->gl_list = gp->gl_match; else { - argv = (char**)stakalloc((gp->gl_pathc + extra) * sizeof(char*)); + argv = (char**)stkalloc(stkstd,(gp->gl_pathc + extra) * sizeof(char*)); if (gp->gl_flags & GLOB_APPEND) { skip += --extra; @@ -832,7 +832,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t if (gp->gl_starstar > 1) gp->gl_flags &= ~GLOB_STARSTAR; if (gp->gl_stak) - stakinstall(oldstak, 0); + stkinstall(oldstak, 0); return gp->gl_error; } diff --git a/src/lib/libcmd/Mamfile b/src/lib/libcmd/Mamfile index c328a6ad6e18..5b183776665e 100644 --- a/src/lib/libcmd/Mamfile +++ b/src/lib/libcmd/Mamfile @@ -377,9 +377,7 @@ make install prev ${PACKAGE_ast_INCLUDE}/shcmd.h done cmdext.h dontcare generated prev ${PACKAGE_ast_INCLUDE}/shcmd.h - make ${PACKAGE_ast_INCLUDE}/stak.h implicit - prev ${PACKAGE_ast_INCLUDE}/stk.h - done ${PACKAGE_ast_INCLUDE}/stak.h + prev ${PACKAGE_ast_INCLUDE}/stk.h prev ${PACKAGE_ast_INCLUDE}/error.h prev ${PACKAGE_ast_INCLUDE}/ast.h done cmd.h diff --git a/src/lib/libcmd/chgrp.c b/src/lib/libcmd/chgrp.c index a7903b0396d2..4a567a817456 100644 --- a/src/lib/libcmd/chgrp.c +++ b/src/lib/libcmd/chgrp.c @@ -367,7 +367,7 @@ b_chgrp(int argc, char** argv, Shbltin_t* context) getids(s, &t, &key, options); if (!(m = (Map_t*)dtmatch(map, &key))) { - if (!(m = (Map_t*)stakalloc(sizeof(Map_t)))) + if (!(m = (Map_t*)stkalloc(stkstd, sizeof(Map_t)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory [id dictionary]"); UNREACHABLE(); diff --git a/src/lib/libcmd/cmd.h b/src/lib/libcmd/cmd.h index 7c1437a7790a..8b6d4cc7ce57 100644 --- a/src/lib/libcmd/cmd.h +++ b/src/lib/libcmd/cmd.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include #define cmdinit _cmd_init diff --git a/src/lib/libcmd/cut.c b/src/lib/libcmd/cut.c index 876d59c317cd..c1d288a868bf 100644 --- a/src/lib/libcmd/cut.c +++ b/src/lib/libcmd/cut.c @@ -134,7 +134,7 @@ cutinit(int mode, char* str, Delim_t* wdelim, Delim_t* ldelim, size_t reclen) char* cp = str; Cut_t* cut; - if (!(cut = (Cut_t*)stakalloc(sizeof(Cut_t) + strlen(cp) * sizeof(int)))) + if (!(cut = (Cut_t*)stkalloc(stkstd, sizeof(Cut_t) + strlen(cp) * sizeof(int)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory"); UNREACHABLE(); diff --git a/src/lib/libcmd/paste.c b/src/lib/libcmd/paste.c index bf70f4338061..614e92654eae 100644 --- a/src/lib/libcmd/paste.c +++ b/src/lib/libcmd/paste.c @@ -257,7 +257,7 @@ b_paste(int argc, char** argv, Shbltin_t* context) n = 1; if(!sflag) { - if (!(streams = (Sfio_t**)stakalloc(n*sizeof(Sfio_t*)))) + if (!(streams = (Sfio_t**)stkalloc(stkstd,n*sizeof(Sfio_t*)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory"); UNREACHABLE(); diff --git a/src/lib/libcmd/tail.c b/src/lib/libcmd/tail.c index 90868a9f93f7..2021dd5632a0 100644 --- a/src/lib/libcmd/tail.c +++ b/src/lib/libcmd/tail.c @@ -629,7 +629,7 @@ b_tail(int argc, char** argv, Shbltin_t* context) } if (flags & FOLLOW) { - if (!(fp = (Tail_t*)stakalloc(argc * sizeof(Tail_t)))) + if (!(fp = (Tail_t*)stkalloc(stkstd, argc * sizeof(Tail_t)))) { error(ERROR_SYSTEM|ERROR_PANIC, "out of memory"); UNREACHABLE(); diff --git a/src/lib/libcmd/tee.c b/src/lib/libcmd/tee.c index c9c3b398d0f2..6399e71f73e1 100644 --- a/src/lib/libcmd/tee.c +++ b/src/lib/libcmd/tee.c @@ -167,7 +167,7 @@ b_tee(int argc, char** argv, Shbltin_t* context) #endif if (argc > 0) { - if (tp = (Tee_t*)stakalloc(sizeof(Tee_t) + argc * sizeof(int))) + if (tp = (Tee_t*)stkalloc(stkstd, sizeof(Tee_t) + argc * sizeof(int))) { memset(&tp->disc, 0, sizeof(tp->disc)); tp->disc.writef = tee_write; diff --git a/src/lib/libcmd/uname.c b/src/lib/libcmd/uname.c index 314ebf7ea90e..880100d5eeb4 100644 --- a/src/lib/libcmd/uname.c +++ b/src/lib/libcmd/uname.c @@ -297,7 +297,7 @@ b_uname(int argc, char** argv, Shbltin_t* context) continue; case ':': { - char **new_argv = (char **)stakalloc((argc + 3) * sizeof(char*)); + char **new_argv = (char **)stkalloc(stkstd, (argc + 3) * sizeof(char*)); new_argv[0] = "command"; new_argv[1] = "-px"; for (n = 0; n <= argc; n++) diff --git a/src/lib/libcmd/wclib.c b/src/lib/libcmd/wclib.c index 87933db157ce..ae6c7d48b707 100644 --- a/src/lib/libcmd/wclib.c +++ b/src/lib/libcmd/wclib.c @@ -56,7 +56,7 @@ Wc_t* wc_init(int mode) int w; Wc_t* wp; - if (!(wp = (Wc_t*)stakalloc(sizeof(Wc_t)))) + if (!(wp = (Wc_t*)stkalloc(stkstd,sizeof(Wc_t)))) return NULL; if (!mbwide()) wp->mb = 0;