1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate /* 27*0Sstevel@tonic-gate * Copyright (c) 1996, by Sun Microsystems, Inc. 28*0Sstevel@tonic-gate * All rights reserved. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.12.1.4 */ 32*0Sstevel@tonic-gate /* 33*0Sstevel@tonic-gate * UNIX shell 34*0Sstevel@tonic-gate */ 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #include "defs.h" 37*0Sstevel@tonic-gate #include "sym.h" 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate static struct ionod * inout(); 40*0Sstevel@tonic-gate static int chkword(); 41*0Sstevel@tonic-gate static int chksym(); 42*0Sstevel@tonic-gate static struct trenod * term(); 43*0Sstevel@tonic-gate static struct trenod * makelist(); 44*0Sstevel@tonic-gate static struct trenod * list(); 45*0Sstevel@tonic-gate static struct regnod * syncase(); 46*0Sstevel@tonic-gate static struct trenod * item(); 47*0Sstevel@tonic-gate static int skipnl(); 48*0Sstevel@tonic-gate static int prsym(); 49*0Sstevel@tonic-gate static int synbad(); 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate /* ======== storage allocation for functions ======== */ 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate unsigned char * 55*0Sstevel@tonic-gate getstor(asize) 56*0Sstevel@tonic-gate int asize; 57*0Sstevel@tonic-gate { 58*0Sstevel@tonic-gate if (fndef) 59*0Sstevel@tonic-gate return((unsigned char *)alloc(asize)); 60*0Sstevel@tonic-gate else 61*0Sstevel@tonic-gate return(getstak(asize)); 62*0Sstevel@tonic-gate } 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate /* ======== command line decoding ========*/ 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate struct trenod * 71*0Sstevel@tonic-gate makefork(flgs, i) 72*0Sstevel@tonic-gate int flgs; 73*0Sstevel@tonic-gate struct trenod *i; 74*0Sstevel@tonic-gate { 75*0Sstevel@tonic-gate register struct forknod *t; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate t = (struct forknod *)getstor(sizeof(struct forknod)); 78*0Sstevel@tonic-gate t->forktyp = flgs|TFORK; 79*0Sstevel@tonic-gate t->forktre = i; 80*0Sstevel@tonic-gate t->forkio = 0; 81*0Sstevel@tonic-gate return((struct trenod *)t); 82*0Sstevel@tonic-gate } 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate static struct trenod * 85*0Sstevel@tonic-gate makelist(type, i, r) 86*0Sstevel@tonic-gate int type; 87*0Sstevel@tonic-gate struct trenod *i, *r; 88*0Sstevel@tonic-gate { 89*0Sstevel@tonic-gate register struct lstnod *t; 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate if (i == 0 || r == 0) 92*0Sstevel@tonic-gate synbad(); 93*0Sstevel@tonic-gate else 94*0Sstevel@tonic-gate { 95*0Sstevel@tonic-gate t = (struct lstnod *)getstor(sizeof(struct lstnod)); 96*0Sstevel@tonic-gate t->lsttyp = type; 97*0Sstevel@tonic-gate t->lstlef = i; 98*0Sstevel@tonic-gate t->lstrit = r; 99*0Sstevel@tonic-gate } 100*0Sstevel@tonic-gate return((struct trenod *)t); 101*0Sstevel@tonic-gate } 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate /* 104*0Sstevel@tonic-gate * cmd 105*0Sstevel@tonic-gate * empty 106*0Sstevel@tonic-gate * list 107*0Sstevel@tonic-gate * list & [ cmd ] 108*0Sstevel@tonic-gate * list [ ; cmd ] 109*0Sstevel@tonic-gate */ 110*0Sstevel@tonic-gate struct trenod * 111*0Sstevel@tonic-gate cmd(sym, flg) 112*0Sstevel@tonic-gate register int sym; 113*0Sstevel@tonic-gate int flg; 114*0Sstevel@tonic-gate { 115*0Sstevel@tonic-gate register struct trenod *i, *e; 116*0Sstevel@tonic-gate i = list(flg); 117*0Sstevel@tonic-gate if (wdval == NL) 118*0Sstevel@tonic-gate { 119*0Sstevel@tonic-gate if (flg & NLFLG) 120*0Sstevel@tonic-gate { 121*0Sstevel@tonic-gate wdval = ';'; 122*0Sstevel@tonic-gate chkpr(); 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate else if (i == 0 && (flg & MTFLG) == 0) 126*0Sstevel@tonic-gate synbad(); 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate switch (wdval) 129*0Sstevel@tonic-gate { 130*0Sstevel@tonic-gate case '&': 131*0Sstevel@tonic-gate if (i) 132*0Sstevel@tonic-gate i = makefork(FAMP, i); 133*0Sstevel@tonic-gate else 134*0Sstevel@tonic-gate synbad(); 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate case ';': 137*0Sstevel@tonic-gate if (e = cmd(sym, flg | MTFLG)) 138*0Sstevel@tonic-gate i = makelist(TLST, i, e); 139*0Sstevel@tonic-gate else if (i == 0) 140*0Sstevel@tonic-gate synbad(); 141*0Sstevel@tonic-gate break; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate case EOFSYM: 144*0Sstevel@tonic-gate if (sym == NL) 145*0Sstevel@tonic-gate break; 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate default: 148*0Sstevel@tonic-gate if (sym) 149*0Sstevel@tonic-gate chksym(sym); 150*0Sstevel@tonic-gate } 151*0Sstevel@tonic-gate return(i); 152*0Sstevel@tonic-gate } 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate /* 155*0Sstevel@tonic-gate * list 156*0Sstevel@tonic-gate * term 157*0Sstevel@tonic-gate * list && term 158*0Sstevel@tonic-gate * list || term 159*0Sstevel@tonic-gate */ 160*0Sstevel@tonic-gate static struct trenod * 161*0Sstevel@tonic-gate list(flg) 162*0Sstevel@tonic-gate { 163*0Sstevel@tonic-gate register struct trenod *r; 164*0Sstevel@tonic-gate register int b; 165*0Sstevel@tonic-gate r = term(flg); 166*0Sstevel@tonic-gate while (r && ((b = (wdval == ANDFSYM)) || wdval == ORFSYM)) 167*0Sstevel@tonic-gate r = makelist((b ? TAND : TORF), r, term(NLFLG)); 168*0Sstevel@tonic-gate return(r); 169*0Sstevel@tonic-gate } 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate /* 172*0Sstevel@tonic-gate * term 173*0Sstevel@tonic-gate * item 174*0Sstevel@tonic-gate * item |^ term 175*0Sstevel@tonic-gate */ 176*0Sstevel@tonic-gate static struct trenod * 177*0Sstevel@tonic-gate term(flg) 178*0Sstevel@tonic-gate { 179*0Sstevel@tonic-gate register struct trenod *t; 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate reserv++; 182*0Sstevel@tonic-gate if (flg & NLFLG) 183*0Sstevel@tonic-gate skipnl(); 184*0Sstevel@tonic-gate else 185*0Sstevel@tonic-gate word(); 186*0Sstevel@tonic-gate if ((t = item(TRUE)) && (wdval == '^' || wdval == '|')) 187*0Sstevel@tonic-gate { 188*0Sstevel@tonic-gate struct trenod *left; 189*0Sstevel@tonic-gate struct trenod *right; 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate left = makefork(FPOU, t); 192*0Sstevel@tonic-gate right = makefork(FPIN, term(NLFLG)); 193*0Sstevel@tonic-gate return(makefork(0, makelist(TFIL, left, right))); 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate else 196*0Sstevel@tonic-gate return(t); 197*0Sstevel@tonic-gate } 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate 200*0Sstevel@tonic-gate static struct regnod * 201*0Sstevel@tonic-gate syncase(esym) 202*0Sstevel@tonic-gate register int esym; 203*0Sstevel@tonic-gate { 204*0Sstevel@tonic-gate skipnl(); 205*0Sstevel@tonic-gate if (wdval == esym) 206*0Sstevel@tonic-gate return(0); 207*0Sstevel@tonic-gate else 208*0Sstevel@tonic-gate { 209*0Sstevel@tonic-gate register struct regnod *r = (struct regnod *)getstor(sizeof(struct regnod)); 210*0Sstevel@tonic-gate register struct argnod *argp; 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate r->regptr = 0; 213*0Sstevel@tonic-gate for (;;) 214*0Sstevel@tonic-gate { 215*0Sstevel@tonic-gate if (fndef) 216*0Sstevel@tonic-gate { 217*0Sstevel@tonic-gate argp= wdarg; 218*0Sstevel@tonic-gate wdarg = (struct argnod *)alloc(length(argp->argval) + BYTESPERWORD); 219*0Sstevel@tonic-gate movstr(argp->argval, wdarg->argval); 220*0Sstevel@tonic-gate } 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate wdarg->argnxt = r->regptr; 223*0Sstevel@tonic-gate r->regptr = wdarg; 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate /* 'in' is not a reserved word in this case */ 226*0Sstevel@tonic-gate if (wdval == INSYM){ 227*0Sstevel@tonic-gate wdval = 0; 228*0Sstevel@tonic-gate } 229*0Sstevel@tonic-gate if (wdval || (word() != ')' && wdval != '|')) 230*0Sstevel@tonic-gate synbad(); 231*0Sstevel@tonic-gate if (wdval == '|') 232*0Sstevel@tonic-gate word(); 233*0Sstevel@tonic-gate else 234*0Sstevel@tonic-gate break; 235*0Sstevel@tonic-gate } 236*0Sstevel@tonic-gate r->regcom = cmd(0, NLFLG | MTFLG); 237*0Sstevel@tonic-gate if (wdval == ECSYM) 238*0Sstevel@tonic-gate r->regnxt = syncase(esym); 239*0Sstevel@tonic-gate else 240*0Sstevel@tonic-gate { 241*0Sstevel@tonic-gate chksym(esym); 242*0Sstevel@tonic-gate r->regnxt = 0; 243*0Sstevel@tonic-gate } 244*0Sstevel@tonic-gate return(r); 245*0Sstevel@tonic-gate } 246*0Sstevel@tonic-gate } 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gate /* 249*0Sstevel@tonic-gate * item 250*0Sstevel@tonic-gate * 251*0Sstevel@tonic-gate * ( cmd ) [ < in ] [ > out ] 252*0Sstevel@tonic-gate * word word* [ < in ] [ > out ] 253*0Sstevel@tonic-gate * if ... then ... else ... fi 254*0Sstevel@tonic-gate * for ... while ... do ... done 255*0Sstevel@tonic-gate * case ... in ... esac 256*0Sstevel@tonic-gate * begin ... end 257*0Sstevel@tonic-gate */ 258*0Sstevel@tonic-gate static struct trenod * 259*0Sstevel@tonic-gate item(flag) 260*0Sstevel@tonic-gate BOOL flag; 261*0Sstevel@tonic-gate { 262*0Sstevel@tonic-gate register struct trenod *r; 263*0Sstevel@tonic-gate register struct ionod *io; 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate if (flag) 266*0Sstevel@tonic-gate io = inout((struct ionod *)0); 267*0Sstevel@tonic-gate else 268*0Sstevel@tonic-gate io = 0; 269*0Sstevel@tonic-gate switch (wdval) 270*0Sstevel@tonic-gate { 271*0Sstevel@tonic-gate case CASYM: 272*0Sstevel@tonic-gate { 273*0Sstevel@tonic-gate register struct swnod *t; 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate t = (struct swnod *)getstor(sizeof(struct swnod)); 276*0Sstevel@tonic-gate r = (struct trenod *)t; 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate chkword(); 279*0Sstevel@tonic-gate if (fndef) 280*0Sstevel@tonic-gate t->swarg = make(wdarg->argval); 281*0Sstevel@tonic-gate else 282*0Sstevel@tonic-gate t->swarg = wdarg->argval; 283*0Sstevel@tonic-gate skipnl(); 284*0Sstevel@tonic-gate chksym(INSYM | BRSYM); 285*0Sstevel@tonic-gate t->swlst = syncase(wdval == INSYM ? ESSYM : KTSYM); 286*0Sstevel@tonic-gate t->swtyp = TSW; 287*0Sstevel@tonic-gate break; 288*0Sstevel@tonic-gate } 289*0Sstevel@tonic-gate 290*0Sstevel@tonic-gate case IFSYM: 291*0Sstevel@tonic-gate { 292*0Sstevel@tonic-gate register int w; 293*0Sstevel@tonic-gate register struct ifnod *t; 294*0Sstevel@tonic-gate 295*0Sstevel@tonic-gate t = (struct ifnod *)getstor(sizeof(struct ifnod)); 296*0Sstevel@tonic-gate r = (struct trenod *)t; 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gate t->iftyp = TIF; 299*0Sstevel@tonic-gate t->iftre = cmd(THSYM, NLFLG); 300*0Sstevel@tonic-gate t->thtre = cmd(ELSYM | FISYM | EFSYM, NLFLG); 301*0Sstevel@tonic-gate t->eltre = ((w = wdval) == ELSYM ? cmd(FISYM, NLFLG) : (w == EFSYM ? (wdval = IFSYM, item(0)) : 0)); 302*0Sstevel@tonic-gate if (w == EFSYM) 303*0Sstevel@tonic-gate return(r); 304*0Sstevel@tonic-gate break; 305*0Sstevel@tonic-gate } 306*0Sstevel@tonic-gate 307*0Sstevel@tonic-gate case FORSYM: 308*0Sstevel@tonic-gate { 309*0Sstevel@tonic-gate register struct fornod *t; 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gate t = (struct fornod *)getstor(sizeof(struct fornod)); 312*0Sstevel@tonic-gate r = (struct trenod *)t; 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate t->fortyp = TFOR; 315*0Sstevel@tonic-gate t->forlst = 0; 316*0Sstevel@tonic-gate chkword(); 317*0Sstevel@tonic-gate if (fndef) 318*0Sstevel@tonic-gate t->fornam = make(wdarg->argval); 319*0Sstevel@tonic-gate else 320*0Sstevel@tonic-gate t->fornam = wdarg->argval; 321*0Sstevel@tonic-gate if (skipnl() == INSYM) 322*0Sstevel@tonic-gate { 323*0Sstevel@tonic-gate chkword(); 324*0Sstevel@tonic-gate 325*0Sstevel@tonic-gate nohash++; 326*0Sstevel@tonic-gate t->forlst = (struct comnod *)item(0); 327*0Sstevel@tonic-gate nohash--; 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate if (wdval != NL && wdval != ';') 330*0Sstevel@tonic-gate synbad(); 331*0Sstevel@tonic-gate if (wdval == NL) 332*0Sstevel@tonic-gate chkpr(); 333*0Sstevel@tonic-gate skipnl(); 334*0Sstevel@tonic-gate } 335*0Sstevel@tonic-gate chksym(DOSYM | BRSYM); 336*0Sstevel@tonic-gate t->fortre = cmd(wdval == DOSYM ? ODSYM : KTSYM, NLFLG); 337*0Sstevel@tonic-gate break; 338*0Sstevel@tonic-gate } 339*0Sstevel@tonic-gate 340*0Sstevel@tonic-gate case WHSYM: 341*0Sstevel@tonic-gate case UNSYM: 342*0Sstevel@tonic-gate { 343*0Sstevel@tonic-gate register struct whnod *t; 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gate t = (struct whnod *)getstor(sizeof(struct whnod)); 346*0Sstevel@tonic-gate r = (struct trenod *)t; 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gate t->whtyp = (wdval == WHSYM ? TWH : TUN); 349*0Sstevel@tonic-gate t->whtre = cmd(DOSYM, NLFLG); 350*0Sstevel@tonic-gate t->dotre = cmd(ODSYM, NLFLG); 351*0Sstevel@tonic-gate break; 352*0Sstevel@tonic-gate } 353*0Sstevel@tonic-gate 354*0Sstevel@tonic-gate case BRSYM: 355*0Sstevel@tonic-gate r = cmd(KTSYM, NLFLG); 356*0Sstevel@tonic-gate break; 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate case '(': 359*0Sstevel@tonic-gate { 360*0Sstevel@tonic-gate register struct parnod *p; 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate p = (struct parnod *)getstor(sizeof(struct parnod)); 363*0Sstevel@tonic-gate p->partre = cmd(')', NLFLG); 364*0Sstevel@tonic-gate p->partyp = TPAR; 365*0Sstevel@tonic-gate r = makefork(0, p); 366*0Sstevel@tonic-gate break; 367*0Sstevel@tonic-gate } 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate default: 370*0Sstevel@tonic-gate if (io == 0) 371*0Sstevel@tonic-gate return(0); 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gate case 0: 374*0Sstevel@tonic-gate { 375*0Sstevel@tonic-gate register struct comnod *t; 376*0Sstevel@tonic-gate register struct argnod *argp; 377*0Sstevel@tonic-gate register struct argnod **argtail; 378*0Sstevel@tonic-gate register struct argnod **argset = 0; 379*0Sstevel@tonic-gate int keywd = 1; 380*0Sstevel@tonic-gate unsigned char *com; 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate if ((wdval != NL) && ((peekn = skipwc()) == '(')) 383*0Sstevel@tonic-gate { 384*0Sstevel@tonic-gate struct fndnod *f; 385*0Sstevel@tonic-gate struct ionod *saveio; 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gate saveio = iotemp; 388*0Sstevel@tonic-gate peekn = 0; 389*0Sstevel@tonic-gate if (skipwc() != ')') 390*0Sstevel@tonic-gate synbad(); 391*0Sstevel@tonic-gate 392*0Sstevel@tonic-gate f = (struct fndnod *)getstor(sizeof(struct fndnod)); 393*0Sstevel@tonic-gate r = (struct trenod *)f; 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gate f->fndtyp = TFND; 396*0Sstevel@tonic-gate if (fndef) 397*0Sstevel@tonic-gate f->fndnam = make(wdarg->argval); 398*0Sstevel@tonic-gate else 399*0Sstevel@tonic-gate f->fndnam = wdarg->argval; 400*0Sstevel@tonic-gate reserv++; 401*0Sstevel@tonic-gate fndef++; 402*0Sstevel@tonic-gate skipnl(); 403*0Sstevel@tonic-gate f->fndval = (struct trenod *)item(0); 404*0Sstevel@tonic-gate fndef--; 405*0Sstevel@tonic-gate 406*0Sstevel@tonic-gate if (iotemp != saveio) 407*0Sstevel@tonic-gate { 408*0Sstevel@tonic-gate struct ionod *ioptr = iotemp; 409*0Sstevel@tonic-gate 410*0Sstevel@tonic-gate while (ioptr->iolst != saveio) 411*0Sstevel@tonic-gate ioptr = ioptr->iolst; 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate ioptr->iolst = fiotemp; 414*0Sstevel@tonic-gate fiotemp = iotemp; 415*0Sstevel@tonic-gate iotemp = saveio; 416*0Sstevel@tonic-gate } 417*0Sstevel@tonic-gate return(r); 418*0Sstevel@tonic-gate } 419*0Sstevel@tonic-gate else 420*0Sstevel@tonic-gate { 421*0Sstevel@tonic-gate t = (struct comnod *)getstor(sizeof(struct comnod)); 422*0Sstevel@tonic-gate r = (struct trenod *)t; 423*0Sstevel@tonic-gate 424*0Sstevel@tonic-gate t->comio = io; /*initial io chain*/ 425*0Sstevel@tonic-gate argtail = &(t->comarg); 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gate while (wdval == 0) 428*0Sstevel@tonic-gate { 429*0Sstevel@tonic-gate if (fndef) 430*0Sstevel@tonic-gate { 431*0Sstevel@tonic-gate argp = wdarg; 432*0Sstevel@tonic-gate wdarg = (struct argnod *)alloc(length(argp->argval) + BYTESPERWORD); 433*0Sstevel@tonic-gate movstr(argp->argval, wdarg->argval); 434*0Sstevel@tonic-gate } 435*0Sstevel@tonic-gate 436*0Sstevel@tonic-gate argp = wdarg; 437*0Sstevel@tonic-gate if (wdset && keywd) 438*0Sstevel@tonic-gate { 439*0Sstevel@tonic-gate argp->argnxt = (struct argnod *)argset; 440*0Sstevel@tonic-gate argset = (struct argnod **)argp; 441*0Sstevel@tonic-gate } 442*0Sstevel@tonic-gate else 443*0Sstevel@tonic-gate { 444*0Sstevel@tonic-gate *argtail = argp; 445*0Sstevel@tonic-gate argtail = &(argp->argnxt); 446*0Sstevel@tonic-gate keywd = flags & keyflg; 447*0Sstevel@tonic-gate } 448*0Sstevel@tonic-gate word(); 449*0Sstevel@tonic-gate if (flag) 450*0Sstevel@tonic-gate { 451*0Sstevel@tonic-gate if (io) 452*0Sstevel@tonic-gate { 453*0Sstevel@tonic-gate while(io->ionxt) 454*0Sstevel@tonic-gate io = io->ionxt; 455*0Sstevel@tonic-gate io->ionxt = inout((struct ionod *)0); 456*0Sstevel@tonic-gate } 457*0Sstevel@tonic-gate else 458*0Sstevel@tonic-gate t->comio = io = inout((struct ionod *)0); 459*0Sstevel@tonic-gate } 460*0Sstevel@tonic-gate } 461*0Sstevel@tonic-gate 462*0Sstevel@tonic-gate t->comtyp = TCOM; 463*0Sstevel@tonic-gate t->comset = (struct argnod *)argset; 464*0Sstevel@tonic-gate *argtail = 0; 465*0Sstevel@tonic-gate 466*0Sstevel@tonic-gate if (nohash == 0 && (fndef == 0 || (flags & hashflg))) 467*0Sstevel@tonic-gate { 468*0Sstevel@tonic-gate if (t->comarg) 469*0Sstevel@tonic-gate { 470*0Sstevel@tonic-gate com = t->comarg->argval; 471*0Sstevel@tonic-gate if (*com && *com != DOLLAR) 472*0Sstevel@tonic-gate pathlook(com, 0, t->comset); 473*0Sstevel@tonic-gate } 474*0Sstevel@tonic-gate } 475*0Sstevel@tonic-gate 476*0Sstevel@tonic-gate return(r); 477*0Sstevel@tonic-gate } 478*0Sstevel@tonic-gate } 479*0Sstevel@tonic-gate 480*0Sstevel@tonic-gate } 481*0Sstevel@tonic-gate reserv++; 482*0Sstevel@tonic-gate word(); 483*0Sstevel@tonic-gate if (io = inout(io)) 484*0Sstevel@tonic-gate { 485*0Sstevel@tonic-gate r = makefork(0,r); 486*0Sstevel@tonic-gate r->treio = io; 487*0Sstevel@tonic-gate } 488*0Sstevel@tonic-gate return(r); 489*0Sstevel@tonic-gate } 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gate 492*0Sstevel@tonic-gate static int 493*0Sstevel@tonic-gate skipnl() 494*0Sstevel@tonic-gate { 495*0Sstevel@tonic-gate while ((reserv++, word() == NL)) 496*0Sstevel@tonic-gate chkpr(); 497*0Sstevel@tonic-gate return(wdval); 498*0Sstevel@tonic-gate } 499*0Sstevel@tonic-gate 500*0Sstevel@tonic-gate static struct ionod * 501*0Sstevel@tonic-gate inout(lastio) 502*0Sstevel@tonic-gate struct ionod *lastio; 503*0Sstevel@tonic-gate { 504*0Sstevel@tonic-gate register int iof; 505*0Sstevel@tonic-gate register struct ionod *iop; 506*0Sstevel@tonic-gate register unsigned int c; 507*0Sstevel@tonic-gate 508*0Sstevel@tonic-gate iof = wdnum; 509*0Sstevel@tonic-gate switch (wdval) 510*0Sstevel@tonic-gate { 511*0Sstevel@tonic-gate case DOCSYM: /* << */ 512*0Sstevel@tonic-gate iof |= IODOC; 513*0Sstevel@tonic-gate break; 514*0Sstevel@tonic-gate 515*0Sstevel@tonic-gate case APPSYM: /* >> */ 516*0Sstevel@tonic-gate case '>': 517*0Sstevel@tonic-gate if (wdnum == 0) 518*0Sstevel@tonic-gate iof |= 1; 519*0Sstevel@tonic-gate iof |= IOPUT; 520*0Sstevel@tonic-gate if (wdval == APPSYM) 521*0Sstevel@tonic-gate { 522*0Sstevel@tonic-gate iof |= IOAPP; 523*0Sstevel@tonic-gate break; 524*0Sstevel@tonic-gate } 525*0Sstevel@tonic-gate 526*0Sstevel@tonic-gate case '<': 527*0Sstevel@tonic-gate if ((c = nextwc()) == '&') 528*0Sstevel@tonic-gate iof |= IOMOV; 529*0Sstevel@tonic-gate else if (c == '>') 530*0Sstevel@tonic-gate iof |= IORDW; 531*0Sstevel@tonic-gate else 532*0Sstevel@tonic-gate peekn = c | MARK; 533*0Sstevel@tonic-gate break; 534*0Sstevel@tonic-gate 535*0Sstevel@tonic-gate default: 536*0Sstevel@tonic-gate return(lastio); 537*0Sstevel@tonic-gate } 538*0Sstevel@tonic-gate 539*0Sstevel@tonic-gate chkword(); 540*0Sstevel@tonic-gate iop = (struct ionod *)getstor(sizeof(struct ionod)); 541*0Sstevel@tonic-gate 542*0Sstevel@tonic-gate if (fndef) 543*0Sstevel@tonic-gate iop->ioname = (char *) make(wdarg->argval); 544*0Sstevel@tonic-gate else 545*0Sstevel@tonic-gate iop->ioname = (char *) (wdarg->argval); 546*0Sstevel@tonic-gate 547*0Sstevel@tonic-gate iop->iolink = 0; 548*0Sstevel@tonic-gate iop->iofile = iof; 549*0Sstevel@tonic-gate if (iof & IODOC) 550*0Sstevel@tonic-gate { 551*0Sstevel@tonic-gate iop->iolst = iopend; 552*0Sstevel@tonic-gate iopend = iop; 553*0Sstevel@tonic-gate } 554*0Sstevel@tonic-gate word(); 555*0Sstevel@tonic-gate iop->ionxt = inout(lastio); 556*0Sstevel@tonic-gate return(iop); 557*0Sstevel@tonic-gate } 558*0Sstevel@tonic-gate 559*0Sstevel@tonic-gate static int 560*0Sstevel@tonic-gate chkword() 561*0Sstevel@tonic-gate { 562*0Sstevel@tonic-gate if (word()) 563*0Sstevel@tonic-gate synbad(); 564*0Sstevel@tonic-gate } 565*0Sstevel@tonic-gate 566*0Sstevel@tonic-gate static int 567*0Sstevel@tonic-gate chksym(sym) 568*0Sstevel@tonic-gate { 569*0Sstevel@tonic-gate register int x = sym & wdval; 570*0Sstevel@tonic-gate 571*0Sstevel@tonic-gate if (((x & SYMFLG) ? x : sym) != wdval) 572*0Sstevel@tonic-gate synbad(); 573*0Sstevel@tonic-gate } 574*0Sstevel@tonic-gate 575*0Sstevel@tonic-gate static int 576*0Sstevel@tonic-gate prsym(sym) 577*0Sstevel@tonic-gate { 578*0Sstevel@tonic-gate if (sym & SYMFLG) 579*0Sstevel@tonic-gate { 580*0Sstevel@tonic-gate register const struct sysnod *sp = reserved; 581*0Sstevel@tonic-gate 582*0Sstevel@tonic-gate while (sp->sysval && sp->sysval != sym) 583*0Sstevel@tonic-gate sp++; 584*0Sstevel@tonic-gate prs(sp->sysnam); 585*0Sstevel@tonic-gate } 586*0Sstevel@tonic-gate else if (sym == EOFSYM) 587*0Sstevel@tonic-gate prs(endoffile); 588*0Sstevel@tonic-gate else 589*0Sstevel@tonic-gate { 590*0Sstevel@tonic-gate if (sym & SYMREP) 591*0Sstevel@tonic-gate prc(sym); 592*0Sstevel@tonic-gate if (sym == NL) 593*0Sstevel@tonic-gate prs("newline or ;"); 594*0Sstevel@tonic-gate else 595*0Sstevel@tonic-gate prc(sym); 596*0Sstevel@tonic-gate } 597*0Sstevel@tonic-gate } 598*0Sstevel@tonic-gate 599*0Sstevel@tonic-gate static int 600*0Sstevel@tonic-gate synbad() 601*0Sstevel@tonic-gate { 602*0Sstevel@tonic-gate prp(); 603*0Sstevel@tonic-gate prs(synmsg); 604*0Sstevel@tonic-gate if ((flags & ttyflg) == 0) 605*0Sstevel@tonic-gate { 606*0Sstevel@tonic-gate prs(atline); 607*0Sstevel@tonic-gate prn(standin->flin); 608*0Sstevel@tonic-gate } 609*0Sstevel@tonic-gate prs(colon); 610*0Sstevel@tonic-gate prc(LQ); 611*0Sstevel@tonic-gate if (wdval) 612*0Sstevel@tonic-gate prsym(wdval); 613*0Sstevel@tonic-gate else 614*0Sstevel@tonic-gate prs_cntl(wdarg->argval); 615*0Sstevel@tonic-gate prc(RQ); 616*0Sstevel@tonic-gate prs(unexpected); 617*0Sstevel@tonic-gate newline(); 618*0Sstevel@tonic-gate exitsh(SYNBAD); 619*0Sstevel@tonic-gate } 620