Lines Matching refs:shp

105 static int p_time(Shell_t *shp, Sfio_t *out, const char *format, clock_t *tm)  in p_time()  argument
110 Stk_t *stkp = shp->stk; in p_time()
395 int sh_debug(Shell_t *shp, const char *trap, const char *name, const char *subscript, char *const a… in sh_debug() argument
397 Stk_t *stkp=shp->stk; in sh_debug()
405 if(shp->indebug) in sh_debug()
407 shp->indebug = 1; in sh_debug()
438 shp->st.lineno = error_info.line; in sh_debug()
439 level = shp->fn_depth+shp->dot_depth; in sh_debug()
444 savst = shp->st; in sh_debug()
445 shp->st.trap[SH_DEBUGTRAP] = 0; in sh_debug()
448 shp->indebug = 0; in sh_debug()
449 if(shp->st.cmdname) in sh_debug()
450 error_info.id = shp->st.cmdname; in sh_debug()
451 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_debug()
452 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_debug()
453 shp->st = savst; in sh_debug()
467 Shell_t *shp = sh_getinterp(); in sh_eval() local
468 struct slnod *saveslp = shp->st.staklist; in sh_eval()
470 struct checkpt *pp = (struct checkpt*)shp->jmplist; in sh_eval()
474 int binscript=shp->binscript; in sh_eval()
476 shp->binscript = 0; in sh_eval()
481 shp->fn_reset = 1; in sh_eval()
490 lineno = shp->inlineno; in sh_eval()
494 t = (Shnode_t*)sh_parse(shp,iop,(mode&(SH_READEVAL|SH_FUNEVAL))?mode&SH_FUNEVAL:SH_NL); in sh_eval()
505 if((mode&~SH_FUNEVAL) && shp->hist_ptr) in sh_eval()
507 hist_flush(shp->hist_ptr); in sh_eval()
515 shp->binscript = binscript; in sh_eval()
519 shp->inlineno = lineno; in sh_eval()
522 sh_freeup(shp); in sh_eval()
523 shp->st.staklist = saveslp; in sh_eval()
524 shp->fn_reset = 0; in sh_eval()
526 siglongjmp(*shp->jmplist,jmpval); in sh_eval()
527 return(shp->exitval); in sh_eval()
531 static int pipe_exec(Shell_t* shp,int pv[], Shnode_t *t, int errorflg) in pipe_exec() argument
544 pv[0] = shp->lim.open_max; in pipe_exec()
545 shp->fdstatus[pv[0]] = IOREAD|IODUP|IOSEEK; in pipe_exec()
546 pv[1] = shp->lim.open_max+1; in pipe_exec()
547 shp->fdstatus[pv[1]] = IOWRITE|IOSEEK; in pipe_exec()
549 shp->sftable[shp->lim.open_max+1] = iop; in pipe_exec()
552 sh_iosave(shp,0,shp->topfd,(char*)0); in pipe_exec()
553 sh_iosave(shp,1,shp->topfd,(char*)0); in pipe_exec()
558 sh_iorenumber(shp,shp->inpipe[0],0); in pipe_exec()
559 sh_iorenumber(shp,shp->lim.open_max+1,1); in pipe_exec()
566 shp->sftable[pv[0]] = iop; in pipe_exec()
567 shp->fdstatus[pv[0]] = IOREAD|IODUP|IOSEEK; in pipe_exec()
570 sh_iorestore(shp,buff.topfd,jmpval); in pipe_exec()
572 siglongjmp(*shp->jmplist,jmpval); in pipe_exec()
611 static int set_instance(Shell_t *shp,Namval_t *nq, Namval_t *node, struct Namref *nr) in set_instance() argument
619 shp->instance = 1; in set_instance()
622 shp->instance = 0; in set_instance()
655 register Shell_t *shp = &sh; in sh_exec() local
656 Stk_t *stkp = shp->stk; in sh_exec()
658 if(t && !shp->st.execbrk && !sh_isoption(SH_NOEXEC)) in sh_exec()
671 int topfd = shp->topfd; in sh_exec()
695 if(!shp->intrap) in sh_exec()
696 shp->oldexit=shp->exitval; in sh_exec()
697 shp->exitval=0; in sh_exec()
698 shp->lastsig = 0; in sh_exec()
699 shp->lastpath = 0; in sh_exec()
709 shp->bltindata.invariant = type>>(COMBITS+2); in sh_exec()
712 error_info.line = t->com.comline-shp->st.firstline; in sh_exec()
713 com = sh_argbuild(shp,&argn,&(t->com),OPTIMIZE); in sh_exec()
724 shp->xargexit = 0; in sh_exec()
727 register int n = b_command(0,com,&shp->bltindata); in sh_exec()
734 np = nv_bfsearch(com0, shp->bltin_tree, &nq, &cp); in sh_exec()
736 if(shp->xargexit) in sh_exec()
738 shp->xargmin -= command; in sh_exec()
739 shp->xargmax -= command; in sh_exec()
742 shp->xargmin = 0; in sh_exec()
745 np = dtsearch(shp->fun_tree,np); in sh_exec()
750 Dt_t *root = command?shp->bltin_tree:shp->fun_tree; in sh_exec()
753 if(shp->namespace && !nq && !cp) in sh_exec()
756 sfputr(stkp,nv_name(shp->namespace),-1); in sh_exec()
767 if(shp->envlist = argp = t->com.comset) in sh_exec()
784 if(!shp->st.var_local) in sh_exec()
786 sh_scope(shp,(struct argnod*)0,0); in sh_exec()
787 shp->st.var_local = shp->var_tree; in sh_exec()
798 shp->typeinit = np; in sh_exec()
807 else if(!shp->typeinit && (checkopt(com,'L') || checkopt(com,'R') || checkopt(com,'Z'))) in sh_exec()
812 shp->prefix = NV_CLASS; in sh_exec()
817 if((shp->fn_depth && !shp->prefix) || np==SYSLOCAL) in sh_exec()
831 if(np==shp->typeinit) in sh_exec()
832 shp->typeinit = 0; in sh_exec()
833 shp->envlist = argp; in sh_exec()
837 last_table = shp->last_table; in sh_exec()
838 shp->last_table = 0; in sh_exec()
863 sh_redirect(shp,io,SH_SHOWME); in sh_exec()
868 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
870 int n = sh_debug(shp,trap,(char*)0,(char*)0, com, ARG_RAW); in sh_exec()
871 if(n==255 && shp->fn_depth+shp->dot_depth) in sh_exec()
884 sfsync(shp->outpool); in sh_exec()
885 shp->lastpath = 0; in sh_exec()
890 error_info.line = t->com.comline-shp->st.firstline; in sh_exec()
891 if((np=nv_search(com0,shp->fun_tree,0)) && !np->nvalue.ip) in sh_exec()
893 Namval_t *mp=nv_search(com0,shp->bltin_tree,0); in sh_exec()
900 if((np=nv_search(com0,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp) in sh_exec()
901 np=nv_search(nv_getval(np),shp->bltin_tree,0); in sh_exec()
922 bp = &shp->bltindata; in sh_exec()
956 type = (execflg && !shp->subshell && !shp->st.trapcom[0]); in sh_exec()
957 sh_redirect(shp,io,type); in sh_exec()
965 if(!shp->pwd) in sh_exec()
967 if(shp->pwd) in sh_exec()
975 save_prompt = shp->nextprompt; in sh_exec()
976 shp->nextprompt = 0; in sh_exec()
981 sh_scope(shp,argp,0); in sh_exec()
987 shp->exitval = 0; in sh_exec()
988 shp->bltinfun = funptr(np); in sh_exec()
996 if(shp->subshell && nv_isattr(np,BLT_NOSFIO)) in sh_exec()
998 if(execflg && !shp->subshell && in sh_exec()
999 … !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && shp->fn_depth==0 && !nv_isattr(np,BLT_ENV)) in sh_exec()
1003 for(fd=0; fd < shp->lim.open_max; fd++) in sh_exec()
1004 if((shp->fdstatus[fd]&IOCLEX)&&fd!=shp->infd) in sh_exec()
1008 shp->exitval = (*shp->bltinfun)(argn,com,(void*)bp); in sh_exec()
1011 ((Shnode_t*)t)->com.comstate = shp->bltindata.data; in sh_exec()
1013 if(!nv_isattr(np,BLT_EXIT) && shp->exitval!=SH_RUNPROG) in sh_exec()
1014 shp->exitval &= SH_EXITMASK; in sh_exec()
1024 if(shp->hist_ptr && item->strm == shp->hist_ptr->histfp) in sh_exec()
1025 hist_close(shp->hist_ptr); in sh_exec()
1030 if(shp->bltinfun && (error_info.flags&ERROR_NOTIFY)) in sh_exec()
1031 (*shp->bltinfun)(-2,com,(void*)bp); in sh_exec()
1042 if(bp->nosfio && shp->pwd) in sh_exec()
1048 chdir(shp->pwd); in sh_exec()
1054 sfpool(sfstderr,shp->outpool,SF_WRITE); in sh_exec()
1056 shp->nextprompt = save_prompt; in sh_exec()
1061 shp->bltinfun = 0; in sh_exec()
1071 sh_unscope(shp); in sh_exec()
1075 if((shp->topfd>topfd) && !(shp->subshell && np==SYSEXEC)) in sh_exec()
1076 sh_iorestore(shp,topfd,jmpval); in sh_exec()
1078 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1083 if(shp->exitval >=0) in sh_exec()
1102 np = nv_search(com0,shp->fun_tree,HASH_NOSCOPE); in sh_exec()
1109 shp->exitval = ERROR_NOEXEC; in sh_exec()
1114 shp->exitval = ERROR_NOENT; in sh_exec()
1125 shp->last_table = last_table; in sh_exec()
1126 mode = set_instance(shp,nq,&node,&nr); in sh_exec()
1130 indx = shp->topfd; in sh_exec()
1137 indx = sh_redirect(shp,io,execflg); in sh_exec()
1138 sh_funct(shp,np,argn,com,t->com.comset,(flags&~OPTIMIZE_FLAG)); in sh_exec()
1145 sh_iorestore(shp,indx,jmpval); in sh_exec()
1152 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1168 if(shp->subshell) in sh_exec()
1170 if(shp->subshare) in sh_exec()
1176 !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && in sh_exec()
1177 ((struct checkpt*)shp->jmplist)->mode!=SH_JMPEVAL && in sh_exec()
1179 !shp->subshell && shp->fn_depth==0 && in sh_exec()
1182 if(sh_isstate(SH_PROFILE) || shp->dot_depth) in sh_exec()
1209 coproc_init(shp,pipes); in sh_exec()
1213 parent = sh_ntfork(shp,t,com,&jobid,ntflag); in sh_exec()
1222 parent = sh_ntfork(shp,t,com,&jobid,ntflag); in sh_exec()
1226 if((parent = sh_ntfork(shp,t,com,&jobid,ntflag))<=0) in sh_exec()
1247 sh_close(shp->inpipe[0]); in sh_exec()
1249 shp->bckpid = parent; in sh_exec()
1252 if(shp->topfd > topfd) in sh_exec()
1253 sh_iorestore(shp,topfd,0); in sh_exec()
1256 if(!(shp->sigflag[SIGINT]&(SH_SIGFAULT|SH_SIGOFF))) in sh_exec()
1258 shp->trapnote |= SH_SIGIGNORE; in sh_exec()
1260 if(execflg && shp->subshell && !shp->subshare) in sh_exec()
1262 shp->spid = parent; in sh_exec()
1265 else if(shp->pipepid) in sh_exec()
1266 shp->pipepid = parent; in sh_exec()
1271 shp->trapnote &= ~SH_SIGIGNORE; in sh_exec()
1272 if(shp->exitval == (SH_EXITSIG|SIGINT)) in sh_exec()
1308 if(!shp->st.ioset) in sh_exec()
1322 sh_iorenumber(shp,shp->inpipe[0],0); in sh_exec()
1324 sh_close(shp->inpipe[1]); in sh_exec()
1328 sh_iorenumber(shp,shp->outpipe[1],1); in sh_exec()
1329 sh_pclose(shp->outpipe); in sh_exec()
1332 error_info.line = t->fork.forkline-shp->st.firstline; in sh_exec()
1333 if(shp->topfd) in sh_exec()
1334 sh_iounsave(shp); in sh_exec()
1335 topfd = shp->topfd; in sh_exec()
1336 sh_redirect(shp,t->tre.treio,1); in sh_exec()
1337 if(shp->topfd > topfd) in sh_exec()
1348 sh_iorestore(shp,topfd,SH_JMPCMD); in sh_exec()
1349 sh_done(shp,(shp->exitval&SH_EXITSIG)?(shp->exitval&SH_EXITMASK):0); in sh_exec()
1366 sh_freeup(shp); in sh_exec()
1372 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1373 sh_done(shp,0); in sh_exec()
1387 if(shp->subshell) in sh_exec()
1394 sh_iosave(shp,0,shp->topfd,(char*)0); in sh_exec()
1395 shp->pipepid = simple; in sh_exec()
1396 sh_iorenumber(shp,shp->inpipe[0],0); in sh_exec()
1408 error_info.line = t->fork.forkline-shp->st.firstline; in sh_exec()
1412 sh_redirect(shp,t->fork.forkio,execflg); in sh_exec()
1417 sfsync(shp->outpool); in sh_exec()
1419 sh_iorestore(shp,buff.topfd,jmpval); in sh_exec()
1425 type = shp->exitval; in sh_exec()
1429 if(shp->pipepid>1) in sh_exec()
1431 job_wait(shp->pipepid); in sh_exec()
1432 type = shp->exitval; in sh_exec()
1437 shp->exitval = type; in sh_exec()
1439 shp->pipepid = 0; in sh_exec()
1440 shp->st.ioset = 0; in sh_exec()
1448 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1455 …if(!shp->subshell && !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && (flags&sh_state(SH_NOFORK… in sh_exec()
1460 shp->st.otrapcom = 0; in sh_exec()
1461 if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0]) in sh_exec()
1464 memcpy(savsig=malloc(nsig),(char*)&shp->st.trapcom[0],nsig); in sh_exec()
1465 shp->st.otrapcom = (char**)savsig; in sh_exec()
1474 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1475 sh_done(shp,0); in sh_exec()
1494 if(shp->subshell) in sh_exec()
1496 if(shp->subshare) in sh_exec()
1501 shp->inpipe = pvo; in sh_exec()
1502 shp->outpipe = pvn; in sh_exec()
1512 type = pipe_exec(shp,pvn,t->lst.lstlef, errorflg); in sh_exec()
1530 shp->inpipe = pvn; in sh_exec()
1531 shp->outpipe = 0; in sh_exec()
1550 tcsetpgrp(JOBTTY,shp->pid); in sh_exec()
1595 int jmpval = ((struct checkpt*)shp->jmplist)->mode; in sh_exec()
1597 void *optlist = shp->optlist; in sh_exec()
1598 shp->optlist = 0; in sh_exec()
1605 error_info.line = t->for_.forline-shp->st.firstline; in sh_exec()
1608 args=shp->st.dolv+1; in sh_exec()
1609 nargs = shp->st.dolc; in sh_exec()
1610 argsav=sh_arguse(shp); in sh_exec()
1614 args=sh_argbuild(shp,&argn,tp,0); in sh_exec()
1617 np = nv_open(t->for_.fornam, shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME|NV_NOREF); in sh_exec()
1619 shp->st.loopcnt++; in sh_exec()
1621 while(cp && shp->st.execbrk==0) in sh_exec()
1633 save_prompt = shp->nextprompt; in sh_exec()
1634 shp->nextprompt = 3; in sh_exec()
1635 shp->timeout = 0; in sh_exec()
1636 shp->exitval=sh_readline(shp,&nullptr,0,1,1000*shp->st.tmout); in sh_exec()
1637 shp->nextprompt = save_prompt; in sh_exec()
1638 if(shp->exitval||sfeof(sfstdin)||sferror(sfstdin)) in sh_exec()
1640 shp->exitval = 1; in sh_exec()
1643 if(!(val=nv_getval(sh_scoped(shp,REPLYNOD)))) in sh_exec()
1672 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
1679 sh_debug(shp,trap,(char*)0,(char*)0,av,0); in sh_exec()
1685 if((cp=nv_getval(sh_scoped(shp,REPLYNOD))) && *cp==0) in sh_exec()
1691 if(shp->st.breakcnt<0) in sh_exec()
1692 shp->st.execbrk = (++shp->st.breakcnt !=0); in sh_exec()
1698 sh_optclear(shp,optlist); in sh_exec()
1700 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1702 if(shp->st.breakcnt>0) in sh_exec()
1703 shp->st.execbrk = (--shp->st.breakcnt !=0); in sh_exec()
1704 shp->st.loopcnt--; in sh_exec()
1705 sh_argfree(shp,argsav,0); in sh_exec()
1720 int jmpval = ((struct checkpt*)shp->jmplist)->mode; in sh_exec()
1722 void *optlist = shp->optlist; in sh_exec()
1723 shp->optlist = 0; in sh_exec()
1734 fd = sh_redirect(shp,tt->com.comio,3); in sh_exec()
1741 shp->offsets[0] = -1; in sh_exec()
1742 shp->offsets[1] = 0; in sh_exec()
1747 shp->st.loopcnt++; in sh_exec()
1748 while(shp->st.execbrk==0) in sh_exec()
1753 if(!(shp->cur_line=sfgetr(iop,'\n',SF_STRING))) in sh_exec()
1761 if(shp->st.breakcnt<0) in sh_exec()
1762 shp->st.execbrk = (++shp->st.breakcnt !=0); in sh_exec()
1764 if(shp->st.execbrk==0 && t->wh.whinc) in sh_exec()
1769 shp->offsets[0] = -1; in sh_exec()
1770 shp->offsets[1] = 0; in sh_exec()
1778 sh_optclear(shp,optlist); in sh_exec()
1780 siglongjmp(*shp->jmplist,jmpval); in sh_exec()
1782 if(shp->st.breakcnt>0) in sh_exec()
1783 shp->st.execbrk = (--shp->st.breakcnt !=0); in sh_exec()
1784 shp->st.loopcnt--; in sh_exec()
1785 shp->exitval= r; in sh_exec()
1792 shp->cur_line = 0; in sh_exec()
1801 error_info.line = t->ar.arline-shp->st.firstline; in sh_exec()
1804 arg[1] = sh_macpat(shp,t->ar.arexpr,OPTIMIZE|ARG_ARITH); in sh_exec()
1809 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
1810 sh_debug(shp,trap,(char*)0, (char*)0, arg, ARG_ARITH); in sh_exec()
1817 shp->exitval = !arith_exec((Arith_t*)t->ar.arcomp); in sh_exec()
1819 shp->exitval = !sh_arith(arg[1]); in sh_exec()
1829 shp->exitval=0; /* force zero exit for if-then-fi */ in sh_exec()
1835 char *trap, *r = sh_macpat(shp,tt->sw.swarg,OPTIMIZE); in sh_exec()
1836 error_info.line = t->sw.swline-shp->st.firstline; in sh_exec()
1838 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
1845 sh_debug(shp,trap, (char*)0, (char*)0, av, 0); in sh_exec()
1855 s = sh_macpat(shp,rex,OPTIMIZE|ARG_EXP); in sh_exec()
1895 shp->exitval = !shp->exitval; in sh_exec()
1926 at = shp->lim.clk_tck*(ta.tv_sec-tb.tv_sec); in sh_exec()
1927 at += ((shp->lim.clk_tck*(((1000000L/2)/shp->lim.clk_tck)+(ta.tv_usec-tb.tv_usec)))/1000000L); in sh_exec()
1934 Namval_t *np = nv_open("TIMEFORMAT",shp->var_tree,NV_NOADD); in sh_exec()
1950 p_time(shp,sfstderr,sh_translate(format),tm); in sh_exec()
1964 Namval_t *oldnspace = shp->namespace; in sh_exec()
1966 long optindex = shp->st.optindex; in sh_exec()
1971 np = nv_open(stkptr(stkp,offset),shp->var_base,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME); in sh_exec()
1973 shp->namespace = np; in sh_exec()
1978 shp->st.optindex = 1; in sh_exec()
1980 if(oldnspace && dtvnext(dtvnext(shp->var_tree))) in sh_exec()
1981 top = dtview(shp->var_tree,0); in sh_exec()
1982 else if(dtvnext(shp->var_tree)) in sh_exec()
1983 top = dtview(shp->var_tree,0); in sh_exec()
1984 oldroot = shp->var_tree; in sh_exec()
1985 dtview(root,shp->var_base); in sh_exec()
1986 shp->var_tree = root; in sh_exec()
1988 dtview(shp->var_tree,top); in sh_exec()
1990 if(dtvnext(shp->var_tree)) in sh_exec()
1991 top = dtview(shp->var_tree,0); in sh_exec()
1992 shp->var_tree = oldroot; in sh_exec()
1994 dtview(top,shp->var_tree); in sh_exec()
1995 shp->namespace = oldnspace; in sh_exec()
1996 shp->st.optindex = optindex; in sh_exec()
2001 error_info.line = t->funct.functline-shp->st.firstline; in sh_exec()
2003 if(cp || shp->prefix) in sh_exec()
2006 if(shp->prefix) in sh_exec()
2008 cp = shp->prefix; in sh_exec()
2009 shp->prefix = 0; in sh_exec()
2010 npv = nv_open(cp,shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME); in sh_exec()
2011 shp->prefix = cp; in sh_exec()
2018 npv = nv_open(stkptr(stkp,offset),shp->var_tree,NV_NOASSIGN|NV_NOARRAY|NV_VARNAME); in sh_exec()
2024 else if((np=nv_search(fname,shp->bltin_tree,0)) && nv_isattr(np,BLT_SPC)) in sh_exec()
2027 else if(shp->namespace) in sh_exec()
2030 sfputr(stkp,nv_name(shp->namespace),-1); in sh_exec()
2040 if(!shp->mktype) in sh_exec()
2042 if(shp->typeinit) in sh_exec()
2044 if(tp=nv_open(shp->typeinit->nvname,shp->typedict,NV_IDENT|NV_NOFAIL)) in sh_exec()
2060 if(shp->funload) in sh_exec()
2069 np->nvalue.rp = new_of(struct Ufunction,shp->funload?sizeof(Dtlink_t):0); in sh_exec()
2086 np->nvalue.rp->nspace = shp->namespace; in sh_exec()
2088 np->nvalue.rp->fdict = shp->fun_tree; in sh_exec()
2094 if(shp->funload) in sh_exec()
2098 if(!shp->fpathdict) in sh_exec()
2099 shp->fpathdict = dtopen(&_Rpdisc,Dtbag); in sh_exec()
2100 if(shp->fpathdict) in sh_exec()
2101 dtinsert(shp->fpathdict,rp); in sh_exec()
2125 error_info.line = t->tst.tstline-shp->st.firstline; in sh_exec()
2130 n = !shp->exitval; in sh_exec()
2139 left = sh_macpat(shp,&(t->lst.lstlef->arg),OPTIMIZE); in sh_exec()
2141 right = sh_macpat(shp,&(t->lst.lstrit->arg),((n==TEST_PEQ||n==TEST_PNE)?ARG_EXP:0)|OPTIMIZE); in sh_exec()
2142 if(trap=shp->st.trap[SH_DEBUGTRAP]) in sh_exec()
2163 sh_debug(shp,trap,(char*)0,(char*)0,argv, 0); in sh_exec()
2183 sh_debug(shp,trap,(char*)0,(char*)0,argv, pattern); in sh_exec()
2198 shp->exitval = ((!n)^negate); in sh_exec()
2204 if(shp->trapnote || (shp->exitval && sh_isstate(SH_ERREXIT)) && in sh_exec()
2213 sh_done(shp,0); in sh_exec()
2214 if(shp->lastarg!= lastarg && shp->lastarg) in sh_exec()
2215 free(shp->lastarg); in sh_exec()
2219 shp->lastarg = strcpy(lastarg,comn); in sh_exec()
2224 shp->lastarg = strdup(comn); in sh_exec()
2236 if(shp->trapnote&SH_SIGSET) in sh_exec()
2237 sh_exit(SH_EXITSIG|shp->lastsig); in sh_exec()
2245 return(shp->exitval); in sh_exec()
2300 Shell_t *shp = &sh; in sh_trace() local
2309 if(!(cp=nv_getval(sh_scoped(shp,PS4NOD)))) in sh_trace()
2314 cp = sh_mactry(shp,cp); in sh_trace()
2333 if(decl && shp->prefix && cp!=argv0 && *cp!='-') in sh_trace()
2336 cp = shp->prefix; in sh_trace()
2338 sfputr(sfstderr,shp->prefix,'.'); in sh_trace()
2375 Shell_t *shp = &sh; in _sh_fork() local
2404 shp->nforks++; in _sh_fork()
2428 shp->cpid = parent; in _sh_fork()
2448 if(shp->trapnote&SH_SIGTERM) in _sh_fork()
2450 shp->nforks=0; in _sh_fork()
2478 shp->login_sh = 0; in _sh_fork()
2482 if (shp->fn_reset) in _sh_fork()
2483 shp->fn_depth = shp->fn_reset = 0; in _sh_fork()
2491 shp->subshell = 0; in _sh_fork()
2492 if((flags&FAMP) && shp->coutpipe>1) in _sh_fork()
2493 sh_close(shp->coutpipe); in _sh_fork()
2494 sig = shp->savesig; in _sh_fork()
2495 shp->savesig = 0; in _sh_fork()
2555 register Shell_t *shp = &sh; in sh_funscope() local
2557 struct sh_scoped savst, *prevscope = shp->st.self; in sh_funscope()
2564 Namval_t *nspace = shp->namespace; in sh_funscope()
2565 Dt_t *last_root = shp->last_root; in sh_funscope()
2566 Shopt_t options = shp->options; in sh_funscope()
2567 if(shp->fn_depth==0) in sh_funscope()
2568 shp->glob_options = shp->options; in sh_funscope()
2570 shp->options = shp->glob_options; in sh_funscope()
2572 shp->st.lineno = error_info.line; in sh_funscope()
2574 *prevscope = shp->st; in sh_funscope()
2576 shp->st.prevst = prevscope; in sh_funscope()
2577 shp->st.self = &savst; in sh_funscope()
2578 shp->topscope = (Shscope_t*)shp->st.self; in sh_funscope()
2579 shp->st.opterror = shp->st.optchar = 0; in sh_funscope()
2580 shp->st.optindex = 1; in sh_funscope()
2581 shp->st.loopcnt = 0; in sh_funscope()
2585 shp->st.real_fun = (fp->node)->nvalue.rp; in sh_funscope()
2588 prevscope->save_tree = shp->var_tree; in sh_funscope()
2589 sh_scope(shp,envlist,1); in sh_funscope()
2590 if(dtvnext(prevscope->save_tree)!= (shp->namespace?shp->var_base:0)) in sh_funscope()
2595 shp->st.save_tree = shp->var_tree; in sh_funscope()
2604 if((np=(fp->node)->nvalue.rp->nspace) && np!=shp->namespace) in sh_funscope()
2606 Dt_t *dt = shp->var_tree; in sh_funscope()
2609 shp->var_tree = nv_dict(np); in sh_funscope()
2610 shp->namespace = np; in sh_funscope()
2614 shp->st.cmdname = argv[0]; in sh_funscope()
2616 if((nsig=shp->st.trapmax*sizeof(char*))>0 || shp->st.trapcom[0]) in sh_funscope()
2619 memcpy(savstak=stakalloc(nsig),(char*)&shp->st.trapcom[0],nsig); in sh_funscope()
2622 argsav = sh_argnew(shp,argv,&saveargfor); in sh_funscope()
2626 shp->st.var_local = shp->var_tree; in sh_funscope()
2630 shp->st.filename = fp->node->nvalue.rp->fname; in sh_funscope()
2631 shp->st.funname = nv_name(fp->node); in sh_funscope()
2632 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_funscope()
2633 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_funscope()
2637 if(shp->fn_depth++ > MAXDEPTH) in sh_funscope()
2639 shp->toomany = 1; in sh_funscope()
2640 siglongjmp(*shp->jmplist,SH_JMPERRFN); in sh_funscope()
2647 r = shp->exitval; in sh_funscope()
2650 if(--shp->fn_depth==1 && jmpval==SH_JMPERRFN) in sh_funscope()
2653 if (shp->st.self != &savst) in sh_funscope()
2654 shp->var_tree = (Dt_t*)savst.save_tree; in sh_funscope()
2655 sh_unscope(shp); in sh_funscope()
2656 shp->namespace = nspace; in sh_funscope()
2657 shp->var_tree = (Dt_t*)prevscope->save_tree; in sh_funscope()
2658 if(shp->topscope != (Shscope_t*)shp->st.self) in sh_funscope()
2659 sh_setscope(shp->topscope); in sh_funscope()
2660 sh_argreset(shp,argsav,saveargfor); in sh_funscope()
2661 trap = shp->st.trapcom[0]; in sh_funscope()
2662 shp->st.trapcom[0] = 0; in sh_funscope()
2664 if (shp->st.self != &savst) in sh_funscope()
2665 *shp->st.self = shp->st; in sh_funscope()
2666 shp->st = *prevscope; in sh_funscope()
2667 shp->topscope = (Shscope_t*)prevscope; in sh_funscope()
2668 nv_getval(sh_scoped(shp,IFSNOD)); in sh_funscope()
2670 memcpy((char*)&shp->st.trapcom[0],savstak,nsig); in sh_funscope()
2671 shp->trapnote=0; in sh_funscope()
2674 shp->options = options; in sh_funscope()
2675 shp->last_root = last_root; in sh_funscope()
2677 siglongjmp(*shp->jmplist,jmpval); in sh_funscope()
2683 if(shp->exitval > SH_EXITSIG) in sh_funscope()
2684 sh_fault(shp->exitval&SH_EXITMASK); in sh_funscope()
2688 siglongjmp(*shp->jmplist,jmpval); in sh_funscope()
2693 static void sh_funct(Shell_t *shp,Namval_t *np,int argn, char *argv[],struct argnod *envlist,int ex… in sh_funct() argument
2698 int level, pipepid=shp->pipepid; in sh_funct()
2699 shp->pipepid = 0; in sh_funct()
2703 if((struct sh_scoped*)shp->topscope != shp->st.self) in sh_funct()
2704 sh_setscope(shp->topscope); in sh_funct()
2705 level = lp->maxlevel = shp->dot_depth + shp->fn_depth+1; in sh_funct()
2707 shp->st.lineno = error_info.line; in sh_funct()
2711 int loopcnt = shp->st.loopcnt; in sh_funct()
2712 shp->posix_fun = np; in sh_funct()
2715 shp->st.funname = nv_name(np); in sh_funct()
2719 shp->st.loopcnt = 0; in sh_funct()
2720 b_dot_cmd(argn+1,argv-1,&shp->bltindata); in sh_funct()
2721 shp->st.loopcnt = loopcnt; in sh_funct()
2738 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); in sh_funct()
2742 nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE); in sh_funct()
2743 shp->pipepid = pipepid; in sh_funct()
2753 Shell_t *shp = &sh; in sh_fun() local
2759 char *prefix = shp->prefix; in sh_fun()
2766 shp->prefix = 0; in sh_fun()
2776 mode = set_instance(shp,nq,&node, &nr); in sh_fun()
2800 sh_funct(shp,np,n,argv,(struct argnod*)0,sh_isstate(SH_ERREXIT)); in sh_fun()
2806 shp->prefix = prefix; in sh_fun()
2827 static void coproc_init(Shell_t *shp, int pipes[]) in coproc_init() argument
2830 if(shp->coutpipe>=0 && shp->cpid) in coproc_init()
2832 shp->cpid = 0; in coproc_init()
2833 if(shp->cpipe[0]<=0 || shp->cpipe[1]<=0) in coproc_init()
2836 sh_pclose(shp->cpipe); in coproc_init()
2837 sh_pipe(shp->cpipe); in coproc_init()
2838 if((outfd=shp->cpipe[1]) < 10) in coproc_init()
2840 int fd=fcntl(shp->cpipe[1],F_DUPFD,10); in coproc_init()
2843 shp->fdstatus[fd] = (shp->fdstatus[outfd]&~IOCLEX); in coproc_init()
2845 shp->fdstatus[outfd] = IOCLOSE; in coproc_init()
2846 shp->cpipe[1] = fd; in coproc_init()
2849 if(fcntl(*shp->cpipe,F_SETFD,FD_CLOEXEC)>=0) in coproc_init()
2850 shp->fdstatus[shp->cpipe[0]] |= IOCLEX; in coproc_init()
2851 shp->fdptrs[shp->cpipe[0]] = shp->cpipe; in coproc_init()
2853 if(fcntl(shp->cpipe[1],F_SETFD,FD_CLOEXEC) >=0) in coproc_init()
2854 shp->fdstatus[shp->cpipe[1]] |= IOCLEX; in coproc_init()
2856 shp->outpipe = shp->cpipe; in coproc_init()
2857 sh_pipe(shp->inpipe=pipes); in coproc_init()
2858 shp->coutpipe = shp->inpipe[1]; in coproc_init()
2859 shp->fdptrs[shp->coutpipe] = &shp->coutpipe; in coproc_init()
2860 if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0) in coproc_init()
2861 shp->fdstatus[shp->outpipe[0]] |= IOCLEX; in coproc_init()
2976 static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,int flag) in sh_ntfork() argument
3023 if(!np && path && !nv_search(path,shp->fun_tree,0)) in sh_ntfork()
3034 if(!shp->st.ioset) in sh_ntfork()
3036 sh_iosave(shp,0,buff.topfd,(char*)0); in sh_ntfork()
3037 sh_iorenumber(shp,sh_chkopen(e_devnull),0); in sh_ntfork()
3042 int fd = shp->inpipe[1]; in sh_ntfork()
3043 sh_iosave(shp,0,buff.topfd,(char*)0); in sh_ntfork()
3044 sh_iorenumber(shp,shp->inpipe[0],0); in sh_ntfork()
3046 shp->fdstatus[fd] |= IOCLEX; in sh_ntfork()
3050 sh_iosave(shp,1,buff.topfd,(char*)0); in sh_ntfork()
3051 sh_iorenumber(shp,sh_dup(shp->outpipe[1]),1); in sh_ntfork()
3052 if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0) in sh_ntfork()
3053 shp->fdstatus[shp->outpipe[0]] |= IOCLEX; in sh_ntfork()
3057 sh_redirect(shp,t->fork.forkio,0); in sh_ntfork()
3091 …if((otype&FPIN) && (!(otype&FPOU) || (otype&FCOOP)) && fcntl(shp->inpipe[1],F_SETFD,FD_CLOEXEC)>=0) in sh_ntfork()
3092 shp->fdstatus[shp->inpipe[1]] &= ~IOCLEX; in sh_ntfork()
3094 sh_iorestore(shp,buff.topfd,jmpval); in sh_ntfork()
3114 siglongjmp(*shp->jmplist,jmpval); in sh_ntfork()
3117 sh_close(shp->coutpipe); in sh_ntfork()
3118 sh_close(shp->cpipe[1]); in sh_ntfork()
3119 shp->cpipe[1] = -1; in sh_ntfork()
3120 shp->coutpipe = -1; in sh_ntfork()
3122 shp->exitval = 0; in sh_ntfork()
3138 sh_redirect(shp,t->com.comio,0); in sh_ntfork()
3143 sh_scope(shp,t->com.comset,0); in sh_ntfork()
3148 if((np=nv_search(path,shp->track_tree,0)) && !nv_isattr(np,NV_NOALIAS) && np->nvalue.cp) in sh_ntfork()
3152 path = stkptr(shp->stk,PATH_OFFSET); in sh_ntfork()
3153 stkfreeze(shp->stk,0); in sh_ntfork()
3176 shp->exitval = 0; in sh_ntfork()
3214 if(!shp->shpath) in sh_ntfork()
3215 shp->shpath = pathshell(); in sh_ntfork()
3216 spawnpid = path_spawn(shp->shpath,&argv[-1],arge,pp,(grp<<1)|1); in sh_ntfork()
3222 if(spawnpid < 0) switch(errno=shp->path_err) in sh_ntfork()
3246 sh_unscope(shp); in sh_ntfork()
3251 sh_iorestore(shp,buff.topfd,jmpval); in sh_ntfork()
3253 siglongjmp(*shp->jmplist,jmpval); in sh_ntfork()