1: #ifndef lint
   2: static char sccsid[] = "@(#)args.c	4.4 7/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: 
  16: PROC STRING *copyargs();
  17: LOCAL DOLPTR    dolh;
  18: 
  19: CHAR    flagadr[10];
  20: 
  21: CHAR    flagchar[] = {
  22:     'x',    'n',    'v',    't',    's',    'i',    'e',    'r',    'k',    'u',    0
  23: };
  24: INT flagval[]  = {
  25:     execpr, noexec, readpr, oneflg, stdflg, intflg, errflg, rshflg, keyflg, setflg, 0
  26: };
  27: 
  28: /* ========	option handling	======== */
  29: 
  30: 
  31: INT options(argc,argv)
  32:     STRING      *argv;
  33:     INT     argc;
  34: {
  35:     REG STRING  cp;
  36:     REG STRING  *argp=argv;
  37:     REG STRING  flagc;
  38:     STRING      flagp;
  39: 
  40:     IF argc>1 ANDF *argp[1]=='-'
  41:     THEN    cp=argp[1];
  42:         flags &= ~(execpr|readpr);
  43:         WHILE *++cp
  44:         DO  flagc=flagchar;
  45: 
  46:             WHILE *flagc ANDF *flagc != *cp DO flagc++ OD
  47:             IF *cp == *flagc
  48:             THEN    flags |= flagval[flagc-flagchar];
  49:             ELIF *cp=='c' ANDF argc>2 ANDF comdiv==0
  50:             THEN    comdiv=argp[2];
  51:                 argp[1]=argp[0]; argp++; argc--;
  52:             ELSE    failed(argv[1],badopt);
  53:             FI
  54:         OD
  55:         argp[1]=argp[0]; argc--;
  56:     FI
  57: 
  58:     /* set up $- */
  59:     flagc=flagchar;
  60:     flagp=flagadr;
  61:     WHILE *flagc
  62:     DO IF flags&flagval[flagc-flagchar]
  63:        THEN *flagp++ = *flagc;
  64:        FI
  65:        flagc++;
  66:     OD
  67:     *flagp++=0;
  68: 
  69:     return(argc);
  70: }
  71: 
  72: VOID    setargs(argi)
  73:     STRING      argi[];
  74: {
  75:     /* count args */
  76:     REG STRING  *argp=argi;
  77:     REG INT     argn=0;
  78: 
  79:     WHILE Rcheat(*argp++)!=ENDARGS DO argn++ OD
  80: 
  81:     /* free old ones unless on for loop chain */
  82:     freeargs(dolh);
  83:     dolh=copyargs(argi,argn);   /* sets dolv */
  84:     assnum(&dolladr,dolc=argn-1);
  85: }
  86: 
  87: freeargs(blk)
  88:     DOLPTR      blk;
  89: {
  90:     REG STRING  *argp;
  91:     REG DOLPTR  argr=0;
  92:     REG DOLPTR  argblk;
  93: 
  94:     IF argblk=blk
  95:     THEN    argr = argblk->dolnxt;
  96:         IF (--argblk->doluse)==0
  97:         THEN    FOR argp=argblk->dolarg; Rcheat(*argp)!=ENDARGS; argp++
  98:             DO free(*argp) OD
  99:             free(argblk);
 100:         FI
 101:     FI
 102:     return(argr);
 103: }
 104: 
 105: LOCAL STRING *  copyargs(from, n)
 106:     STRING      from[];
 107: {
 108:     REG STRING *    np=alloc(sizeof(STRING*)*n+3*BYTESPERWORD);
 109:     REG STRING *    fp=from;
 110:     REG STRING *    pp=np;
 111: 
 112:     np->doluse=1;   /* use count */
 113:     np=np->dolarg;
 114:     dolv=np;
 115: 
 116:     WHILE n--
 117:     DO *np++ = make(*fp++) OD
 118:     *np++ = ENDARGS;
 119:     return(pp);
 120: }
 121: 
 122: clearup()
 123: {
 124:     /* force `for' $* lists to go away */
 125:     WHILE argfor=freeargs(argfor) DONE
 126: 
 127:     /* clean up io files */
 128:     WHILE pop() DONE
 129: }
 130: 
 131: DOLPTR  useargs()
 132: {
 133:     IF dolh
 134:     THEN    dolh->doluse++;
 135:         dolh->dolnxt=argfor;
 136:         return(argfor=dolh);
 137:     ELSE    return(0);
 138:     FI
 139: }

Defined functions

clearup defined in line 122; used 2 times
copyargs defined in line 105; used 2 times
freeargs defined in line 87; used 3 times
options defined in line 31; used 2 times
setargs defined in line 72; used 3 times
useargs defined in line 131; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1985-08-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2504
Valid CSS Valid XHTML 1.0 Strict