Lines Matching refs:shp

102 	Shell_t	*shp = (Shell_t*)handle;  in fifo_check()  local
106 unlink(shp->fifo); in fifo_check()
107 sh_done(shp,0); in fifo_check()
119 static bool iousepipe(Shell_t *shp) in iousepipe() argument
125 sh_iounpipe(shp); in iousepipe()
130 if(shp->comsub!=1) in iousepipe()
137 shp->fdstatus[subpipe[2]] = shp->fdstatus[1]; in iousepipe()
141 shp->fdstatus[1] = shp->fdstatus[subpipe[1]]&~IOCLEX; in iousepipe()
143 if(subdup=shp->subdup) for(i=0; i < 10; i++) in iousepipe()
149 shp->fdstatus[i] = shp->fdstatus[1]; in iousepipe()
155 void sh_iounpipe(Shell_t *shp) in sh_iounpipe() argument
162 if(shp->comsub>1) in sh_iounpipe()
171 shp->fdstatus[1] = shp->fdstatus[subpipe[2]]; in sh_iounpipe()
178 shp->fdstatus[n] = shp->fdstatus[1]; in sh_iounpipe()
181 shp->subdup = 0; in sh_iounpipe()
234 static int p_time(Shell_t *shp, Sfio_t *out, const char *format, clock_t *tm) in p_time() argument
236 int c,p,l,n,offset = stktell(shp->stk); in p_time()
239 Stk_t *stkp = shp->stk; in p_time()
279 d = (double)tm[n]/shp->gd->lim.clk_tck; in p_time()
302 static int p_comarg(Shell_t *shp,register struct comnod *com) in p_comarg() argument
305 int n = p_arg(shp,com->comset,ARG_ASSIGN); in p_comarg()
307 n+= p_arg(shp,com->comarg,0); in p_comarg()
311 Shbltin_t *bp = &shp->bltindata; in p_comarg()
331 static int sh_tclear(Shell_t *shp, register Shnode_t *t) in sh_tclear() argument
340 return(sh_tclear(shp,t->par.partre)); in sh_tclear()
342 return(p_comarg(shp,(struct comnod*)t)); in sh_tclear()
345 return(sh_tclear(shp,t->fork.forktre)); in sh_tclear()
347 n=sh_tclear(shp,t->if_.iftre); in sh_tclear()
348 n+=sh_tclear(shp,t->if_.thtre); in sh_tclear()
349 n+=sh_tclear(shp,t->if_.eltre); in sh_tclear()
353 n=sh_tclear(shp,(Shnode_t*)(t->wh.whinc)); in sh_tclear()
354 n+=sh_tclear(shp,t->wh.whtre); in sh_tclear()
355 n+=sh_tclear(shp,t->wh.dotre); in sh_tclear()
361 n=sh_tclear(shp,t->lst.lstlef); in sh_tclear()
362 return(n+sh_tclear(shp,t->lst.lstrit)); in sh_tclear()
364 return(p_arg(shp,t->ar.arexpr,ARG_ARITH)); in sh_tclear()
366 n=sh_tclear(shp,t->for_.fortre); in sh_tclear()
367 return(n+sh_tclear(shp,(Shnode_t*)t->for_.forlst)); in sh_tclear()
369 n=p_arg(shp,t->sw.swarg,0); in sh_tclear()
370 return(n+p_switch(shp,t->sw.swlst)); in sh_tclear()
372 n=sh_tclear(shp,t->funct.functtre); in sh_tclear()
373 return(n+sh_tclear(shp,(Shnode_t*)t->funct.functargs)); in sh_tclear()
376 return(sh_tclear(shp,t->lst.lstlef)); in sh_tclear()
379 n=p_arg(shp,&(t->lst.lstlef->arg),0); in sh_tclear()
381 n+=p_arg(shp,&(t->lst.lstrit->arg),0); in sh_tclear()
387 static int p_arg(Shell_t *shp,register struct argnod *arg,int flag) in p_arg() argument
394 sh_tclear(shp,(Shnode_t*)arg->argchn.ap); in p_arg()
396 sh_tclear(shp,((struct fornod*)arg->argchn.ap)->fortre); in p_arg()
402 static int p_switch(Shell_t *shp,register struct regnod *reg) in p_switch() argument
407 n+=p_arg(shp,reg->regptr,0); in p_switch()
408 n+=sh_tclear(shp,reg->regcom); in p_switch()
479 Shell_t *shp = sh_ptr(np); in put_level() local
500 if(sp = sh_getscope(shp,level,SEEK_SET)) in put_level()
502 sh_setscope(shp,sp); in put_level()
510 static struct Level *init_level(Shell_t *shp,int level) in init_level() argument
516 shp->last_root = nv_dict(DOTSHNOD); in init_level()
526 int sh_debug(Shell_t *shp, const char *trap, const char *name, const char *subscript, char *const a… in sh_debug() argument
528 Stk_t *stkp=shp->stk; in sh_debug()
536 if(shp->indebug) in sh_debug()
538 shp->indebug = 1; in sh_debug()
569 shp->st.lineno = error_info.line; in sh_debug()
570 level = shp->fn_depth+shp->dot_depth; in sh_debug()
571 shp->last_root = nv_dict(DOTSHNOD); in sh_debug()
573 init_level(shp,level); in sh_debug()
576 savst = shp->st; in sh_debug()
577 shp->st.trap[SH_DEBUGTRAP] = 0; in sh_debug()
578 n = sh_trap(shp,trap,0); in sh_debug()
580 shp->indebug = 0; in sh_debug()
581 if(shp->st.cmdname) in sh_debug()
582 error_info.id = shp->st.cmdname; in sh_debug()
583 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_debug()
584 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_debug()
585 shp->st = savst; in sh_debug()
627 static int set_instance(Shell_t *shp,Namval_t *nq, Namval_t *node, struct Namref *nr) in set_instance() argument
639 nr->root = shp->var_tree; in set_instance()
640 nr->table = shp->last_table; in set_instance()
642 if(!nr->table && shp->namespace) in set_instance()
643 nr->table = shp->namespace; in set_instance()
645 shp->instance = 1; in set_instance()
648 shp->instance = 0; in set_instance()
649 if(shp->var_tree!=shp->var_base && !nv_search((char*)nq,nr->root,HASH_BUCKET|HASH_NOSCOPE)) in set_instance()
652 nr->root = shp->namespace?nv_dict(shp->namespace):shp->var_base; in set_instance()
654 nr->root = shp->var_base; in set_instance()
705 static void *sh_coinit(Shell_t *shp,char **argv) in sh_coinit() argument
717 nv_open(name,shp->var_tree,NV_IDENT|NV_NOADD); in sh_coinit()
752 bool sh_coaddfile(Shell_t *shp, char *name) in sh_coaddfile() argument
754 Namval_t *np = dtmatch(shp->inpool,name); in sh_coaddfile()
757 np = (Namval_t*)stkalloc(shp->stk,sizeof(Dtlink_t)+sizeof(char*)); in sh_coaddfile()
759 (Namval_t*)dtinsert(shp->inpool,np); in sh_coaddfile()
760 shp->poolfiles++; in sh_coaddfile()
766 static int sh_coexec(Shell_t *shp,const Shnode_t *t, int filt) in sh_coexec() argument
768 struct cosh *csp = ((struct cosh*)shp->coshell); in sh_coexec()
771 int lineno,sig,trace = sh_isoption(shp,SH_XTRACE); in sh_coexec()
772 int verbose = sh_isoption(shp,SH_VERBOSE); in sh_coexec()
773 sh_offoption(shp,SH_XTRACE); in sh_coexec()
774 sh_offoption(shp,SH_VERBOSE); in sh_coexec()
775 if(!shp->strbuf2) in sh_coexec()
776 shp->strbuf2 = sfstropen(); in sh_coexec()
777 sfswap(shp->strbuf2,sfstdout); in sh_coexec()
778 sh_trap(shp,"typeset -p\nprint cd \"$PWD\"\nprint .sh.dollar=$$\nprint umask $(umask)",0); in sh_coexec()
779 for(sig=shp->st.trapmax;--sig>0;) in sh_coexec()
781 if((trap=shp->st.trapcom[sig]) && *trap==0) in sh_coexec()
792 if(shp->inpipe[2]>=20000) in sh_coexec()
793 …sfprintf(sfstdout,"command exec < /dev/tcp/%s/%d || print -u2 'cannot create pipe'\n",host,shp->in… in sh_coexec()
794 …sfprintf(sfstdout,"command exec > /dev/tcp/%s/%d || print -u2 'cannot create pipe'\n",host,shp->ou… in sh_coexec()
800 nv_scan(shp->fun_tree, print_fun, (void*)0,0, 0); in sh_coexec()
803 Dt_t *top = shp->var_tree; in sh_coexec()
804 sh_scope(shp,(struct argnod*)0,0); in sh_coexec()
805 shp->inpool = dtopen(&_Nvdisc,Dtset); in sh_coexec()
806 sh_exec(shp,t,filt==1||filt==2?SH_NOFORK:0); in sh_coexec()
807 if(shp->poolfiles) in sh_coexec()
811 for(np=(Namval_t*)dtfirst(shp->inpool);np;np=(Namval_t*)dtnext(shp->inpool,np)) in sh_coexec()
818 dtclose(shp->inpool); in sh_coexec()
819 shp->inpool = 0; in sh_coexec()
820 shp->poolfiles = 0; in sh_coexec()
821 sh_unscope(shp); in sh_coexec()
822 shp->var_tree = top; in sh_coexec()
827 sh_onoption(shp,SH_XTRACE); in sh_coexec()
829 sh_onoption(shp,SH_VERBOSE); in sh_coexec()
830 sh_trap(shp,"set +o",0); in sh_coexec()
833 sfswap(shp->strbuf2,sfstdout); in sh_coexec()
834 str = sfstruse(shp->strbuf2); in sh_coexec()
838 cjp->local = shp->coshell; in sh_coexec()
842 sh_coaccept(shp,shp->inpipe,1); in sh_coexec()
843 sh_coaccept(shp,shp->outpipe,0); in sh_coexec()
846 shp->coutpipe = shp->inpipe[1]; in sh_coexec()
847 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; in sh_coexec()
857 static Sfio_t *openstream(Shell_t *shp, struct ionod *iop, int *save) in openstream() argument
859 int err=errno,savein, fd = sh_redirect(shp,iop,3); in openstream()
868 shp->offsets[0] = -1; in openstream()
869 shp->offsets[1] = 0; in openstream()
876 static Namval_t *enter_namespace(Shell_t *shp, Namval_t *nsp) in enter_namespace() argument
878 Namval_t *path=nsp, *fpath=nsp, *onsp=shp->namespace; in enter_namespace()
885 else if(nv_dict(nsp)->view!=shp->var_base) in enter_namespace()
900 if(shp->var_tree==oroot) in enter_namespace()
902 shp->var_tree = shp->var_tree->view; in enter_namespace()
903 oroot = shp->var_base; in enter_namespace()
908 if(shp->var_tree==shp->var_base) in enter_namespace()
909 shp->var_tree = nv_dict(nsp); in enter_namespace()
912 for(root=shp->var_tree; root->view!=oroot;root=root->view); in enter_namespace()
916 shp->namespace = nsp; in enter_namespace()
917 if(path && (path = nv_search(PATHNOD->nvname,shp->var_tree,HASH_NOSCOPE)) && (val=nv_getval(path))) in enter_namespace()
919 …if(fpath && (fpath = nv_search(FPATHNOD->nvname,shp->var_tree,HASH_NOSCOPE)) && (val=nv_getval(fpa… in enter_namespace()
925 int sh_exec(register Shell_t *shp,register const Shnode_t *t, int flags) in sh_exec() argument
927 Stk_t *stkp = shp->stk; in sh_exec()
929 sh_sigcheck(shp); in sh_exec()
930 if(t && !shp->st.execbrk && !sh_isoption(shp,SH_NOEXEC)) in sh_exec()
943 int topfd = shp->topfd; in sh_exec()
949 int vexi = shp->vexp->cur; in sh_exec()
953 volatile int was_errexit = sh_isstate(shp,SH_ERREXIT); in sh_exec()
954 volatile int was_monitor = sh_isstate(shp,SH_MONITOR); in sh_exec()
966 sh_offstate(shp,SH_ERREXIT); in sh_exec()
967 sh_offstate(shp,SH_DEFPATH); in sh_exec()
969 sh_onstate(shp,SH_ERREXIT); in sh_exec()
971 sh_onstate(shp,SH_MONITOR); in sh_exec()
973 if(!shp->intrap) in sh_exec()
974 shp->oldexit=shp->exitval; in sh_exec()
975 shp->exitval=0; in sh_exec()
976 shp->lastsig = 0; in sh_exec()
977 shp->lastpath = 0; in sh_exec()
987 shp->bltindata.invariant = type>>(COMBITS+2); in sh_exec()
988 shp->bltindata.pwdfd = shp->pwdfd; in sh_exec()
991 error_info.line = t->com.comline-shp->st.firstline; in sh_exec()
992 spawnvex_add(shp->vex,SPAWN_frame,0,0,0); in sh_exec()
993 com = sh_argbuild(shp,&argn,&(t->com),OPTIMIZE); in sh_exec()
994 procsub = shp->procsub; in sh_exec()
995 shp->procsub = 0; in sh_exec()
1001 sh_sigcheck(shp); in sh_exec()
1006 …if(np && shp->namespace && nq!=shp->namespace && nv_isattr(np,NV_BLTIN|NV_INTEGER|BLT_SPC)!=(NV_BL… in sh_exec()
1009 if(mp = sh_fsearch(shp,com[0],0)) in sh_exec()
1011 nq = shp->namespace; in sh_exec()
1017 shp->xargexit = 0; in sh_exec()
1020 register int n = b_command(0,com,&shp->bltindata); in sh_exec()
1027 np = nv_bfsearch(com0, shp->bltin_tree, &nq, &cp); in sh_exec()
1029 if(shp->xargexit) in sh_exec()
1031 shp->xargmin -= command; in sh_exec()
1032 shp->xargmax -= command; in sh_exec()
1035 shp->xargmin = 0; in sh_exec()
1038 if(argn && shp->inpool) in sh_exec()
1041 sh_redirect(shp,io,0); in sh_exec()
1048 sh_coaddfile(shp,*argv); in sh_exec()
1057 shp->coshell = sh_coinit(shp,com); in sh_exec()
1068 if(shp->namespace && (mp=sh_fsearch(shp,np->nvname,0))) in sh_exec()
1072 np = dtsearch(shp->fun_tree,np); in sh_exec()
1075 if(sh_isoption(shp,SH_PFSH) && nv_isattr(np,NV_BLTINOPT) && !nv_isattr(np,NV_BLTPFSH)) in sh_exec()
1077 if(path_xattr(shp,np->nvname,(char*)0)) in sh_exec()
1079 dtdelete(shp->bltin_tree,np); in sh_exec()
1092 Dt_t *root = command?shp->bltin_tree:shp->fun_tree; in sh_exec()
1095 if(shp->namespace && !nq && !cp) in sh_exec()
1096 np = sh_fsearch(shp,com0,0); in sh_exec()
1103 if(shp->envlist = argp = t->com.comset) in sh_exec()
1122 if(!shp->st.var_local) in sh_exec()
1124 sh_scope(shp,(struct argnod*)0,0); in sh_exec()
1125 shp->st.var_local = shp->var_tree; in sh_exec()
1134 shp->typeinit = np; in sh_exec()
1148 if(shp->namespace) in sh_exec()
1151 if(!shp->strbuf2) in sh_exec()
1152 shp->strbuf2 = sfstropen(); in sh_exec()
1153 sfprintf(shp->strbuf2,"%s%s%c",NV_CLASS,nv_name(shp->namespace),0); in sh_exec()
1154 shp->prefix = strdup(sfstruse(shp->strbuf2)); in sh_exec()
1155 xp = shp->prefix+strlen(NV_CLASS); in sh_exec()
1160 nv_open(shp->prefix,shp->var_base,NV_VARNAME); in sh_exec()
1167 shp->prefix = NV_CLASS; in sh_exec()
1171 if((shp->fn_depth && !shp->prefix) || np==SYSLOCAL) in sh_exec()
1188 shp->nodelist = sh_setlist(shp,argp,flgs,tp); in sh_exec()
1189 if(np==shp->typeinit) in sh_exec()
1190 shp->typeinit = 0; in sh_exec()
1191 shp->envlist = argp; in sh_exec()
1195 last_table = shp->last_table; in sh_exec()
1196 shp->last_table = 0; in sh_exec()
1212 else if((t->tre.tretyp&FSHOWME) && sh_isoption(shp,SH_SHOWME)) in sh_exec()
1214 int ison = sh_isoption(shp,SH_XTRACE); in sh_exec()
1216 sh_onoption(shp,SH_XTRACE); in sh_exec()
1217 sh_trace(shp,com-command,tflags); in sh_exec()
1219 sh_redirect(shp,io,SH_SHOWME|IOHERESTRING); in sh_exec()
1221 sh_offoption(shp,SH_XTRACE); in sh_exec()
1224 else if((np!=SYSSET) && sh_isoption(shp,SH_XTRACE)) in sh_exec()
1225 sh_trace(shp,com-command,tflags); in sh_exec()
1226 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
1228 int n = sh_debug(shp,trap,(char*)0,(char*)0, com, ARG_RAW); in sh_exec()
1229 if(n==255 && shp->fn_depth+shp->dot_depth) in sh_exec()
1242 sfsync(shp->outpool); in sh_exec()
1243 shp->lastpath = 0; in sh_exec()
1246 if(path_search(shp,com0,NIL(Pathcomp_t**),1)) in sh_exec()
1248 error_info.line = t->com.comline-shp->st.firstline; in sh_exec()
1250 if(!shp->namespace || !(np=sh_fsearch(shp,com0,0))) in sh_exec()
1252 np=nv_search(com0,shp->fun_tree,0); in sh_exec()
1255 Namval_t *mp=nv_search(com0,shp->bltin_tree,0); in sh_exec()
1267 if((np=nv_search(com0,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp) in sh_exec()
1268 np=nv_search(nv_getval(np),shp->bltin_tree,0); in sh_exec()
1275 if(shp->comsub==1 && np && is_abuiltin(np) && *np->nvname=='/') in sh_exec()
1291 int was_nofork = execflg?sh_isstate(shp,SH_NOFORK):0; in sh_exec()
1292 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1297 bp = &shp->bltindata; in sh_exec()
1309 was_vi = sh_isoption(shp,SH_VI); in sh_exec()
1310 was_emacs = sh_isoption(shp,SH_EMACS); in sh_exec()
1311 was_gmacs = sh_isoption(shp,SH_GMACS); in sh_exec()
1312 sh_offoption(shp,SH_VI); in sh_exec()
1313 sh_offoption(shp,SH_EMACS); in sh_exec()
1314 sh_offoption(shp,SH_GMACS); in sh_exec()
1317 sh_onstate(shp,SH_NOFORK); in sh_exec()
1318 sh_pushcontext(shp,buffp,SH_JMPCMD); in sh_exec()
1333 type = (execflg && !shp->subshell && !shp->st.trapcom[0]); in sh_exec()
1334 shp->redir0 = 1; in sh_exec()
1335 sh_redirect(shp,io,type|(np->nvalue.bfp==(Nambfp_f)b_dot_cmd?0:IOHERESTRING|IOUSEVEX)); in sh_exec()
1341 if(!shp->pwd) in sh_exec()
1342 path_pwd(shp,0); in sh_exec()
1344 else if (shp->pwdfd>=0) in sh_exec()
1345 fstat(shp->pwdfd,&statb); in sh_exec()
1346 else if (shp->pwd) in sh_exec()
1351 sh_onstate(shp,SH_STOPOK); in sh_exec()
1354 save_prompt = shp->nextprompt; in sh_exec()
1355 shp->nextprompt = 0; in sh_exec()
1360 sh_scope(shp,argp,0); in sh_exec()
1366 shp->exitval = 0; in sh_exec()
1367 shp->bltinfun = (Shbltin_f)funptr(np); in sh_exec()
1375 if(shp->subshell && nv_isattr(np,BLT_NOSFIO)) in sh_exec()
1376 sh_subtmpfile(shp); in sh_exec()
1377 if(execflg && !shp->subshell && in sh_exec()
1378 … !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && shp->fn_depth==0 && !nv_isattr(np,BLT_ENV)) in sh_exec()
1382 for(fd=0; fd < shp->gd->lim.open_max; fd++) in sh_exec()
1383 if((shp->fdstatus[fd]&IOCLEX)&&fd!=shp->infd && (fd!=shp->pwdfd)) in sh_exec()
1387 shp->exitval = (*shp->bltinfun)(argn,com,(void*)bp); in sh_exec()
1390 ((Shnode_t*)t)->com.comstate = shp->bltindata.data; in sh_exec()
1392 if(shp->exitval && errno==EINTR && shp->lastsig) in sh_exec()
1393 shp->exitval = SH_EXITSIG|shp->lastsig; in sh_exec()
1394 else if(!nv_isattr(np,BLT_EXIT) && shp->exitval!=SH_RUNPROG) in sh_exec()
1395 shp->exitval &= SH_EXITMASK; in sh_exec()
1405 if(shp->gd->hist_ptr && item->strm == shp->gd->hist_ptr->histfp) in sh_exec()
1406 hist_close(shp->gd->hist_ptr); in sh_exec()
1411 if(shp->bltinfun && (error_info.flags&ERROR_NOTIFY)) in sh_exec()
1412 (*shp->bltinfun)(-2,com,(void*)bp); in sh_exec()
1417 if(np!=SYSEXEC && shp->vex->cur) in sh_exec()
1419 spawnvex_apply(shp->vex, 0, SPAWN_RESET|SPAWN_FRAME); in sh_exec()
1423 spawnvex_apply(shp->vex, 0, SPAWN_RESET|SPAWN_FRAME); in sh_exec()
1424 if(shp->comsub && (fd=sffileno(sfstdout))!=1 && fd>=0) in sh_exec()
1425 spawnvex_add(shp->vex,fd,1,0,0); in sh_exec()
1435 sh_offstate(shp,SH_NOFORK); in sh_exec()
1439 while((fchdir(shp->pwdfd) < 0) && errno==EINTR) in sh_exec()
1442 if(shp->pwd || (shp->pwdfd >= 0)) in sh_exec()
1451 if(shp->pwdfd >= 0) in sh_exec()
1453 while((fchdir(shp->pwdfd) < 0) && errno==EINTR) in sh_exec()
1458 while((chdir(shp->pwd) < 0) && errno==EINTR) in sh_exec()
1464 sh_offstate(shp,SH_STOPOK); in sh_exec()
1468 sfpool(sfstderr,shp->outpool,SF_WRITE); in sh_exec()
1470 shp->nextprompt = save_prompt; in sh_exec()
1472 sh_popcontext(shp,buffp); in sh_exec()
1475 shp->bltinfun = 0; in sh_exec()
1479 sh_onoption(shp,SH_VI); in sh_exec()
1481 sh_onoption(shp,SH_EMACS); in sh_exec()
1483 sh_onoption(shp,SH_GMACS); in sh_exec()
1485 sh_unscope(shp); in sh_exec()
1489 if((shp->topfd>topfd) && !(shp->subshell && np==SYSEXEC)) in sh_exec()
1490 sh_iorestore(shp,topfd,jmpval); in sh_exec()
1491 if(shp->vexp->cur>vexi) in sh_exec()
1492 sh_vexrestore(shp,vexi); in sh_exec()
1493 shp->redir0 = 0; in sh_exec()
1495 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1500 if(shp->exitval >=0) in sh_exec()
1510 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1521 indx = path_search(shp,com0,NIL(Pathcomp_t**),0); in sh_exec()
1525 if(shp->namespace) in sh_exec()
1526 np = sh_fsearch(shp,com0,0); in sh_exec()
1529 np = nv_search(com0,shp->fun_tree,HASH_NOSCOPE); in sh_exec()
1537 shp->exitval = ERROR_NOEXEC; in sh_exec()
1542 shp->exitval = ERROR_NOENT; in sh_exec()
1556 shp->last_table = last_table; in sh_exec()
1557 mode = set_instance(shp,nq,&node,&nr); in sh_exec()
1561 indx = shp->topfd; in sh_exec()
1562 sh_pushcontext(shp,buffp,SH_JMPCMD); in sh_exec()
1569 indx = sh_redirect(shp,io,execflg|IOUSEVEX); in sh_exec()
1586 namespace = nv_search(cp-1,shp->var_base,HASH_NOSCOPE); in sh_exec()
1590 namespace = enter_namespace(shp,namespace); in sh_exec()
1592 sh_funct(shp,np,argn,com,t->com.comset,(flags&~OPTIMIZE_FLAG)); in sh_exec()
1595 enter_namespace(shp,namespace); in sh_exec()
1597 spawnvex_apply(shp->vex, 0, SPAWN_RESET|SPAWN_FRAME); in sh_exec()
1598 if(shp->vexp->cur>vexi) in sh_exec()
1599 sh_vexrestore(shp,vexi); in sh_exec()
1604 sh_popcontext(shp,buffp); in sh_exec()
1605 sh_iorestore(shp,indx,jmpval); in sh_exec()
1612 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1618 spawnvex_apply(shp->vex, 0, SPAWN_RESET|SPAWN_FRAME); in sh_exec()
1620 exitset(shp); in sh_exec()
1630 if(shp->inpool) in sh_exec()
1632 sh_exec(shp,t->fork.forktre,0); in sh_exec()
1636 if(shp->subshell) in sh_exec()
1638 sh_subtmpfile(shp); in sh_exec()
1641 if(shp->comsub && !(shp->fdstatus[1]&IONOSEEK)) in sh_exec()
1643 unpipe = iousepipe(shp); in sh_exec()
1648 no_fork = !ntflag && !(type&(FAMP|FPOU)) && !shp->subshell && in sh_exec()
1649 !(shp->st.trapcom[SIGINT] && *shp->st.trapcom[SIGINT]) && in sh_exec()
1650 !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && in sh_exec()
1651 ((struct checkpt*)shp->jmplist)->mode!=SH_JMPEVAL && in sh_exec()
1652 (execflg2 || (execflg && shp->fn_depth==0 && in sh_exec()
1653 !(pipejob && sh_isoption(shp,SH_PIPEFAIL)) in sh_exec()
1655 if(sh_isstate(shp,SH_PROFILE) || shp->dot_depth) in sh_exec()
1659 sh_offstate(shp,SH_MONITOR); in sh_exec()
1662 sh_offstate(shp,SH_MONITOR); in sh_exec()
1679 restorefd = shp->topfd; in sh_exec()
1681 restorevex = shp->vexp->cur; in sh_exec()
1687 if(shp->coshell) in sh_exec()
1689 if(shp->cpipe[0]<0 || shp->cpipe[1] < 0) in sh_exec()
1691 sh_copipe(shp,shp->outpipe=shp->cpipe,0); in sh_exec()
1692 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; in sh_exec()
1694 sh_copipe(shp,shp->inpipe=pipes,0); in sh_exec()
1695 parent = sh_coexec(shp,t,3); in sh_exec()
1696 shp->cpid = parent; in sh_exec()
1697 jobid = job_post(shp,parent,0); in sh_exec()
1701 coproc_init(shp,pipes); in sh_exec()
1706 if(shp->coshell) in sh_exec()
1708 parent = sh_coexec(shp,t,0); in sh_exec()
1709 jobid = job_post(shp,parent,0); in sh_exec()
1716 parent = sh_ntfork(shp,t,com,&jobid,ntflag); in sh_exec()
1718 parent = sh_fork(shp,type,&jobid); in sh_exec()
1721 if(shp->comsub==1 && usepipe && unpipe) in sh_exec()
1722 sh_iounpipe(shp); in sh_exec()
1729 parent = sh_ntfork(shp,t,com,&jobid,ntflag); in sh_exec()
1731 parent = sh_fork(shp,type,&jobid); in sh_exec()
1733 if((parent = sh_ntfork(shp,t,com,&jobid,ntflag))<=0) in sh_exec()
1738 if(shp->comsub==1 && usepipe && unpipe) in sh_exec()
1739 sh_iounpipe(shp); in sh_exec()
1743 parent = sh_fork(shp,type,&jobid); in sh_exec()
1761 if(shp->subshell) in sh_exec()
1762 shp->spid = parent; in sh_exec()
1764 sh_close(shp->inpipe[0]); in sh_exec()
1766 shp->bckpid = parent; in sh_exec()
1769 if(!sh_isoption(shp,SH_MONITOR)) in sh_exec()
1771 if(!(shp->sigflag[SIGINT]&(SH_SIGFAULT|SH_SIGOFF))) in sh_exec()
1772 sh_sigtrap(shp,SIGINT); in sh_exec()
1773 shp->trapnote |= SH_SIGIGNORE; in sh_exec()
1775 if(shp->pipepid) in sh_exec()
1776 shp->pipepid = parent; in sh_exec()
1780 if(parent==shp->spid) in sh_exec()
1781 shp->spid = 0; in sh_exec()
1783 if(shp->topfd > topfd) in sh_exec()
1784 sh_iorestore(shp,topfd,0); in sh_exec()
1786 if(shp->vexp->cur > vexi) in sh_exec()
1787 sh_vexrestore(shp,vexi); in sh_exec()
1790 sh_iounpipe(shp); in sh_exec()
1791 if(!sh_isoption(shp,SH_MONITOR)) in sh_exec()
1793 shp->trapnote &= ~SH_SIGIGNORE; in sh_exec()
1794 if(shp->exitval == (SH_EXITSIG|SIGINT)) in sh_exec()
1800 if(sh_isstate(shp,SH_PROFILE) || sh_isstate(shp,SH_INTERACTIVE)) in sh_exec()
1805 sfprintf(sfstderr,"[%d]\t%s\n",jobid,sh_pid2str(shp,parent)); in sh_exec()
1822 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1826 sh_sigreset(shp,2); in sh_exec()
1827 sh_pushcontext(shp,buffp,SH_JMPEXIT); in sh_exec()
1831 if((type&FINT) && !sh_isstate(shp,SH_MONITOR)) in sh_exec()
1836 shp->sigflag[SIGINT] = SH_SIGOFF; in sh_exec()
1837 shp->sigflag[SIGQUIT] = SH_SIGOFF; in sh_exec()
1838 if(!shp->st.ioset) in sh_exec()
1844 sh_offstate(shp,SH_MONITOR); in sh_exec()
1847 if((type&FAMP) && sh_isoption(shp,SH_BGNICE)) in sh_exec()
1851 if(shp->fifo && (type&(FPIN|FPOU))) in sh_exec()
1854 void *fifo_timer=sh_timeradd(500,1,fifo_check,(void*)shp); in sh_exec()
1855 fn = sh_open(shp->fifo,fd?O_WRONLY:O_RDONLY); in sh_exec()
1857 sh_iorenumber(shp,fn,fd); in sh_exec()
1860 unlink(shp->fifo); in sh_exec()
1861 free(shp->fifo); in sh_exec()
1862 shp->fifo = 0; in sh_exec()
1869 if(shp->inpipe[2]>20000) in sh_exec()
1870 sh_coaccept(shp,shp->inpipe,0); in sh_exec()
1872 sh_iorenumber(shp,shp->inpipe[0],0); in sh_exec()
1874 sh_close(shp->inpipe[1]); in sh_exec()
1879 if(shp->outpipe[2]>20000) in sh_exec()
1880 sh_coaccept(shp,shp->outpipe,1); in sh_exec()
1882 sh_iorenumber(shp,shp->outpipe[1],1); in sh_exec()
1883 sh_pclose(shp->outpipe); in sh_exec()
1886 error_info.line = t->fork.forkline-shp->st.firstline; in sh_exec()
1887 if(shp->topfd) in sh_exec()
1888 sh_iounsave(shp); in sh_exec()
1889 topfd = shp->topfd; in sh_exec()
1898 sh_redirect(shp,t->tre.treio,1|IOUSEVEX); in sh_exec()
1903 _sh_fork(shp,parent, 0, (int*)0); in sh_exec()
1907 job_post(shp,parent,0); in sh_exec()
1909 sh_iorestore(shp,topfd,SH_JMPCMD); in sh_exec()
1910 if(shp->vexp->cur>vexi) in sh_exec()
1911 sh_vexrestore(shp,vexi); in sh_exec()
1912 sh_done(shp,(shp->exitval&SH_EXITSIG)?(shp->exitval&SH_EXITMASK):0); in sh_exec()
1924 job_clear(shp); in sh_exec()
1925 sh_exec(shp,t->fork.forktre,flags|sh_state(SH_NOFORK)|sh_state(SH_FORKED)); in sh_exec()
1929 sh_offoption(shp,SH_ERREXIT); in sh_exec()
1930 sh_freeup(shp); in sh_exec()
1931 path_exec(shp,com0,com,t->com.comset); in sh_exec()
1934 sh_popcontext(shp,buffp); in sh_exec()
1936 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1937 sh_done(shp,0); in sh_exec()
1950 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
1952 if(shp->inpool) in sh_exec()
1954 sh_redirect(shp,t->fork.forkio,0); in sh_exec()
1955 sh_exec(shp,t->fork.forktre,0); in sh_exec()
1959 if(shp->subshell) in sh_exec()
1961 sh_pushcontext(shp,buffp,SH_JMPIO); in sh_exec()
1964 was_interactive = sh_isstate(shp,SH_INTERACTIVE); in sh_exec()
1965 sh_offstate(shp,SH_INTERACTIVE); in sh_exec()
1966 shp->pipepid = simple; in sh_exec()
1968 sh_vexsave(shp,0,shp->inpipe[0],0,0); in sh_exec()
1970 sh_iosave(shp,0,shp->topfd,(char*)0); in sh_exec()
1971 sh_iorenumber(shp,shp->inpipe[0],0); in sh_exec()
1984 error_info.line = t->fork.forkline-shp->st.firstline; in sh_exec()
1988 if(shp->comsub) in sh_exec()
1990 sh_redirect(shp,t->fork.forkio,execflg); in sh_exec()
1994 shp,SH_BASH) && !sh_isoption(shp,SH_LASTPIPE)) in sh_exec()
1997 Shnode_t *tt = (Shnode_t*)stkalloc(shp->stk,sizeof(Shnode_t)); in sh_exec()
2002 sh_exec(shp,t,flags&~simple); in sh_exec()
2005 sfsync(shp->outpool); in sh_exec()
2006 sh_popcontext(shp,buffp); in sh_exec()
2007 sh_iorestore(shp,buffp->topfd,jmpval); in sh_exec()
2008 if(shp->vexp->cur>vexi) in sh_exec()
2009 sh_vexrestore(shp,buffp->vexi); in sh_exec()
2015 type = shp->exitval; in sh_exec()
2019 if(shp->pipepid>1 && shp->comsub!=1) in sh_exec()
2021 job_wait(shp->pipepid); in sh_exec()
2022 type = shp->exitval; in sh_exec()
2026 if(type || !sh_isoption(shp,SH_PIPEFAIL)) in sh_exec()
2027 shp->exitval = type; in sh_exec()
2029 if(shp->comsub==1 && usepipe && unpipe) in sh_exec()
2030 sh_iounpipe(shp); in sh_exec()
2031 shp->pipepid = 0; in sh_exec()
2032 shp->st.ioset = 0; in sh_exec()
2036 sh_onstate(shp,SH_ERREXIT); in sh_exec()
2040 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
2046 if(shp->inpool) in sh_exec()
2048 sh_exec(shp,t->par.partre,0); in sh_exec()
2054 …if(!shp->subshell && !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && (flags&sh_state(SH_NOFORK… in sh_exec()
2058 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
2059 shp->st.otrapcom = 0; in sh_exec()
2060 if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0]) in sh_exec()
2063 memcpy(savsig=malloc(nsig),(char*)&shp->st.trapcom[0],nsig); in sh_exec()
2064 shp->st.otrapcom = (char**)savsig; in sh_exec()
2066 sh_sigreset(shp,0); in sh_exec()
2067 sh_pushcontext(shp,buffp,SH_JMPEXIT); in sh_exec()
2070 sh_exec(shp,t->par.partre,flags); in sh_exec()
2071 sh_popcontext(shp,buffp); in sh_exec()
2073 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
2074 if(shp->exitval > 256) in sh_exec()
2075 shp->exitval -= 128; in sh_exec()
2076 sh_done(shp,0); in sh_exec()
2083 _sh_fork(shp,pid,0,0); in sh_exec()
2086 sh_exec(shp,t->par.partre,flags); in sh_exec()
2087 shp->st.trapcom[0]=0; in sh_exec()
2088 sh_done(shp,0); in sh_exec()
2092 sh_subshell(shp,t->par.partre,flags,0); in sh_exec()
2117 if(shp->inpool) in sh_exec()
2121 sh_exec(shp,t->lst.lstlef, 0); in sh_exec()
2127 sh_exec(shp,t,0); in sh_exec()
2134 if(shp->subshell) in sh_exec()
2136 sh_subtmpfile(shp); in sh_exec()
2137 if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK)) in sh_exec()
2138 iousepipe(shp); in sh_exec()
2140 shp->inpipe = pvo; in sh_exec()
2141 shp->outpipe = pvn; in sh_exec()
2143 if(sh_isoption(shp,SH_PIPEFAIL)) in sh_exec()
2150 exitval = job.exitval = (int*)stkalloc(shp->stk,job.waitall*sizeof(int)); in sh_exec()
2154 job.waitall |= !pipejob && sh_isstate(shp,SH_MONITOR); in sh_exec()
2162 if(shp->coshell && !showme) in sh_exec()
2166 sh_copipe(shp,pvn,0); in sh_exec()
2167 type = sh_coexec(shp,t,1+copipe); in sh_exec()
2172 job_post(shp,type,0); in sh_exec()
2184 sh_copipe(shp,pvn,0); in sh_exec()
2198 type = sh_exec(shp,t->lst.lstlef, errorflg); in sh_exec()
2209 shp->inpipe = pvn; in sh_exec()
2210 shp->outpipe = 0; in sh_exec()
2221 sh_exec(shp,t,flags); in sh_exec()
2230 n = shp->exitval; in sh_exec()
2233 if(sh_isstate(shp,SH_MONITOR)) in sh_exec()
2237 shp->intrap++; in sh_exec()
2239 shp->intrap--; in sh_exec()
2253 shp->exitval = n; in sh_exec()
2255 if(!pipejob && sh_isstate(shp,SH_MONITOR) && sh_isoption(shp,SH_INTERACTIVE)) in sh_exec()
2256 tcsetpgrp(JOBTTY,shp->gd->pid); in sh_exec()
2270 sh_exec(shp,t->lst.lstlef,errorflg|OPTIMIZE); in sh_exec()
2274 sh_exec(shp,t,flags); in sh_exec()
2280 if(shp->inpool) in sh_exec()
2283 sh_exec(shp,t->lst.lstlef,0); in sh_exec()
2284 sh_exec(shp,t->lst.lstrit,0); in sh_exec()
2290 if(sh_exec(shp,t->lst.lstlef,OPTIMIZE)==0) in sh_exec()
2291 sh_exec(shp,t->lst.lstrit,flags); in sh_exec()
2296 if(shp->inpool) in sh_exec()
2301 if(sh_exec(shp,t->lst.lstlef,OPTIMIZE)!=0) in sh_exec()
2302 sh_exec(shp,t->lst.lstrit,flags); in sh_exec()
2320 int jmpval = ((struct checkpt*)shp->jmplist)->mode; in sh_exec()
2321 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
2322 void *optlist = shp->optlist; in sh_exec()
2323 shp->optlist = 0; in sh_exec()
2324 sh_tclear(shp,t->for_.fortre); in sh_exec()
2325 sh_pushcontext(shp,buffp,jmpval); in sh_exec()
2330 error_info.line = t->for_.forline-shp->st.firstline; in sh_exec()
2333 args=shp->st.dolv+1; in sh_exec()
2334 nargs = shp->st.dolc; in sh_exec()
2335 argsav=sh_arguse(shp); in sh_exec()
2339 args=sh_argbuild(shp,&argn,tp,0); in sh_exec()
2342 np = nv_open(t->for_.fornam, shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME|NV_NOREF); in sh_exec()
2344 shp->st.loopcnt++; in sh_exec()
2346 while(cp && shp->st.execbrk==0) in sh_exec()
2355 sh_menu(shp,sfstderr,nargs,args); in sh_exec()
2358 save_prompt = shp->nextprompt; in sh_exec()
2359 shp->nextprompt = 3; in sh_exec()
2360 shp->timeout = 0; in sh_exec()
2361 shp->exitval=sh_readline(shp,&nullptr,(void*)0,0,1,(size_t)0,1000*shp->st.tmout); in sh_exec()
2362 shp->nextprompt = save_prompt; in sh_exec()
2363 if(shp->exitval||sfeof(sfstdin)||sferror(sfstdin)) in sh_exec()
2365 shp->exitval = 1; in sh_exec()
2368 if(!(val=nv_getval(sh_scoped(shp,REPLYNOD)))) in sh_exec()
2400 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2407 sh_debug(shp,trap,(char*)0,(char*)0,av,0); in sh_exec()
2410 if(shp->inpool) in sh_exec()
2412 poolfiles = shp->poolfiles; in sh_exec()
2413 sh_exec(shp,t->for_.fortre,0); in sh_exec()
2414 if(poolfiles==shp->poolfiles) in sh_exec()
2418 sh_exec(shp,t->for_.fortre,flag); in sh_exec()
2422 if((cp=nv_getval(sh_scoped(shp,REPLYNOD))) && *cp==0) in sh_exec()
2428 if(shp->st.breakcnt<0) in sh_exec()
2429 shp->st.execbrk = (++shp->st.breakcnt !=0); in sh_exec()
2435 sh_popcontext(shp,buffp); in sh_exec()
2436 sh_tclear(shp,t->for_.fortre); in sh_exec()
2437 sh_optclear(shp,optlist); in sh_exec()
2439 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
2441 if(shp->st.breakcnt>0) in sh_exec()
2442 shp->st.execbrk = (--shp->st.breakcnt !=0); in sh_exec()
2443 shp->st.loopcnt--; in sh_exec()
2444 sh_argfree(shp,argsav,0); in sh_exec()
2459 int jmpval = ((struct checkpt*)shp->jmplist)->mode; in sh_exec()
2460 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_exec()
2461 void *optlist = shp->optlist; in sh_exec()
2464 if(shp->inpool) in sh_exec()
2470 sh_redirect(shp,tt->com.comio,0); in sh_exec()
2474 sh_exec(shp,tt,0); in sh_exec()
2477 if((sh_exec(shp,tt,0)==0)!=(type==TWH)) in sh_exec()
2479 poolfiles = shp->poolfiles; in sh_exec()
2480 sh_exec(shp,t->wh.dotre,0); in sh_exec()
2482 sh_exec(shp,(Shnode_t*)t->wh.whinc,0); in sh_exec()
2484 while(poolfiles != shp->poolfiles); in sh_exec()
2489 shp->optlist = 0; in sh_exec()
2490 sh_tclear(shp,t->wh.whtre); in sh_exec()
2491 sh_tclear(shp,t->wh.dotre); in sh_exec()
2492 sh_pushcontext(shp,buffp,jmpval); in sh_exec()
2500 iop = openstream(shp,tt->com.comio,&savein); in sh_exec()
2502 sh_setlist(shp,tt->com.comset,NV_IDENT|NV_ASSIGN,0); in sh_exec()
2505 shp->st.loopcnt++; in sh_exec()
2506 while(shp->st.execbrk==0) in sh_exec()
2511 if(!(shp->cur_line=sfgetr(iop,'\n',SF_STRING))) in sh_exec()
2516 if((sh_exec(shp,tt,first)==0)!=(type==TWH)) in sh_exec()
2518 r = sh_exec(shp,t->wh.dotre,first|errorflg); in sh_exec()
2519 if(shp->st.breakcnt<0) in sh_exec()
2520 shp->st.execbrk = (++shp->st.breakcnt !=0); in sh_exec()
2522 if(shp->st.execbrk==0 && t->wh.whinc) in sh_exec()
2523 sh_exec(shp,(Shnode_t*)t->wh.whinc,first); in sh_exec()
2527 shp->offsets[0] = -1; in sh_exec()
2528 shp->offsets[1] = 0; in sh_exec()
2533 sh_popcontext(shp,buffp); in sh_exec()
2534 sh_tclear(shp,t->wh.whtre); in sh_exec()
2535 sh_tclear(shp,t->wh.dotre); in sh_exec()
2536 sh_optclear(shp,optlist); in sh_exec()
2538 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
2540 if(shp->st.breakcnt>0) in sh_exec()
2541 shp->st.execbrk = (--shp->st.breakcnt !=0); in sh_exec()
2542 shp->st.loopcnt--; in sh_exec()
2543 shp->exitval= r; in sh_exec()
2552 shp->cur_line = 0; in sh_exec()
2561 error_info.line = t->ar.arline-shp->st.firstline; in sh_exec()
2564 arg[1] = sh_macpat(shp,t->ar.arexpr,OPTIMIZE|ARG_ARITH); in sh_exec()
2569 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2570 sh_debug(shp,trap,(char*)0, (char*)0, arg, ARG_ARITH); in sh_exec()
2571 if(sh_isoption(shp,SH_XTRACE)) in sh_exec()
2573 sh_trace(shp,NIL(char**),0); in sh_exec()
2577 shp->exitval = !arith_exec((Arith_t*)t->ar.arcomp); in sh_exec()
2579 shp->exitval = !sh_arith(shp,arg[1]); in sh_exec()
2585 if(shp->inpool) in sh_exec()
2587 sh_exec(shp,t->if_.thtre,0); in sh_exec()
2589 sh_exec(shp,t->if_.eltre, 0); in sh_exec()
2593 if(sh_exec(shp,t->if_.iftre,OPTIMIZE)==0) in sh_exec()
2594 sh_exec(shp,t->if_.thtre,flags); in sh_exec()
2596 sh_exec(shp,t->if_.eltre, flags); in sh_exec()
2598 shp->exitval=0; /* force zero exit for if-then-fi */ in sh_exec()
2604 char *trap, *r = sh_macpat(shp,tt->sw.swarg,OPTIMIZE); in sh_exec()
2605 error_info.line = t->sw.swline-shp->st.firstline; in sh_exec()
2607 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2614 sh_debug(shp,trap, (char*)0, (char*)0, av, 0); in sh_exec()
2620 if(shp->inpool) in sh_exec()
2622 sh_exec(shp,t->reg.regcom,0); in sh_exec()
2631 s = sh_macpat(shp,rex,OPTIMIZE|ARG_EXP|ARG_CASE); in sh_exec()
2642 do sh_exec(shp,t->reg.regcom,(t->reg.regflag?(flags&sh_state(SH_ERREXIT)):flags)); in sh_exec()
2669 if(shp->inpool) in sh_exec()
2672 sh_exec(shp,t->par.partre,0); in sh_exec()
2678 sh_exec(shp,t->par.partre,OPTIMIZE); in sh_exec()
2679 shp->exitval = !shp->exitval; in sh_exec()
2685 if(shp->subshell && shp->comsub==1) in sh_exec()
2687 timer_on = sh_isstate(shp,SH_TIMING); in sh_exec()
2695 sh_onstate(shp,SH_TIMING); in sh_exec()
2696 sh_exec(shp,t->par.partre,OPTIMIZE); in sh_exec()
2698 sh_offstate(shp,SH_TIMING); in sh_exec()
2712 at = shp->gd->lim.clk_tck*(ta.tv_sec-tb.tv_sec); in sh_exec()
2713 …at += ((shp->gd->lim.clk_tck*(((1000000L/2)/shp->gd->lim.clk_tck)+(ta.tv_usec-tb.tv_usec)))/10000… in sh_exec()
2720 Namval_t *np = nv_open("TIMEFORMAT",shp->var_tree,NV_NOADD); in sh_exec()
2736 p_time(shp,sfstderr,sh_translate(format),tm); in sh_exec()
2747 if(shp->inpool) in sh_exec()
2749 sh_exec(shp,t->funct.functtre,0); in sh_exec()
2757 Namval_t *oldnspace = shp->namespace; in sh_exec()
2768 np = nv_open(xp,shp->var_tree,flag); in sh_exec()
2778 dtuserdata(root,shp,1); in sh_exec()
2781 dtview(root,shp->var_base); in sh_exec()
2783 oldnspace = enter_namespace(shp,np); in sh_exec()
2784 sh_exec(shp,t->for_.fortre,flag|sh_state(SH_ERREXIT)); in sh_exec()
2785 enter_namespace(shp,oldnspace); in sh_exec()
2790 error_info.line = t->funct.functline-shp->st.firstline; in sh_exec()
2792 if(cp || shp->prefix) in sh_exec()
2795 if(shp->prefix) in sh_exec()
2797 cp = shp->prefix; in sh_exec()
2798 shp->prefix = 0; in sh_exec()
2799 npv = nv_open(cp,shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME); in sh_exec()
2800 shp->prefix = cp; in sh_exec()
2807 npv = nv_open(stkptr(stkp,offset),shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME); in sh_exec()
2813 else if((mp=nv_search(fname,shp->bltin_tree,0)) && nv_isattr(mp,BLT_SPC)) in sh_exec()
2816 if(shp->namespace && !shp->prefix && *fname!='.') in sh_exec()
2817 np = sh_fsearch(shp,fname,NV_ADD|HASH_NOSCOPE); in sh_exec()
2820 np = nv_open(fname,sh_subfuntree(shp,1),NV_NOASSIGN|NV_NOARRAY|NV_VARNAME|NV_NOSCOPE); in sh_exec()
2823 if(!shp->mktype) in sh_exec()
2837 shp->last_root = rp->sdict; in sh_exec()
2847 if(shp->funload) in sh_exec()
2849 if(!shp->fpathdict) in sh_exec()
2856 np->nvalue.rp = new_of(struct Ufunction,shp->funload?sizeof(Dtlink_t):0); in sh_exec()
2874 np->nvalue.rp->nspace = shp->namespace; in sh_exec()
2878 np->nvalue.rp->fdict = shp->fun_tree; in sh_exec()
2884 if(shp->funload) in sh_exec()
2888 if(!shp->fpathdict) in sh_exec()
2889 shp->fpathdict = dtopen(&_Rpdisc,Dtobag); in sh_exec()
2890 if(shp->fpathdict) in sh_exec()
2892 dtuserdata(shp->fpathdict,shp,1); in sh_exec()
2893 dtinsert(shp->fpathdict,rp); in sh_exec()
2919 if(shp->inpool) in sh_exec()
2924 error_info.line = t->tst.tstline-shp->st.firstline; in sh_exec()
2928 sh_exec(shp,t->lst.lstlef,OPTIMIZE); in sh_exec()
2929 n = !shp->exitval; in sh_exec()
2937 int savexit = shp->savexit; in sh_exec()
2939 left = sh_macpat(shp,&(t->lst.lstlef->arg),OPTIMIZE); in sh_exec()
2941 right = sh_macpat(shp,&(t->lst.lstrit->arg),((n==TEST_PEQ||n==TEST_PNE)?ARG_EXP:0)|OPTIMIZE); in sh_exec()
2942 shp->savexit = savexit; in sh_exec()
2943 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2945 if(sh_isoption(shp,SH_XTRACE)) in sh_exec()
2947 traceon = sh_trace(shp,NIL(char**),0); in sh_exec()
2964 sh_debug(shp,trap,(char*)0,(char*)0,argv, 0); in sh_exec()
2966 n = test_unop(shp,n,left); in sh_exec()
2984 sh_debug(shp,trap,(char*)0,(char*)0,argv, pattern); in sh_exec()
2986 n = test_binop(shp,n,left,right); in sh_exec()
2999 shp->exitval = ((!n)^negate); in sh_exec()
3001 exitset(shp); in sh_exec()
3008 int exitval = shp->exitval; in sh_exec()
3011 shp->exitval = exitval; in sh_exec()
3013 if(shp->trapnote&SH_SIGALRM) in sh_exec()
3015 shp->trapnote &= ~SH_SIGALRM; in sh_exec()
3016 sh_timetraps(shp); in sh_exec()
3018 if(shp->trapnote || (shp->exitval && sh_isstate(shp,SH_ERREXIT)) && in sh_exec()
3020 sh_chktrap(shp); in sh_exec()
3026 if(sh_isstate(shp,SH_FORKED)) in sh_exec()
3027 sh_done(shp,0); in sh_exec()
3028 if(shp->lastarg!= lastarg && shp->lastarg) in sh_exec()
3029 free(shp->lastarg); in sh_exec()
3033 shp->lastarg = strcpy(lastarg,comn); in sh_exec()
3038 shp->lastarg = strdup(comn); in sh_exec()
3042 exitset(shp); in sh_exec()
3044 if(!shp->inpool && !(OPTIMIZE)) in sh_exec()
3054 if(shp->trapnote&SH_SIGSET) in sh_exec()
3055 sh_exit(shp,SH_EXITSIG|shp->lastsig); in sh_exec()
3057 sh_onstate(shp,SH_INTERACTIVE); in sh_exec()
3058 if(was_monitor && sh_isoption(shp,SH_MONITOR)) in sh_exec()
3059 sh_onstate(shp,SH_MONITOR); in sh_exec()
3061 sh_onstate(shp,SH_ERREXIT); in sh_exec()
3063 return(shp->exitval); in sh_exec()
3088 bool sh_trace(Shell_t *shp,register char *argv[], register int nl) in sh_trace() argument
3094 if(sh_isoption(shp,SH_XTRACE)) in sh_trace()
3098 if(!(cp=nv_getval(sh_scoped(shp,PS4NOD)))) in sh_trace()
3102 shp->intrace = 1; in sh_trace()
3103 sh_offoption(shp,SH_XTRACE); in sh_trace()
3104 cp = sh_mactry(shp,cp); in sh_trace()
3105 sh_onoption(shp,SH_XTRACE); in sh_trace()
3106 shp->intrace = 0; in sh_trace()
3124 if(decl && shp->prefix && cp!=argv0 && *cp!='-') in sh_trace()
3127 cp = shp->prefix; in sh_trace()
3129 sfputr(sfstderr,shp->prefix,'.'); in sh_trace()
3163 pid_t _sh_fork(Shell_t *shp,register pid_t parent,int flags,int *jobid) in _sh_fork() argument
3171 sh_sigcheck(shp); in _sh_fork()
3194 shp->gd->nforks++; in _sh_fork()
3196 job_clear(shp); in _sh_fork()
3200 if(sh_isstate(shp,SH_MONITOR)) in _sh_fork()
3215 if(!sh_isstate(shp,SH_MONITOR) && job.waitall && postid==0) in _sh_fork()
3218 shp->cpid = parent; in _sh_fork()
3223 myjob = job_post(shp,parent,postid); in _sh_fork()
3237 if(shp->comsub==1 && usepipe) in _sh_fork()
3242 if(shp->vexp->cur>restorevex) in _sh_fork()
3243 sh_vexrestore(shp,restorevex); in _sh_fork()
3245 if(shp->topfd > restorefd) in _sh_fork()
3246 sh_iorestore(shp,restorefd,0); in _sh_fork()
3247 sh_iounpipe(shp); in _sh_fork()
3255 shp->outpipepid = ((flags&FPOU)?getpid():0); in _sh_fork()
3257 if(shp->trapnote&SH_SIGTERM) in _sh_fork()
3258 sh_exit(shp,SH_EXITSIG|SIGTERM); in _sh_fork()
3259 shp->gd->nforks=0; in _sh_fork()
3263 sh_offstate(shp,SH_MONITOR); in _sh_fork()
3264 if(sh_isstate(shp,SH_MONITOR)) in _sh_fork()
3287 shp->login_sh = 0; in _sh_fork()
3288 sh_offoption(shp,SH_LOGIN_SHELL); in _sh_fork()
3289 sh_onstate(shp,SH_FORKED); in _sh_fork()
3290 sh_onstate(shp,SH_NOLOG); in _sh_fork()
3291 if (shp->fn_reset) in _sh_fork()
3292 shp->fn_depth = shp->fn_reset = 0; in _sh_fork()
3299 sh_sigreset(shp,2); in _sh_fork()
3300 shp->subshell = 0; in _sh_fork()
3301 shp->comsub = 0; in _sh_fork()
3302 shp->spid = 0; in _sh_fork()
3303 if((flags&FAMP) && shp->coutpipe>1) in _sh_fork()
3304 sh_close(shp->coutpipe); in _sh_fork()
3305 sig = shp->savesig; in _sh_fork()
3306 shp->savesig = 0; in _sh_fork()
3309 sh_sigcheck(shp); in _sh_fork()
3314 pid_t sh_fork(Shell_t *shp,int flags, int *jobid) in sh_fork() argument
3318 if(!shp->pathlist) in sh_fork()
3319 path_get(shp,""); in sh_fork()
3321 shp->trapnote &= ~SH_SIGTERM; in sh_fork()
3325 while(_sh_fork(shp,parent=fork(),flags,jobid) < 0); in sh_fork()
3328 if(parent==0 && shp->vex) in sh_fork()
3330 spawnvex_apply(shp->vex,0,0); in sh_fork()
3331 spawnvex_apply(shp->vexp,0,SPAWN_RESET); in sh_fork()
3351 Shell_t *shp = ((struct Tdata*)data)->sh; in local_exports() local
3356 …if((cp = nv_getval(np)) && (mp = nv_search(nv_name(np), shp->var_tree, NV_ADD|HASH_NOSCOPE)) && nv… in local_exports()
3363 Sfdouble_t sh_mathfun(Shell_t *shp,void *fp, int nargs, Sfdouble_t *arg) in sh_mathfun() argument
3381 *nr++ = mp = nv_namptr(shp->mathnodes,i); in sh_mathfun()
3388 sh_funscope(shp,1,argv,0,&funenv,0); in sh_mathfun()
3398 static void sh_funct(Shell_t *shp,Namval_t *np,int argn, char *argv[],struct argnod *envlist,int ex… in sh_funct() argument
3403 int level, pipepid=shp->pipepid; in sh_funct()
3404 shp->pipepid = 0; in sh_funct()
3407 lp = init_level(shp,0); in sh_funct()
3408 if((struct sh_scoped*)shp->topscope != shp->st.self) in sh_funct()
3409 sh_setscope(shp,shp->topscope); in sh_funct()
3410 level = lp->maxlevel = shp->dot_depth + shp->fn_depth+1; in sh_funct()
3412 shp->st.lineno = error_info.line; in sh_funct()
3414 if(nv_isattr(np,NV_FPOSIX) && !sh_isoption(shp,SH_BASH)) in sh_funct()
3417 int loopcnt = shp->st.loopcnt; in sh_funct()
3418 shp->posix_fun = np; in sh_funct()
3421 shp->st.funname = nv_name(np); in sh_funct()
3422 shp->last_root = nv_dict(DOTSHNOD); in sh_funct()
3426 shp->st.loopcnt = 0; in sh_funct()
3427 b_dot_cmd(argn+1,argv-1,&shp->bltindata); in sh_funct()
3428 shp->st.loopcnt = loopcnt; in sh_funct()
3436 sh_funscope(shp,argn,argv,0,&fun,execflg); in sh_funct()
3440 Shscope_t *sp = sh_getscope(shp,0,SEEK_END); in sh_funct()
3441 sh_setscope(shp,sp); in sh_funct()
3445 shp->last_root = nv_dict(DOTSHNOD); in sh_funct()
3447 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_funct()
3451 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_funct()
3452 shp->pipepid = pipepid; in sh_funct()
3466 int sh_fun_20120720(Shell_t *shp,Namval_t *np, Namval_t *nq, char *argv[]) in sh_fun_20120720() argument
3473 char *prefix = shp->prefix; in sh_fun_20120720()
3478 if((offset=stktell(shp->stk))>0) in sh_fun_20120720()
3479 base=stkfreeze(shp->stk,0); in sh_fun_20120720()
3480 shp->prefix = 0; in sh_fun_20120720()
3490 mode = set_instance(shp,nq,&node, &nr); in sh_fun_20120720()
3494 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_fun_20120720()
3495 Shbltin_t *bp = &shp->bltindata; in sh_fun_20120720()
3496 sh_pushcontext(shp,buffp,SH_JMPCMD); in sh_fun_20120720()
3506 shp->exitval = 0; in sh_fun_20120720()
3507 shp->exitval = ((Shbltin_f)funptr(np))(n,argv,bp); in sh_fun_20120720()
3509 sh_popcontext(shp,buffp); in sh_fun_20120720()
3511 siglongjmp(*shp->jmplist,jmpval); in sh_fun_20120720()
3514 sh_funct(shp,np,n,argv,(struct argnod*)0,sh_isstate(shp,SH_ERREXIT)); in sh_fun_20120720()
3519 stkset(shp->stk,base,offset); in sh_fun_20120720()
3520 shp->prefix = prefix; in sh_fun_20120720()
3521 return(shp->exitval); in sh_fun_20120720()
3546 static void coproc_init(Shell_t *shp, int pipes[]) in coproc_init() argument
3549 if(shp->coutpipe>=0 && shp->cpid) in coproc_init()
3551 shp->cpid = 0; in coproc_init()
3552 if(shp->cpipe[0]<=0 || shp->cpipe[1]<=0) in coproc_init()
3555 sh_pclose(shp->cpipe); in coproc_init()
3556 sh_pipe(shp->cpipe); in coproc_init()
3557 if((outfd=shp->cpipe[1]) < 10) in coproc_init()
3559 int fd=sh_fcntl(shp->cpipe[1],F_dupfd_cloexec,10); in coproc_init()
3562 shp->fdstatus[fd] = (shp->fdstatus[outfd]&~IOCLEX); in coproc_init()
3564 shp->fdstatus[outfd] = IOCLOSE; in coproc_init()
3565 shp->cpipe[1] = fd; in coproc_init()
3568 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; in coproc_init()
3570 shp->outpipe = shp->cpipe; in coproc_init()
3571 sh_pipe(shp->inpipe=pipes); in coproc_init()
3572 shp->coutpipe = shp->inpipe[1]; in coproc_init()
3573 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; in coproc_init()
3584 static int run_subshell(Shell_t *shp,const Shnode_t *t,pid_t grp) in run_subshell() argument
3587 register int i, fd, trace = sh_isoption(shp,SH_XTRACE); in run_subshell()
3594 arglist[0] = error_info.id?error_info.id:shp->shname; in run_subshell()
3602 sh_offoption(shp,SH_XTRACE); in run_subshell()
3604 sh_trap(shp,prolog,0); in run_subshell()
3605 nv_scan(shp->fun_tree, print_fun, (void*)0,0, 0); in run_subshell()
3606 if(shp->st.dolc>0) in run_subshell()
3609 char **argv = shp->st.dolv+1; in run_subshell()
3615 pin = (shp->inpipe?shp->inpipe[1]:0); in run_subshell()
3616 pout = (shp->outpipe?shp->outpipe[0]:0); in run_subshell()
3619 if(shp->fdstatus[i]&IOCLEX && i!=pin && i!=pout) in run_subshell()
3629 sh_onoption(shp,SH_XTRACE); in run_subshell()
3642 if(!shp->gd->shpath) in run_subshell()
3643 shp->gd->shpath = pathshell(); in run_subshell()
3644 pid = spawnveg(shp->shpath,arglist,envlist,grp); in run_subshell()
3648 if(shp->fdstatus[i]&IOCLEX && i!=pin && i!=pout) in run_subshell()
3657 static void sigreset(Shell_t *shp,int mode) in sigreset() argument
3660 register int sig=shp->st.trapmax; in sigreset()
3671 if(shp->sigflag[sig]&SH_SIGOFF) in sigreset()
3673 if((trap=shp->st.trapcom[sig]) && *trap==0) in sigreset()
3681 static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,int flag) in sh_ntfork() argument
3686 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_ntfork()
3687 int otype=0, jmpval,jobfork=0, lineno=shp->st.firstline; in sh_ntfork()
3728 if(!np && path && !nv_search(path,shp->fun_tree,0)) in sh_ntfork()
3732 sh_pushcontext(shp,buffp,SH_JMPIO); in sh_ntfork()
3735 if((otype&FINT) && !sh_isstate(shp,SH_MONITOR)) in sh_ntfork()
3739 if(!shp->st.ioset) in sh_ntfork()
3741 sh_iosave(shp,0,buffp->topfd,(char*)0); in sh_ntfork()
3742 sh_iorenumber(shp,sh_open(e_devnull,O_RDONLY),0); in sh_ntfork()
3747 int fd = shp->inpipe[1]; in sh_ntfork()
3749 sh_vexsave(shp,0,shp->inpipe[0],0,0); in sh_ntfork()
3751 sh_iosave(shp,0,buffp->topfd,(char*)0); in sh_ntfork()
3752 sh_iorenumber(shp,shp->inpipe[0],0); in sh_ntfork()
3758 if(shp->outpipe[2] > 20000) in sh_ntfork()
3759 sh_coaccept(shp,shp->outpipe,1); in sh_ntfork()
3762 sh_vexsave(shp,1,shp->outpipe[1],0,0); in sh_ntfork()
3764 sh_iosave(shp,1,buffp->topfd,(char*)0); in sh_ntfork()
3765 sh_iorenumber(shp,sh_dup(shp->outpipe[1]),1); in sh_ntfork()
3770 sh_redirect(shp,t->fork.forkio,0); in sh_ntfork()
3774 if(sh_isstate(shp,SH_MONITOR) && (job.jobcontrol || (otype&FAMP))) in sh_ntfork()
3782 spawnpid = run_subshell(shp,t,grp); in sh_ntfork()
3786 sh_exec(shp,tchild,SH_NTFORK); in sh_ntfork()
3791 sh_popcontext(shp,buffp); in sh_ntfork()
3792 if((otype&FINT) && !sh_isstate(shp,SH_MONITOR)) in sh_ntfork()
3799 sh_iorestore(shp,buffp->topfd,jmpval); in sh_ntfork()
3800 if(shp->vexp->cur>buffp->vexi) in sh_ntfork()
3801 sh_vexrestore(shp,buffp->vexi); in sh_ntfork()
3806 _sh_fork(shp,spawnpid,otype,jobid); in sh_ntfork()
3815 siglongjmp(*shp->jmplist,jmpval); in sh_ntfork()
3818 sh_close(shp->coutpipe); in sh_ntfork()
3819 sh_close(shp->cpipe[1]); in sh_ntfork()
3820 shp->cpipe[1] = -1; in sh_ntfork()
3821 shp->coutpipe = -1; in sh_ntfork()
3823 shp->exitval = 0; in sh_ntfork()
3827 sh_pushcontext(shp,buffp,SH_JMPCMD); in sh_ntfork()
3832 if((otype&FINT) && !sh_isstate(shp,SH_MONITOR)) in sh_ntfork()
3840 shp->errorfd = error_info.fd; in sh_ntfork()
3842 sh_redirect(shp,t->com.comio,io_usevex(t->com.comio)); in sh_ntfork()
3844 sh_redirect(shp,t->com.comio,0); in sh_ntfork()
3851 sh_scope(shp,t->com.comset,0); in sh_ntfork()
3856 if((np=nv_search(path,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp) in sh_ntfork()
3858 else if(path_absolute(shp,path,NIL(Pathcomp_t*))) in sh_ntfork()
3860 path = stkptr(shp->stk,PATH_OFFSET); in sh_ntfork()
3861 stkfreeze(shp->stk,0); in sh_ntfork()
3865 pp=path_get(shp,path); in sh_ntfork()
3876 else if(sh_isoption(shp,SH_RESTRICTED)) in sh_ntfork()
3883 arge = sh_envgen(shp); in sh_ntfork()
3885 shp->st.firstline = lineno; in sh_ntfork()
3886 shp->exitval = 0; in sh_ntfork()
3888 if(sh_isstate(shp,SH_MONITOR) && (job.jobcontrol || (otype&FAMP))) in sh_ntfork()
3898 sigreset(shp,0); /* set signals to ignore */ in sh_ntfork()
3901 for(pp=path_get(shp,argv[0]); pp && !pp->lib ; pp=pp->next); in sh_ntfork()
3904 spawnpid = path_spawn(shp,path,argv,arge,pp,(grp<<1)|1); in sh_ntfork()
3914 sfprintf(shp->strbuf,"/dev/fd/%d",fd); in sh_ntfork()
3915 if(stat(devfd=sfstruse(shp->strbuf),&statb)>=0) in sh_ntfork()
3918 if(!shp->gd->shpath) in sh_ntfork()
3919 shp->gd->shpath = pathshell(); in sh_ntfork()
3920 spawnpid = path_spawn(shp,shp->gd->shpath,&argv[-1],arge,pp,(grp<<1)|1); in sh_ntfork()
3928 if(spawnpid < 0) switch(errno=shp->path_err) in sh_ntfork()
3937 exitset(shp); in sh_ntfork()
3938 sh_popcontext(shp,buffp); in sh_ntfork()
3942 sigreset(shp,1); /* restore ignored signals */ in sh_ntfork()
3945 sh_unscope(shp); in sh_ntfork()
3947 sh_setlist(shp,t->com.comset,NV_EXPORT|NV_IDENT|NV_ASSIGN,0); in sh_ntfork()
3951 sh_iorestore(shp,buffp->topfd,jmpval); in sh_ntfork()
3953 if(shp->vexp->cur > buffp->vexi) in sh_ntfork()
3954 sh_vexrestore(shp,buffp->vexi); in sh_ntfork()
3959 siglongjmp(*shp->jmplist,jmpval); in sh_ntfork()
3962 _sh_fork(shp,spawnpid,otype,jobid); in sh_ntfork()
3999 int sh_funscope_20120720(Shell_t *shp,int argn, char *argv[],int(*fun)(void*),void *arg,int execflg) in sh_funscope_20120720() argument
4004 struct sh_scoped savst, *prevscope = shp->st.self; in sh_funscope_20120720()
4011 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_funscope_20120720()
4012 Namval_t *nspace = shp->namespace; in sh_funscope_20120720()
4013 Dt_t *last_root = shp->last_root; in sh_funscope_20120720()
4015 options = shp->options; in sh_funscope_20120720()
4016 if(shp->fn_depth==0) in sh_funscope_20120720()
4017 shp->glob_options = shp->options; in sh_funscope_20120720()
4019 shp->options = shp->glob_options; in sh_funscope_20120720()
4021 shp->st.lineno = error_info.line; in sh_funscope_20120720()
4023 *prevscope = shp->st; in sh_funscope_20120720()
4024 sh_offoption(shp,SH_ERREXIT); in sh_funscope_20120720()
4025 shp->st.prevst = prevscope; in sh_funscope_20120720()
4026 shp->st.self = &savst; in sh_funscope_20120720()
4027 shp->topscope = (Shscope_t*)shp->st.self; in sh_funscope_20120720()
4028 shp->st.opterror = shp->st.optchar = 0; in sh_funscope_20120720()
4029 shp->st.optindex = 1; in sh_funscope_20120720()
4030 shp->st.loopcnt = 0; in sh_funscope_20120720()
4034 shp->st.real_fun = (fp->node)->nvalue.rp; in sh_funscope_20120720()
4037 prevscope->save_tree = shp->var_tree; in sh_funscope_20120720()
4038 n = dtvnext(prevscope->save_tree)!= (shp->namespace?shp->var_base:0); in sh_funscope_20120720()
4039 sh_scope(shp,envlist,1); in sh_funscope_20120720()
4044 tdata.sh = shp; in sh_funscope_20120720()
4048 shp->st.save_tree = shp->var_tree; in sh_funscope_20120720()
4052 sh_onoption(shp,SH_XTRACE); in sh_funscope_20120720()
4054 sh_offoption(shp,SH_XTRACE); in sh_funscope_20120720()
4056 shp->st.cmdname = argv[0]; in sh_funscope_20120720()
4058 if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0]) in sh_funscope_20120720()
4061 memcpy(savstak=stkalloc(shp->stk,nsig),(char*)&shp->st.trapcom[0],nsig); in sh_funscope_20120720()
4063 sh_sigreset(shp,0); in sh_funscope_20120720()
4064 argsav = sh_argnew(shp,argv,&saveargfor); in sh_funscope_20120720()
4065 sh_pushcontext(shp,buffp,SH_JMPFUN); in sh_funscope_20120720()
4068 shp->st.var_local = shp->var_tree; in sh_funscope_20120720()
4071 shp->st.filename = fp->node->nvalue.rp->fname; in sh_funscope_20120720()
4072 shp->st.funname = nv_name(fp->node); in sh_funscope_20120720()
4073 shp->last_root = nv_dict(DOTSHNOD); in sh_funscope_20120720()
4074 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_funscope_20120720()
4075 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_funscope_20120720()
4080 if(shp->fn_depth++ > MAXDEPTH) in sh_funscope_20120720()
4082 shp->toomany = 1; in sh_funscope_20120720()
4083 siglongjmp(*shp->jmplist,SH_JMPERRFN); in sh_funscope_20120720()
4089 char **args = shp->st.real_fun->argv; in sh_funscope_20120720()
4093 shp->last_root = 0; in sh_funscope_20120720()
4096 np = nv_search(args[r],shp->var_tree,HASH_NOSCOPE|NV_ADD); in sh_funscope_20120720()
4111 sh_exec(shp,(Shnode_t*)(nv_funtree((fp->node))),execflg|SH_ERREXIT); in sh_funscope_20120720()
4112 r = shp->exitval; in sh_funscope_20120720()
4115 if(shp->topscope != (Shscope_t*)shp->st.self) in sh_funscope_20120720()
4116 sh_setscope(shp,shp->topscope); in sh_funscope_20120720()
4117 if(--shp->fn_depth==1 && jmpval==SH_JMPERRFN) in sh_funscope_20120720()
4119 sh_popcontext(shp,buffp); in sh_funscope_20120720()
4120 sh_unscope(shp); in sh_funscope_20120720()
4121 shp->namespace = nspace; in sh_funscope_20120720()
4122 shp->var_tree = (Dt_t*)prevscope->save_tree; in sh_funscope_20120720()
4123 sh_argreset(shp,argsav,saveargfor); in sh_funscope_20120720()
4124 trap = shp->st.trapcom[0]; in sh_funscope_20120720()
4125 shp->st.trapcom[0] = 0; in sh_funscope_20120720()
4126 sh_sigreset(shp,1); in sh_funscope_20120720()
4127 shp->st = *prevscope; in sh_funscope_20120720()
4128 shp->topscope = (Shscope_t*)prevscope; in sh_funscope_20120720()
4129 nv_getval(sh_scoped(shp,IFSNOD)); in sh_funscope_20120720()
4131 memcpy((char*)&shp->st.trapcom[0],savstak,nsig); in sh_funscope_20120720()
4132 shp->trapnote=0; in sh_funscope_20120720()
4134 stkset(shp->stk,savstak,0); in sh_funscope_20120720()
4135 shp->options = options; in sh_funscope_20120720()
4136 shp->last_root = last_root; in sh_funscope_20120720()
4138 siglongjmp(*shp->jmplist,jmpval); in sh_funscope_20120720()
4141 sh_trap(shp,trap,0); in sh_funscope_20120720()
4145 r=shp->exitval; in sh_funscope_20120720()
4146 …if(!sh_isstate(shp,SH_IOPROMPT) && r>SH_EXITSIG && ((r&SH_EXITMASK)==SIGINT || ((r&SH_EXITMASK)==S… in sh_funscope_20120720()
4150 sh_chktrap(shp); in sh_funscope_20120720()
4151 siglongjmp(*shp->jmplist,jmpval); in sh_funscope_20120720()
4165 int sh_eval_20120720(Shell_t *shp,register Sfio_t *iop, int mode) in sh_eval_20120720() argument
4168 struct slnod *saveslp = shp->st.staklist; in sh_eval_20120720()
4170 struct checkpt *pp = (struct checkpt*)shp->jmplist; in sh_eval_20120720()
4171 struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); in sh_eval_20120720()
4175 int binscript=shp->binscript; in sh_eval_20120720()
4176 char comsub = shp->comsub; in sh_eval_20120720()
4179 shp->binscript = 0; in sh_eval_20120720()
4180 shp->comsub = 0; in sh_eval_20120720()
4185 shp->fn_reset = 1; in sh_eval_20120720()
4187 sh_pushcontext(shp,buffp,SH_JMPEVAL); in sh_eval_20120720()
4194 lineno = shp->inlineno; in sh_eval_20120720()
4195 if(traceon=sh_isoption(shp,SH_XTRACE)) in sh_eval_20120720()
4196 sh_offoption(shp,SH_XTRACE); in sh_eval_20120720()
4198 t = (Shnode_t*)sh_parse(shp,iop,(mode&(SH_READEVAL|SH_FUNEVAL))?mode&SH_FUNEVAL:SH_NL); in sh_eval_20120720()
4207 if(!sh_isoption(shp,SH_VERBOSE)) in sh_eval_20120720()
4208 sh_offstate(shp,SH_VERBOSE); in sh_eval_20120720()
4209 if((mode&~SH_FUNEVAL) && shp->gd->hist_ptr) in sh_eval_20120720()
4211 hist_flush(shp->gd->hist_ptr); in sh_eval_20120720()
4214 sh_exec(shp,t,sh_isstate(shp,SH_ERREXIT)|sh_isstate(shp,SH_NOFORK)|(mode&~SH_FUNEVAL)); in sh_eval_20120720()
4218 sh_popcontext(shp,buffp); in sh_eval_20120720()
4219 shp->binscript = binscript; in sh_eval_20120720()
4220 shp->comsub = comsub; in sh_eval_20120720()
4222 sh_onoption(shp,SH_XTRACE); in sh_eval_20120720()
4224 shp->inlineno = lineno; in sh_eval_20120720()
4229 sh_freeup(shp); in sh_eval_20120720()
4230 shp->st.staklist = saveslp; in sh_eval_20120720()
4231 shp->fn_reset = 0; in sh_eval_20120720()
4233 siglongjmp(*shp->jmplist,jmpval); in sh_eval_20120720()
4234 return(shp->exitval); in sh_eval_20120720()
4243 int sh_run_20120720(Shell_t *shp,int argn, char *argv[]) in sh_run_20120720() argument
4246 register struct comnod *t = (struct comnod*)stkalloc(shp->stk,sizeof(struct comnod)); in sh_run_20120720()
4247 int savtop = stktell(shp->stk); in sh_run_20120720()
4251 bltindata = shp->bltindata; in sh_run_20120720()
4254 …dp = (struct dolnod*)stkalloc(shp->stk,(unsigned)sizeof(struct dolnod) + ARG_SPARE*sizeof(char*) +… in sh_run_20120720()
4260 t->comnamp = (void*)nv_bfsearch(argv[0],shp->fun_tree,(Namval_t**)&t->comnamq,(char**)0); in sh_run_20120720()
4261 argn=sh_exec(shp,(Shnode_t*)t,sh_isstate(shp,SH_ERREXIT)); in sh_run_20120720()
4263 shp->bltindata = bltindata; in sh_run_20120720()
4264 if(savptr!=stkptr(shp->stk,0)) in sh_run_20120720()
4265 stkset(shp->stk,savptr,savtop); in sh_run_20120720()
4267 stkseek(shp->stk,savtop); in sh_run_20120720()