# 2.11BSD#431 - /usr/src/bin/sh/io.c

##### Functions

    chkopen           X
    chkpipe           X
    copy              X
    create            X
    estabf            X
    initf             X
    pop               X
    push              X
    rename            X
    tmpfil            X

       1: #ifndef lint
       2: static char sccsid[] = "@(#)io.c	4.3 3/19/85";
       3: #endif
       4:
       5: #
       6: /*
       7:  * UNIX shell
       8:  *
       9:  * S. R. Bourne
      10:  * Bell Telephone Laboratories
      11:  *
      12:  */
      13:
      14: #include    "defs.h"
      15:
      16:
      17: /* ========	input output and file copying ======== */
      18:
      19: initf(fd)
      20:     UFD     fd;
      21: {
      22:     REG FILE    f=standin;
      23:
      24:     f->fdes=fd; f->fsiz=((flags&(oneflg|ttyflg))==0 ? BUFSIZ : 1);
      25:     f->fnxt=f->fend=f->fbuf; f->feval=0; f->flin=1;
      26:     f->feof=FALSE;
      27: }
      28:
      29: estabf(s)
      30:     REG STRING  s;
      31: {
      32:     REG FILE    f;
      33:
      34:     (f=standin)->fdes = -1;
      35:     f->fend=length(s)+(f->fnxt=s);
      36:     f->flin=1;
      37:     return(f->feof=(s==0));
      38: }
      39:
      40: push(af)
      41:     FILE        af;
      42: {
      43:     REG FILE    f;
      44:
      45:     (f=af)->fstak=standin;
      46:     f->feof=0; f->feval=0;
      47:     standin=f;
      48: }
      49:
      50: pop()
      51: {
      52:     REG FILE    f;
      53:
      54:     IF (f=standin)->fstak
      55:     THEN    IF f->fdes>=0 THEN close(f->fdes) FI
      56:         standin=f->fstak;
      57:         return(TRUE);
      58:     ELSE    return(FALSE);
      59:     FI
      60: }
      61:
      62: chkpipe(pv)
      63:     INT     *pv;
      64: {
      65:     IF pipe(pv)<0 ORF pv[INPIPE]<0 ORF pv[OTPIPE]<0
      66:     THEN    error(piperr);
      67:     FI
      68: }
      69:
      70: chkopen(idf)
      71:     STRING      idf;
      72: {
      73:     REG INT     rc;
      74:
      75:     IF (rc=open(idf,0))<0
      76:     THEN    failed(idf,badopen);
      77:     ELSE    return(rc);
      78:     FI
      79: }
      80:
      81: rename(f1,f2)
      82:     REG INT     f1, f2;
      83: {
      84:     IF f1!=f2
      85:     THEN    dup2(f1, f2);
      86:         close(f1);
      87:         IF f2==0 THEN ioset|=1 FI
      88:     FI
      89: }
      90:
      91: create(s)
      92:     STRING      s;
      93: {
      94:     REG INT     rc;
      95:
      96:     IF (rc=creat(s,0666))<0
      97:     THEN    failed(s,badcreate);
      98:     ELSE    return(rc);
      99:     FI
     100: }
     101:
     102: tmpfil()
     103: {
     104:     itos(serial++); movstr(numbuf,tmpnam);
     105:     return(create(tmpout));
     106: }
     107:
     108: /* set by trim */
     109: BOOL        nosubst;
     110:
     111: copy(ioparg)
     112:     IOPTR       ioparg;
     113: {
     114:     CHAR        c, *ends;
     115:     REG CHAR    *cline, *clinep;
     116:     INT     fd;
     117:     REG IOPTR   iop;
     118:
     119:     IF iop=ioparg
     120:     THEN    copy(iop->iolst);
     121:         ends=mactrim(iop->ioname); IF nosubst THEN iop->iofile &= ~IODOC FI
     122:         fd=tmpfil();
     123:         iop->ioname=cpystak(tmpout);
     124:         iop->iolst=iotemp; iotemp=iop;
     125:         cline=locstak();
     126:
     127:         LOOP    clinep=cline; chkpr(NL);
     128:             WHILE (c = (nosubst ? readc() :  nextc(*ends)),  !eolchar(c)) DO *clinep++ = c OD
     129:             *clinep=0;
     130:             IF eof ORF eq(cline,ends) THEN break FI
     131:             *clinep++=NL;
     132:             write(fd,cline,clinep-cline);
     133:         POOL
     134:         close(fd);
     135:     FI
     136: }

#### Defined functions

chkopen defined in line 70; used 6 times

- in /usr/src/bin/sh/main.c line 88
- in /usr/src/bin/sh/service.c line 47-48(2), 58, 151
- in /usr/src/bin/sh/xec.c line 290

chkpipe defined in line 62; used 2 times

- in /usr/src/bin/sh/macro.c line 195
- in /usr/src/bin/sh/xec.c line 311

copy defined in line 111; used 2 times

- in line 120
- in /usr/src/bin/sh/word.c line 74

create defined in line 91; used 2 times

- in line 105
- in /usr/src/bin/sh/service.c line 63

estabf defined in line 29; used 5 times

- in /usr/src/bin/sh/macro.c line 162, 186
- in /usr/src/bin/sh/main.c line 87
- in /usr/src/bin/sh/word.c line 108
- in /usr/src/bin/sh/xec.c line 419

initf defined in line 19; used 5 times

- in /usr/src/bin/sh/macro.c line 196, 220
- in /usr/src/bin/sh/main.c line 143
- in /usr/src/bin/sh/name.c line 139
- in /usr/src/bin/sh/xec.c line 421

pop defined in line 50; used 6 times

- in /usr/src/bin/sh/args.c line 128
- in /usr/src/bin/sh/macro.c line 166, 208, 229
- in /usr/src/bin/sh/name.c line 165
- in /usr/src/bin/sh/xec.c line 424

push defined in line 40; used 5 times

- in /usr/src/bin/sh/macro.c line 162, 186, 220
- in /usr/src/bin/sh/name.c line 139
- in /usr/src/bin/sh/xec.c line 417

rename defined in line 81; used 5 times

- in /usr/src/bin/sh/service.c line 66
- in /usr/src/bin/sh/xec.c line 280-284(2), 290, 305

tmpfil defined in line 102; used 2 times

- in line 122
- in /usr/src/bin/sh/service.c line 47

#### Defined variables

sccsid defined in line 2; never used

Last modified: 1985-03-20 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 874 |