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

Defined functions

nextc defined in line 70; used 8 times
readb defined in line 116; used 1 times
readc defined in line 85; used 14 times
word defined in line 17; used 9 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 919
Valid CSS Valid XHTML 1.0 Strict