1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.10.4.1 */ 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate /* 29*7c478bd9Sstevel@tonic-gate * UNIX shell 30*7c478bd9Sstevel@tonic-gate */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include "defs.h" 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate static struct dolnod *copyargs(); 35*7c478bd9Sstevel@tonic-gate static struct dolnod *freedolh(); 36*7c478bd9Sstevel@tonic-gate extern struct dolnod *freeargs(); 37*7c478bd9Sstevel@tonic-gate static struct dolnod *dolh; 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate /* Used to save outermost positional parameters */ 40*7c478bd9Sstevel@tonic-gate static struct dolnod *globdolh; 41*7c478bd9Sstevel@tonic-gate static unsigned char **globdolv; 42*7c478bd9Sstevel@tonic-gate static int globdolc; 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate unsigned char flagadr[16]; 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate unsigned char flagchar[] = 47*7c478bd9Sstevel@tonic-gate { 48*7c478bd9Sstevel@tonic-gate 'x', 49*7c478bd9Sstevel@tonic-gate 'n', 50*7c478bd9Sstevel@tonic-gate 'v', 51*7c478bd9Sstevel@tonic-gate 't', 52*7c478bd9Sstevel@tonic-gate STDFLG, 53*7c478bd9Sstevel@tonic-gate 'i', 54*7c478bd9Sstevel@tonic-gate 'e', 55*7c478bd9Sstevel@tonic-gate 'r', 56*7c478bd9Sstevel@tonic-gate 'k', 57*7c478bd9Sstevel@tonic-gate 'u', 58*7c478bd9Sstevel@tonic-gate 'h', 59*7c478bd9Sstevel@tonic-gate 'f', 60*7c478bd9Sstevel@tonic-gate 'a', 61*7c478bd9Sstevel@tonic-gate 'm', 62*7c478bd9Sstevel@tonic-gate 'p', 63*7c478bd9Sstevel@tonic-gate 0 64*7c478bd9Sstevel@tonic-gate }; 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate long flagval[] = 67*7c478bd9Sstevel@tonic-gate { 68*7c478bd9Sstevel@tonic-gate execpr, 69*7c478bd9Sstevel@tonic-gate noexec, 70*7c478bd9Sstevel@tonic-gate readpr, 71*7c478bd9Sstevel@tonic-gate oneflg, 72*7c478bd9Sstevel@tonic-gate stdflg, 73*7c478bd9Sstevel@tonic-gate intflg, 74*7c478bd9Sstevel@tonic-gate errflg, 75*7c478bd9Sstevel@tonic-gate rshflg, 76*7c478bd9Sstevel@tonic-gate keyflg, 77*7c478bd9Sstevel@tonic-gate setflg, 78*7c478bd9Sstevel@tonic-gate hashflg, 79*7c478bd9Sstevel@tonic-gate nofngflg, 80*7c478bd9Sstevel@tonic-gate exportflg, 81*7c478bd9Sstevel@tonic-gate monitorflg, 82*7c478bd9Sstevel@tonic-gate privflg, 83*7c478bd9Sstevel@tonic-gate 0 84*7c478bd9Sstevel@tonic-gate }; 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate /* ======== option handling ======== */ 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate options(argc,argv) 90*7c478bd9Sstevel@tonic-gate unsigned char **argv; 91*7c478bd9Sstevel@tonic-gate int argc; 92*7c478bd9Sstevel@tonic-gate { 93*7c478bd9Sstevel@tonic-gate register unsigned char *cp; 94*7c478bd9Sstevel@tonic-gate register unsigned char **argp = argv; 95*7c478bd9Sstevel@tonic-gate register unsigned char *flagc; 96*7c478bd9Sstevel@tonic-gate unsigned char *flagp; 97*7c478bd9Sstevel@tonic-gate int len; 98*7c478bd9Sstevel@tonic-gate wchar_t wc; 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate if (argc > 1 && *argp[1] == '-') 101*7c478bd9Sstevel@tonic-gate { 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate * if first argument is "--" then options are not 104*7c478bd9Sstevel@tonic-gate * to be changed. Fix for problems getting 105*7c478bd9Sstevel@tonic-gate * $1 starting with a "-" 106*7c478bd9Sstevel@tonic-gate */ 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate cp = argp[1]; 109*7c478bd9Sstevel@tonic-gate if (cp[1] == '-') 110*7c478bd9Sstevel@tonic-gate { 111*7c478bd9Sstevel@tonic-gate argp[1] = argp[0]; 112*7c478bd9Sstevel@tonic-gate argc--; 113*7c478bd9Sstevel@tonic-gate return(argc); 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate if (cp[1] == '\0') 116*7c478bd9Sstevel@tonic-gate flags &= ~(execpr|readpr); 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate /* 119*7c478bd9Sstevel@tonic-gate * Step along 'flagchar[]' looking for matches. 120*7c478bd9Sstevel@tonic-gate * 'sicrp' are not legal with 'set' command. 121*7c478bd9Sstevel@tonic-gate */ 122*7c478bd9Sstevel@tonic-gate cp++; 123*7c478bd9Sstevel@tonic-gate while (*cp) { 124*7c478bd9Sstevel@tonic-gate if ((len = mbtowc(&wc, (char *)cp, MB_LEN_MAX)) <= 0) { 125*7c478bd9Sstevel@tonic-gate len = 1; 126*7c478bd9Sstevel@tonic-gate wc = (unsigned char)*cp; 127*7c478bd9Sstevel@tonic-gate failed(argv[1],badopt); 128*7c478bd9Sstevel@tonic-gate } 129*7c478bd9Sstevel@tonic-gate cp += len; 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate flagc = flagchar; 132*7c478bd9Sstevel@tonic-gate while (*flagc && wc != *flagc) 133*7c478bd9Sstevel@tonic-gate flagc++; 134*7c478bd9Sstevel@tonic-gate if (wc == *flagc) 135*7c478bd9Sstevel@tonic-gate { 136*7c478bd9Sstevel@tonic-gate if (eq(argv[0], "set") && any(wc, "sicrp")) 137*7c478bd9Sstevel@tonic-gate failed(argv[1], badopt); 138*7c478bd9Sstevel@tonic-gate else 139*7c478bd9Sstevel@tonic-gate { 140*7c478bd9Sstevel@tonic-gate flags |= flagval[flagc-flagchar]; 141*7c478bd9Sstevel@tonic-gate if (flags & errflg) 142*7c478bd9Sstevel@tonic-gate eflag = errflg; 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate else if (wc == 'c' && argc > 2 && comdiv == 0) 146*7c478bd9Sstevel@tonic-gate { 147*7c478bd9Sstevel@tonic-gate comdiv = argp[2]; 148*7c478bd9Sstevel@tonic-gate argp[1] = argp[0]; 149*7c478bd9Sstevel@tonic-gate argp++; 150*7c478bd9Sstevel@tonic-gate argc--; 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate else 153*7c478bd9Sstevel@tonic-gate failed(argv[1],badopt); 154*7c478bd9Sstevel@tonic-gate } 155*7c478bd9Sstevel@tonic-gate argp[1] = argp[0]; 156*7c478bd9Sstevel@tonic-gate argc--; 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate else if (argc > 1 && *argp[1] == '+') /* unset flags x, k, t, n, v, e, u */ 159*7c478bd9Sstevel@tonic-gate { 160*7c478bd9Sstevel@tonic-gate cp = argp[1]; 161*7c478bd9Sstevel@tonic-gate cp++; 162*7c478bd9Sstevel@tonic-gate while (*cp) 163*7c478bd9Sstevel@tonic-gate { 164*7c478bd9Sstevel@tonic-gate if ((len = mbtowc(&wc, (char *)cp, MB_LEN_MAX)) <= 0) { 165*7c478bd9Sstevel@tonic-gate cp++; 166*7c478bd9Sstevel@tonic-gate continue; 167*7c478bd9Sstevel@tonic-gate } 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate flagc = flagchar; 170*7c478bd9Sstevel@tonic-gate while (*flagc && wc != *flagc) 171*7c478bd9Sstevel@tonic-gate flagc++; 172*7c478bd9Sstevel@tonic-gate /* 173*7c478bd9Sstevel@tonic-gate * step through flags 174*7c478bd9Sstevel@tonic-gate */ 175*7c478bd9Sstevel@tonic-gate if (!any(wc, "sicrp") && wc == *flagc) { 176*7c478bd9Sstevel@tonic-gate flags &= ~(flagval[flagc-flagchar]); 177*7c478bd9Sstevel@tonic-gate if (wc == 'e') 178*7c478bd9Sstevel@tonic-gate eflag = 0; 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate cp += len; 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate argp[1] = argp[0]; 183*7c478bd9Sstevel@tonic-gate argc--; 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate /* 186*7c478bd9Sstevel@tonic-gate * set up $- 187*7c478bd9Sstevel@tonic-gate */ 188*7c478bd9Sstevel@tonic-gate flagp = flagadr; 189*7c478bd9Sstevel@tonic-gate if (flags) 190*7c478bd9Sstevel@tonic-gate { 191*7c478bd9Sstevel@tonic-gate flagc = flagchar; 192*7c478bd9Sstevel@tonic-gate while (*flagc) 193*7c478bd9Sstevel@tonic-gate { 194*7c478bd9Sstevel@tonic-gate if (flags & flagval[flagc-flagchar]) 195*7c478bd9Sstevel@tonic-gate *flagp++ = *flagc; 196*7c478bd9Sstevel@tonic-gate flagc++; 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate *flagp = 0; 200*7c478bd9Sstevel@tonic-gate return(argc); 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate /* 204*7c478bd9Sstevel@tonic-gate * sets up positional parameters 205*7c478bd9Sstevel@tonic-gate */ 206*7c478bd9Sstevel@tonic-gate setargs(argi) 207*7c478bd9Sstevel@tonic-gate unsigned char *argi[]; 208*7c478bd9Sstevel@tonic-gate { 209*7c478bd9Sstevel@tonic-gate register unsigned char **argp = argi; /* count args */ 210*7c478bd9Sstevel@tonic-gate register int argn = 0; 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate while (*argp++ != (unsigned char *)ENDARGS) 213*7c478bd9Sstevel@tonic-gate argn++; 214*7c478bd9Sstevel@tonic-gate /* 215*7c478bd9Sstevel@tonic-gate * free old ones unless on for loop chain 216*7c478bd9Sstevel@tonic-gate */ 217*7c478bd9Sstevel@tonic-gate freedolh(); 218*7c478bd9Sstevel@tonic-gate dolh = copyargs(argi, argn); 219*7c478bd9Sstevel@tonic-gate dolc = argn - 1; 220*7c478bd9Sstevel@tonic-gate } 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gate static struct dolnod * 224*7c478bd9Sstevel@tonic-gate freedolh() 225*7c478bd9Sstevel@tonic-gate { 226*7c478bd9Sstevel@tonic-gate register unsigned char **argp; 227*7c478bd9Sstevel@tonic-gate register struct dolnod *argblk; 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate if (argblk = dolh) 230*7c478bd9Sstevel@tonic-gate { 231*7c478bd9Sstevel@tonic-gate if ((--argblk->doluse) == 0) 232*7c478bd9Sstevel@tonic-gate { 233*7c478bd9Sstevel@tonic-gate for (argp = argblk->dolarg; *argp != (unsigned char *)ENDARGS; argp++) 234*7c478bd9Sstevel@tonic-gate free(*argp); 235*7c478bd9Sstevel@tonic-gate free(argblk->dolarg); 236*7c478bd9Sstevel@tonic-gate free(argblk); 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate } 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate struct dolnod * 242*7c478bd9Sstevel@tonic-gate freeargs(blk) 243*7c478bd9Sstevel@tonic-gate struct dolnod *blk; 244*7c478bd9Sstevel@tonic-gate { 245*7c478bd9Sstevel@tonic-gate register unsigned char **argp; 246*7c478bd9Sstevel@tonic-gate register struct dolnod *argr = 0; 247*7c478bd9Sstevel@tonic-gate register struct dolnod *argblk; 248*7c478bd9Sstevel@tonic-gate int cnt; 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate if (argblk = blk) 251*7c478bd9Sstevel@tonic-gate { 252*7c478bd9Sstevel@tonic-gate argr = argblk->dolnxt; 253*7c478bd9Sstevel@tonic-gate cnt = --argblk->doluse; 254*7c478bd9Sstevel@tonic-gate 255*7c478bd9Sstevel@tonic-gate if (argblk == dolh) 256*7c478bd9Sstevel@tonic-gate { 257*7c478bd9Sstevel@tonic-gate if (cnt == 1) 258*7c478bd9Sstevel@tonic-gate return(argr); 259*7c478bd9Sstevel@tonic-gate else 260*7c478bd9Sstevel@tonic-gate return(argblk); 261*7c478bd9Sstevel@tonic-gate } 262*7c478bd9Sstevel@tonic-gate else 263*7c478bd9Sstevel@tonic-gate { 264*7c478bd9Sstevel@tonic-gate if (cnt == 0) 265*7c478bd9Sstevel@tonic-gate { 266*7c478bd9Sstevel@tonic-gate for (argp = argblk->dolarg; *argp != (unsigned char *)ENDARGS; argp++) 267*7c478bd9Sstevel@tonic-gate free(*argp); 268*7c478bd9Sstevel@tonic-gate free(argblk->dolarg); 269*7c478bd9Sstevel@tonic-gate free(argblk); 270*7c478bd9Sstevel@tonic-gate } 271*7c478bd9Sstevel@tonic-gate } 272*7c478bd9Sstevel@tonic-gate } 273*7c478bd9Sstevel@tonic-gate return(argr); 274*7c478bd9Sstevel@tonic-gate } 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate static struct dolnod * 277*7c478bd9Sstevel@tonic-gate copyargs(from, n) 278*7c478bd9Sstevel@tonic-gate unsigned char *from[]; 279*7c478bd9Sstevel@tonic-gate { 280*7c478bd9Sstevel@tonic-gate register struct dolnod *np = (struct dolnod *)alloc(sizeof(struct dolnod)); 281*7c478bd9Sstevel@tonic-gate register unsigned char **fp = from; 282*7c478bd9Sstevel@tonic-gate register unsigned char **pp; 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate np -> dolnxt = 0; 285*7c478bd9Sstevel@tonic-gate np->doluse = 1; /* use count */ 286*7c478bd9Sstevel@tonic-gate pp = np->dolarg = (unsigned char **)alloc((n+1)*sizeof(char *)); 287*7c478bd9Sstevel@tonic-gate dolv = pp; 288*7c478bd9Sstevel@tonic-gate 289*7c478bd9Sstevel@tonic-gate while (n--) 290*7c478bd9Sstevel@tonic-gate *pp++ = make(*fp++); 291*7c478bd9Sstevel@tonic-gate *pp++ = ENDARGS; 292*7c478bd9Sstevel@tonic-gate return(np); 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate struct dolnod * 297*7c478bd9Sstevel@tonic-gate clean_args(blk) 298*7c478bd9Sstevel@tonic-gate struct dolnod *blk; 299*7c478bd9Sstevel@tonic-gate { 300*7c478bd9Sstevel@tonic-gate register unsigned char **argp; 301*7c478bd9Sstevel@tonic-gate register struct dolnod *argr = 0; 302*7c478bd9Sstevel@tonic-gate register struct dolnod *argblk; 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate if (argblk = blk) 305*7c478bd9Sstevel@tonic-gate { 306*7c478bd9Sstevel@tonic-gate argr = argblk->dolnxt; 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate if (argblk == dolh) 309*7c478bd9Sstevel@tonic-gate argblk->doluse = 1; 310*7c478bd9Sstevel@tonic-gate else 311*7c478bd9Sstevel@tonic-gate { 312*7c478bd9Sstevel@tonic-gate for (argp = argblk->dolarg; *argp != (unsigned char *)ENDARGS; argp++) 313*7c478bd9Sstevel@tonic-gate free(*argp); 314*7c478bd9Sstevel@tonic-gate free(argblk->dolarg); 315*7c478bd9Sstevel@tonic-gate free(argblk); 316*7c478bd9Sstevel@tonic-gate } 317*7c478bd9Sstevel@tonic-gate } 318*7c478bd9Sstevel@tonic-gate return(argr); 319*7c478bd9Sstevel@tonic-gate } 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate clearup() 322*7c478bd9Sstevel@tonic-gate { 323*7c478bd9Sstevel@tonic-gate /* 324*7c478bd9Sstevel@tonic-gate * force `for' $* lists to go away 325*7c478bd9Sstevel@tonic-gate */ 326*7c478bd9Sstevel@tonic-gate if(globdolv) 327*7c478bd9Sstevel@tonic-gate dolv = globdolv; 328*7c478bd9Sstevel@tonic-gate if(globdolc) 329*7c478bd9Sstevel@tonic-gate dolc = globdolc; 330*7c478bd9Sstevel@tonic-gate if(globdolh) 331*7c478bd9Sstevel@tonic-gate dolh = globdolh; 332*7c478bd9Sstevel@tonic-gate globdolv = 0; 333*7c478bd9Sstevel@tonic-gate globdolc = 0; 334*7c478bd9Sstevel@tonic-gate globdolh = 0; 335*7c478bd9Sstevel@tonic-gate while (argfor = clean_args(argfor)) 336*7c478bd9Sstevel@tonic-gate ; 337*7c478bd9Sstevel@tonic-gate /* 338*7c478bd9Sstevel@tonic-gate * clean up io files 339*7c478bd9Sstevel@tonic-gate */ 340*7c478bd9Sstevel@tonic-gate while (pop()) 341*7c478bd9Sstevel@tonic-gate ; 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate /* 344*7c478bd9Sstevel@tonic-gate * Clean up pipe file descriptor 345*7c478bd9Sstevel@tonic-gate * from command substitution 346*7c478bd9Sstevel@tonic-gate */ 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate if(savpipe != -1) { 349*7c478bd9Sstevel@tonic-gate close(savpipe); 350*7c478bd9Sstevel@tonic-gate savpipe = -1; 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate 353*7c478bd9Sstevel@tonic-gate /* 354*7c478bd9Sstevel@tonic-gate * clean up tmp files 355*7c478bd9Sstevel@tonic-gate */ 356*7c478bd9Sstevel@tonic-gate while (poptemp()) 357*7c478bd9Sstevel@tonic-gate ; 358*7c478bd9Sstevel@tonic-gate } 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate /* 361*7c478bd9Sstevel@tonic-gate * Save positiional parameters before outermost function invocation 362*7c478bd9Sstevel@tonic-gate * in case we are interrupted. 363*7c478bd9Sstevel@tonic-gate * Increment use count for current positional parameters so that they aren't thrown 364*7c478bd9Sstevel@tonic-gate * away. 365*7c478bd9Sstevel@tonic-gate */ 366*7c478bd9Sstevel@tonic-gate 367*7c478bd9Sstevel@tonic-gate struct dolnod *savargs(funcnt) 368*7c478bd9Sstevel@tonic-gate int funcnt; 369*7c478bd9Sstevel@tonic-gate { 370*7c478bd9Sstevel@tonic-gate if (!funcnt) { 371*7c478bd9Sstevel@tonic-gate globdolh = dolh; 372*7c478bd9Sstevel@tonic-gate globdolv = dolv; 373*7c478bd9Sstevel@tonic-gate globdolc = dolc; 374*7c478bd9Sstevel@tonic-gate } 375*7c478bd9Sstevel@tonic-gate useargs(); 376*7c478bd9Sstevel@tonic-gate return(dolh); 377*7c478bd9Sstevel@tonic-gate } 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate /* After function invocation, free positional parameters, 380*7c478bd9Sstevel@tonic-gate * restore old positional parameters, and restore 381*7c478bd9Sstevel@tonic-gate * use count. 382*7c478bd9Sstevel@tonic-gate */ 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate void restorargs(olddolh, funcnt) 385*7c478bd9Sstevel@tonic-gate struct dolnod *olddolh; 386*7c478bd9Sstevel@tonic-gate { 387*7c478bd9Sstevel@tonic-gate if(argfor != olddolh) 388*7c478bd9Sstevel@tonic-gate while ((argfor = clean_args(argfor)) != olddolh && argfor); 389*7c478bd9Sstevel@tonic-gate if(!argfor) 390*7c478bd9Sstevel@tonic-gate return; 391*7c478bd9Sstevel@tonic-gate freedolh(); 392*7c478bd9Sstevel@tonic-gate dolh = olddolh; 393*7c478bd9Sstevel@tonic-gate if(dolh) 394*7c478bd9Sstevel@tonic-gate dolh -> doluse++; /* increment use count so arguments aren't freed */ 395*7c478bd9Sstevel@tonic-gate argfor = freeargs(dolh); 396*7c478bd9Sstevel@tonic-gate if(funcnt == 1) { 397*7c478bd9Sstevel@tonic-gate globdolh = 0; 398*7c478bd9Sstevel@tonic-gate globdolv = 0; 399*7c478bd9Sstevel@tonic-gate globdolc = 0; 400*7c478bd9Sstevel@tonic-gate } 401*7c478bd9Sstevel@tonic-gate } 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate struct dolnod * 404*7c478bd9Sstevel@tonic-gate useargs() 405*7c478bd9Sstevel@tonic-gate { 406*7c478bd9Sstevel@tonic-gate if (dolh) 407*7c478bd9Sstevel@tonic-gate { 408*7c478bd9Sstevel@tonic-gate if (dolh->doluse++ == 1) 409*7c478bd9Sstevel@tonic-gate { 410*7c478bd9Sstevel@tonic-gate dolh->dolnxt = argfor; 411*7c478bd9Sstevel@tonic-gate argfor = dolh; 412*7c478bd9Sstevel@tonic-gate } 413*7c478bd9Sstevel@tonic-gate } 414*7c478bd9Sstevel@tonic-gate return(dolh); 415*7c478bd9Sstevel@tonic-gate } 416*7c478bd9Sstevel@tonic-gate 417