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

##### Functions

    nextc             X
    readb             X
    readc             X
    word              X

       1: #ifndef lint
       2: static char sccsid[] = "@(#)word.c	4.6 10/31/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: #include    "sym.h"
      16:
      17:
      18: /* ========	character handling for command lines	========*/
      19:
      20:
      21: word()
      22: {
      23:     REG CHAR    c, d;
      24:     REG CHAR    *argp=locstak()+BYTESPERWORD;
      25:     INT     alpha=1;
      26:
      27:     wdnum=0; wdset=0;
      28:
      29:     WHILE (c=nextc(0), space(c)) DONE
      30:
      31:     IF c=='#' ANDF ((flags&prompt)==0 ORF ((flags&ttyflg) ANDF
      32:         standin->fstak!=0))
      33:     THEN    WHILE (c=readc()) ANDF c!=NL DONE
      34:     FI
      35:
      36:     IF !eofmeta(c)
      37:     THEN    REP IF c==LITERAL
      38:             THEN    *argp++=(DQUOTE);
      39:                 WHILE (c=readc()) ANDF c!=LITERAL
      40:                 DO *argp++=(c|QUOTE); chkpr(c) OD
      41:                 *argp++=(DQUOTE);
      42:
      43:             ELSE    *argp++=(c);
      44:                 IF c=='=' THEN wdset |= alpha FI
      45:                 IF !alphanum(c) THEN alpha=0 FI
      46:                 IF qotchar(c)
      47:                 THEN    d=c;
      48:                     WHILE (*argp++=(c=nextc(d))) ANDF c!=d
      49:                     DO chkpr(c) OD
      50:                 FI
      51:             FI
      52:         PER (c=nextc(0), !eofmeta(c)) DONE
      53:         argp=endstak(argp);
      54:         IF !letter(argp->argval[0]) THEN wdset=0 FI
      55:
      56:         peekc=c|MARK;
      57:         IF argp->argval[1]==0 ANDF (d=argp->argval[0], digit(d)) ANDF (c=='>' ORF c=='<')
      58:         THEN    word(); wdnum=d-'0';
      59:         ELSE    /*check for reserved words*/
      60:             IF reserv==FALSE ORF (wdval=syslook(argp->argval,reserved))==0
      61:             THEN    wdarg=argp; wdval=0;
      62:             FI
      63:         FI
      64:
      65:     ELIF dipchar(c)
      66:     THEN    IF (d=nextc(0))==c
      67:         THEN    wdval = c|SYMREP;
      68:         ELSE    peekc = d|MARK; wdval = c;
      69:         FI
      70:     ELSE    IF (wdval=c)==EOF
      71:         THEN    wdval=EOFSYM;
      72:         FI
      73:         IF iopend ANDF eolchar(c)
      74:         THEN    copy(iopend); iopend=0;
      75:         FI
      76:     FI
      77:     reserv=FALSE;
      78:     return(wdval);
      79: }
      80:
      81: nextc(quote)
      82:     CHAR        quote;
      83: {
      84:     REG CHAR    c, d;
      85:     IF (d=readc())==ESCAPE
      86:     THEN    IF (c=readc())==NL
      87:         THEN    chkpr(NL); d=nextc(quote);
      88:         ELIF quote ANDF c!=quote ANDF !escchar(c)
      89:         THEN    peekc=c|MARK;
      90:         ELSE    d = c|QUOTE;
      91:         FI
      92:     FI
      93:     return(d);
      94: }
      95:
      96: readc()
      97: {
      98:     REG CHAR    c;
      99:     REG INT     len;
     100:     REG FILE    f;
     101:
     102: retry:
     103:     IF peekc
     104:     THEN    c=peekc; peekc=0;
     105:     ELIF (f=standin, f->fnxt!=f->fend)
     106:     THEN    IF (c = *f->fnxt++)==0
     107:         THEN    IF f->feval
     108:             THEN    IF estabf(*f->feval++)
     109:                 THEN    c=EOF;
     110:                 ELSE    c=SP;
     111:                 FI
     112:             ELSE    goto retry; /* = c=readc(); */
     113:             FI
     114:         FI
     115:         IF flags&readpr ANDF standin->fstak==0 THEN prc(c) FI
     116:         IF c==NL THEN f->flin++ FI
     117:     ELIF f->feof ORF f->fdes<0
     118:     THEN    c=EOF; f->feof++;
     119:     ELIF (len=readb())<=0
     120:     THEN    close(f->fdes); f->fdes = -1; c=EOF; f->feof++;
     121:     ELSE    f->fend = (f->fnxt = f->fbuf)+len;
     122:         goto retry;
     123:     FI
     124:     return(c);
     125: }
     126:
     127: LOCAL   readb()
     128: {
     129:     REG FILE    f=standin;
     130:     REG INT     len;
     131:
     132:     IF setjmp(INTbuf) == 0 THEN trapjmp[INTR] = 1; FI
     133:     REP IF trapnote&SIGSET THEN newline(); sigchk() FI
     134:     PER (len=read(f->fdes,f->fbuf,f->fsiz))<0 ANDF trapnote DONE
     135:     trapjmp[INTR] = 0;
     136:     return(len);
     137: }

#### Defined functions

nextc defined in line 81; used 8 times

- in line 29, 48-52(2), 66, 87
- in /usr/src/bin/sh/cmd.c line 341
- in /usr/src/bin/sh/io.c line 128
- in /usr/src/bin/sh/name.c line 144

readb defined in line 127; used 1 times

- in line 119

readc defined in line 96; used 15 times

- in line 33, 39, 85-86(2)
- in /usr/src/bin/sh/io.c line 128
- in /usr/src/bin/sh/macro.c line 38, 45, 59, 65, 73-76(2), 101, 180, 201
- in /usr/src/bin/sh/main.c line 160

word defined in line 21; used 9 times

- in line 58
- in /usr/src/bin/sh/cmd.c line 145, 164-168(2), 293, 304, 314, 358, 364

#### Defined variables

sccsid defined in line 2; never used

Last modified: 1985-11-11 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 773 |