Lines Matching refs:shp

385 void sh_ioinit(Shell_t *shp)  in sh_ioinit()  argument
391 n = shp->lim.open_max+2; in sh_ioinit()
393 n = shp->lim.open_max; in sh_ioinit()
395 shp->fdstatus = (unsigned char*)malloc((unsigned)n); in sh_ioinit()
396 memset((char*)shp->fdstatus,0,n); in sh_ioinit()
397 shp->fdptrs = (int**)malloc(n*sizeof(int*)); in sh_ioinit()
398 memset((char*)shp->fdptrs,0,n*sizeof(int*)); in sh_ioinit()
399 shp->sftable = (Sfio_t**)malloc(n*sizeof(Sfio_t*)); in sh_ioinit()
400 memset((char*)shp->sftable,0,n*sizeof(Sfio_t*)); in sh_ioinit()
401 shp->sftable[0] = sfstdin; in sh_ioinit()
402 shp->sftable[1] = sfstdout; in sh_ioinit()
403 shp->sftable[2] = sfstderr; in sh_ioinit()
405 sh_iostream(shp,0); in sh_ioinit()
407 shp->outpool = sfopen(NIL(Sfio_t*),NIL(char*),"sw"); /* pool identifier */ in sh_ioinit()
408 shp->outbuff = (char*)malloc(IOBSIZE+4); in sh_ioinit()
409 shp->errbuff = (char*)malloc(IOBSIZE/4); in sh_ioinit()
410 sfsetbuf(sfstderr,shp->errbuff,IOBSIZE/4); in sh_ioinit()
411 sfsetbuf(sfstdout,shp->outbuff,IOBSIZE); in sh_ioinit()
412 sfpool(sfstdout,shp->outpool,SF_WRITE); in sh_ioinit()
413 sfpool(sfstderr,shp->outpool,SF_WRITE); in sh_ioinit()
468 Sfio_t *sh_iostream(Shell_t *shp, register int fd) in sh_iostream() argument
471 register int status = sh_iocheckfd(shp,fd); in sh_iostream()
476 if(fd>=shp->lim.open_max) in sh_iostream()
477 return(shp->sftable[fd]); in sh_iostream()
501 bp = shp->outbuff; in sh_iostream()
504 if((iop = shp->sftable[fd]) && sffileno(iop)>=0) in sh_iostream()
530 sfpool(iop,shp->outpool,SF_WRITE); in sh_iostream()
533 shp->sftable[fd] = iop; in sh_iostream()
540 static void io_preserve(Shell_t* shp, register Sfio_t *sp, register int f2) in io_preserve() argument
547 if(f2==shp->infd) in io_preserve()
548 shp->infd = fd; in io_preserve()
551 shp->toomany = 1; in io_preserve()
552 ((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT; in io_preserve()
555 if(shp->fdptrs[fd]=shp->fdptrs[f2]) in io_preserve()
559 *shp->fdptrs[fd] = fd; in io_preserve()
560 shp->fdptrs[f2] = 0; in io_preserve()
562 shp->sftable[fd] = sp; in io_preserve()
563 shp->fdstatus[fd] = shp->fdstatus[f2]; in io_preserve()
567 shp->fdstatus[fd] |= IOCLEX; in io_preserve()
569 shp->sftable[f2] = 0; in io_preserve()
578 int sh_iorenumber(Shell_t *shp, register int f1,register int f2) in sh_iorenumber() argument
580 register Sfio_t *sp = shp->sftable[f2]; in sh_iorenumber()
586 if(!(shp->inuse_bits&(1<<f2))) in sh_iorenumber()
587 io_preserve(shp,sp,f2); in sh_iorenumber()
591 shp->st.ioset = 1; in sh_iorenumber()
595 register Sfio_t *spnew = sh_iostream(shp,f1); in sh_iorenumber()
596 shp->fdstatus[f2] = (shp->fdstatus[f1]&~IOCLEX); in sh_iorenumber()
603 shp->fdstatus[f2] = (shp->fdstatus[f1]&~IOCLEX); in sh_iorenumber()
607 sh_iostream(shp,f2); in sh_iorenumber()
610 shp->sftable[f1] = 0; in sh_iorenumber()
667 Shell_t *shp = &sh; in sh_open() local
737 if((mode=sh_iocheckfd(shp,fd))==IOCLOSE) in sh_open()
836 static int io_patseek(Shell_t *shp, regex_t *rp, Sfio_t* sp, int flags) in io_patseek() argument
839 int r, fd=sffileno(sp), close_exec = shp->fdstatus[fd]&IOCLEX; in io_patseek()
842 shp->fdstatus[sffileno(sp)] |= IOCLEX; in io_patseek()
867 shp->fdstatus[sffileno(sp)] &= ~IOCLEX; in io_patseek()
873 static Sfoff_t file_offset(Shell_t *shp, int fn, char *fname) in file_offset() argument
875 Sfio_t *sp = shp->sftable[fn]; in file_offset()
879 Namval_t *mp = nv_open("EOF",shp->var_tree,0); in file_offset()
880 Namval_t *pp = nv_open("CUR",shp->var_tree,0); in file_offset()
960 int sh_redirect(Shell_t *shp,struct ionod *iop, int flag) in sh_redirect() argument
969 int r, indx = shp->topfd, perm= -1; in sh_redirect()
970 char *tname=0, *after="", *trace = shp->st.trap[SH_DEBUGTRAP]; in sh_redirect()
972 int isstring = shp->subshell?(sfset(sfstdout,0,0)&SF_STRING):0; in sh_redirect()
981 if(fn==1 && shp->subshell && !shp->subshare && (flag==2 || isstring)) in sh_redirect()
1006 fname=sh_macpat(shp,ap,(iof&IOARITH)?ARG_ARITH:ARG_EXP); in sh_redirect()
1015 ap = sh_argprocsub(shp,ap); in sh_redirect()
1019 fname=sh_mactrim(shp,fname,(!sh_isoption(SH_NOGLOB)&&sh_isoption(SH_INTERACTIVE))?2:0); in sh_redirect()
1025 np = nv_open(iop->iovname,shp->var_tree,NV_NOASSIGN|NV_VARNAME); in sh_redirect()
1050 fd = io_heredoc(shp,iop,fname,traceon); in sh_redirect()
1073 if(shp->subshell && dupfd==1 && (sfset(sfstdout,0,0)&SF_STRING)) in sh_redirect()
1078 else if(shp->sftable[dupfd]) in sh_redirect()
1079 sfsync(shp->sftable[dupfd]); in sh_redirect()
1089 dupfd = shp->coutpipe; in sh_redirect()
1091 dupfd = shp->cpipe[0]; in sh_redirect()
1104 sh_iocheckfd(shp,dupfd); in sh_redirect()
1105 shp->fdstatus[fd] = (shp->fdstatus[dupfd]&~IOCLEX); in sh_redirect()
1106 if(toclose<0 && shp->fdstatus[fd]&IOREAD) in sh_redirect()
1107 shp->fdstatus[fd] |= IODUP; in sh_redirect()
1108 else if(dupfd==shp->cpipe[0]) in sh_redirect()
1109 sh_pclose(shp->cpipe); in sh_redirect()
1113 sh_iosave(shp,toclose,indx,(char*)0); /* save file descriptor */ in sh_redirect()
1160 (!shp->lim.fs3d || iview(&sb)==0)) in sh_redirect()
1212 sh_debug(shp,trace,(char*)0,(char*)0,av,ARG_NOGLOB); in sh_redirect()
1216 Sfio_t *sp = shp->sftable[fn]; in sh_redirect()
1217 r = shp->fdstatus[fn]; in sh_redirect()
1219 r = sh_iocheckfd(shp,fn); in sh_redirect()
1236 if((off = file_offset(shp,fn,fname))<0) in sh_redirect()
1263 sp = sh_iostream(shp,fn); in sh_redirect()
1264 r=io_patseek(shp,rp,sp,iof); in sh_redirect()
1290 sh_iosave(shp,fn,indx,tname?fname:(trunc?Empty:0)); in sh_redirect()
1293 sh_iosave(shp,fn,indx|IOSUBSHELL,tname?fname:0); in sh_redirect()
1297 if(sh_inuse(fn) || (fn && fn==shp->infd)) in sh_redirect()
1299 if(fn>9 || !(shp->inuse_bits&(1<<fn))) in sh_redirect()
1300 io_preserve(shp,shp->sftable[fn],fn); in sh_redirect()
1316 shp->fdstatus[fn] = shp->fdstatus[fd]; in sh_redirect()
1324 sh_iocheckfd(shp,fd); in sh_redirect()
1328 fd = sh_iorenumber(shp,sh_iomovefd(fd),fn); in sh_redirect()
1330 shp->inuse_bits |= (1<<fn); in sh_redirect()
1336 shp->fdstatus[fd] |= IOCLEX; in sh_redirect()
1351 static int io_heredoc(Shell_t *shp,register struct ionod *iop, const char *name, int traceon) in io_heredoc() argument
1355 if(!(iop->iofile&IOSTRG) && (!shp->heredocs || iop->iosize==0)) in io_heredoc()
1368 infile = subopen(shp,shp->heredocs,iop->iooffset,iop->iosize); in io_heredoc()
1384 char *lastpath = shp->lastpath; in io_heredoc()
1385 sh_machere(shp,infile,outfile,iop->ioname); in io_heredoc()
1386 shp->lastpath = lastpath; in io_heredoc()
1398 shp->fdstatus[fd] = IOREAD; in io_heredoc()
1419 void sh_iosave(Shell_t *shp, register int origfd, int oldtop, char *name) in sh_iosave() argument
1429 for(savefd=shp->topfd; --savefd>=oldtop; ) in sh_iosave()
1435 if(shp->topfd >= filemapsize) in sh_iosave()
1446 for(savefd=shp->lim.open_max+2; --savefd>=0; ) in sh_iosave()
1448 for(savefd=shp->lim.open_max; --savefd>=0; ) in sh_iosave()
1451 cp = (char*)shp->fdptrs[savefd]; in sh_iosave()
1453 shp->fdptrs[savefd] = (int*)(oldptr+moved); in sh_iosave()
1468 shp->toomany=1; in sh_iosave()
1469 ((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT; in sh_iosave()
1473 filemap[shp->topfd].tname = name; in sh_iosave()
1474 filemap[shp->topfd].subshell = flag; in sh_iosave()
1475 filemap[shp->topfd].orig_fd = origfd; in sh_iosave()
1476 filemap[shp->topfd++].save_fd = savefd; in sh_iosave()
1479 register Sfio_t* sp = shp->sftable[origfd]; in sh_iosave()
1484 shp->fdstatus[savefd] = shp->fdstatus[origfd]; in sh_iosave()
1485 shp->fdptrs[savefd] = &filemap[shp->topfd-1].save_fd; in sh_iosave()
1486 if(!(shp->sftable[savefd]=sp)) in sh_iosave()
1493 shp->sftable[savefd] = sp; in sh_iosave()
1496 shp->sftable[origfd] = 0; in sh_iosave()
1503 void sh_iounsave(Shell_t* shp) in sh_iounsave() argument
1506 for(newfd=fd=0; fd < shp->topfd; fd++) in sh_iounsave()
1512 shp->sftable[savefd] = 0; in sh_iounsave()
1516 shp->topfd = newfd; in sh_iounsave()
1522 void sh_iorestore(Shell_t *shp, int last, int jmpval) in sh_iorestore() argument
1527 for (fd = shp->topfd - 1; fd >= last; fd--) in sh_iorestore()
1535 shp->sftable[savefd] = 0; in sh_iorestore()
1541 if(filemap[fd].tname == Empty && shp->exitval==0) in sh_iorestore()
1544 io_usename(filemap[fd].tname,(int*)0,shp->exitval?2:1); in sh_iorestore()
1551 shp->fdstatus[origfd] = shp->fdstatus[savefd]; in sh_iorestore()
1553 if(shp->fdstatus[origfd]&IOCLEX) in sh_iorestore()
1557 sfswap(shp->sftable[savefd],shp->sftable[origfd]); in sh_iorestore()
1559 shp->st.ioset = 0; in sh_iorestore()
1562 shp->sftable[origfd] = shp->sftable[savefd]; in sh_iorestore()
1563 shp->sftable[savefd] = 0; in sh_iorestore()
1567 shp->fdstatus[origfd] = IOCLOSE; in sh_iorestore()
1572 for (fd = last ; fd < shp->topfd; fd++) in sh_iorestore()
1578 if(last < shp->topfd) in sh_iorestore()
1579 shp->topfd = last; in sh_iorestore()
1589 Shell_t *shp = &sh; in sh_ioaccess() local
1593 if((flags=sh_iocheckfd(shp,fd))!=IOCLOSE) in sh_ioaccess()
1794 int sh_iocheckfd(Shell_t *shp, register int fd) in sh_iocheckfd() argument
1861 Shell_t *shp = &sh; in io_prompt() local
1892 cp = sh_mactry(shp,nv_getval(sh_scoped(shp,PS1NOD))); in io_prompt()
1912 cp = nv_getval(sh_scoped(shp,PS2NOD)); in io_prompt()
1915 cp = nv_getval(sh_scoped(shp,PS3NOD)); in io_prompt()
1948 Shell_t *shp = &sh; in sftrack() local
1975 if((unsigned)fd >= shp->lim.open_max) in sftrack()
1980 if(sp==shp->heredocs && fd < 10 && flag==SF_NEW) in sftrack()
1989 if(!shp->sftable[fd] && shp->fdstatus[fd]==IOCLOSE) in sftrack()
1991 shp->sftable[fd] = sp; in sftrack()
1995 shp->fdstatus[fd] = flag; in sftrack()
1996 sh_iostream(shp,fd); in sftrack()
1998 if((pp=(struct checkpt*)shp->jmplist) && pp->mode==SH_JMPCMD) in sftrack()
2016 shp->sftable[fd] = 0; in sftrack()
2017 shp->fdstatus[fd]=IOCLOSE; in sftrack()
2018 if(pp=(struct checkpt*)shp->jmplist) in sftrack()
2112 static Sfio_t *subopen(Shell_t *shp,Sfio_t* sp, off_t offset, long size) in subopen() argument
2123 sp = sfnew(NIL(Sfio_t*),(char*)(disp+1),IOBSIZE,shp->lim.open_max,SF_READ); in subopen()
2178 Shell_t *shp = &sh; in sh_menu() local
2183 char *cp = nv_getval(sh_scoped(shp,LINES)); in sh_menu()
2329 Shell_t *shp = &sh; in sh_iogetiop() local
2340 if(!sh_histinit((void*)shp)) in sh_iogetiop()
2342 fd = sffileno(shp->hist_ptr->histfp); in sh_iogetiop()
2346 fd = shp->coutpipe; in sh_iogetiop()
2348 fd = shp->cpipe[0]; in sh_iogetiop()
2351 if(fd<0 || fd >= shp->lim.open_max) in sh_iogetiop()
2359 if(!(n=shp->fdstatus[fd])) in sh_iogetiop()
2360 n = sh_iocheckfd(shp,fd); in sh_iogetiop()
2365 if(!(iop = shp->sftable[fd])) in sh_iogetiop()
2366 iop=sh_iostream(shp,fd); in sh_iogetiop()
2382 Shell_t *shp = &sh; in sh_fd2sfio() local
2385 if(!sp && (status = sh_iocheckfd(shp,fd))!=IOCLOSE) in sh_fd2sfio()
2400 Shell_t *shp = &sh; in sh_pathopen() local
2411 return(sh_iostream(shp,n)); in sh_pathopen()