cmd.c revision 1573d361e97690e67db291a1e0dc9a9b58f73fd8
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* UNIX shell
*/
#include "defs.h"
#include "sym.h"
static void chkword(void);
static void chksym(int);
static int skipnl();
static void prsym(int);
static void synbad(void);
/* ======== storage allocation for functions ======== */
unsigned char *
int asize;
{
if (fndef)
else
}
/* ======== command line decoding ========*/
struct trenod *
int flgs;
struct trenod *i;
{
struct forknod *t;
t->forktre = i;
t->forkio = 0;
return((struct trenod *)t);
}
static struct trenod *
int type;
struct trenod *i, *r;
{
struct lstnod *t;
if (i == 0 || r == 0)
synbad();
else
{
t->lstlef = i;
t->lstrit = r;
}
return((struct trenod *)t);
}
/*
* cmd
* empty
* list
* list & [ cmd ]
* list [ ; cmd ]
*/
struct trenod *
int sym;
int flg;
{
struct trenod *i, *e;
{
{
wdval = ';';
chkpr();
}
}
synbad();
switch (wdval)
{
case '&':
if (i)
else
synbad();
case ';':
else if (i == 0)
synbad();
break;
case EOFSYM:
break;
default:
if (sym)
}
return(i);
}
/*
* list
* term
* list && term
* list || term
*/
static struct trenod *
{
struct trenod *r;
int b;
return(r);
}
/*
* term
* item
* item |^ term
*/
static struct trenod *
{
struct trenod *t;
reserv++;
skipnl();
else
word();
{
}
else
return(t);
}
static struct regnod *
int esym;
{
skipnl();
return(0);
else
{
struct regnod *r =
r->regptr = 0;
for (;;)
{
if (fndef)
{
}
/* 'in' is not a reserved word in this case */
wdval = 0;
}
synbad();
if (wdval == '|')
word();
else
break;
}
else
{
r->regnxt = 0;
}
return(r);
}
}
/*
* item
*
* ( cmd ) [ < in ] [ > out ]
* word word* [ < in ] [ > out ]
* if ... then ... else ... fi
* for ... while ... do ... done
* case ... in ... esac
* begin ... end
*/
static struct trenod *
{
struct trenod *r;
if (flag)
else
io = 0;
switch (wdval)
{
case CASYM:
{
struct swnod *t;
r = (struct trenod *)t;
chkword();
if (fndef)
else
skipnl();
break;
}
case IFSYM:
{
int w;
struct ifnod *t;
r = (struct trenod *)t;
t->eltre = ((w = wdval) == ELSYM ? cmd(FISYM, NLFLG) : (w == EFSYM ? (wdval = IFSYM, item(0)) : 0));
if (w == EFSYM)
return(r);
break;
}
case FORSYM:
{
struct fornod *t;
r = (struct trenod *)t;
t->forlst = 0;
chkword();
if (fndef)
else
{
chkword();
nohash++;
nohash--;
synbad();
chkpr();
skipnl();
}
break;
}
case WHSYM:
case UNSYM:
{
struct whnod *t;
r = (struct trenod *)t;
break;
}
case BRSYM:
break;
case '(':
{
struct parnod *p;
r = makefork(0, p);
break;
}
default:
if (io == 0)
return(0);
case 0:
{
struct comnod *t;
int keywd = 1;
unsigned char *com;
{
struct fndnod *f;
peekn = 0;
if (skipwc() != ')')
synbad();
r = (struct trenod *)f;
if (fndef)
else
reserv++;
fndef++;
skipnl();
fndef--;
{
}
return(r);
}
else
{
r = (struct trenod *)t;
while (wdval == 0)
{
if (fndef)
{
}
{
}
else
{
}
word();
if (flag)
{
if (io)
{
}
else
}
}
*argtail = 0;
{
if (t->comarg)
{
}
}
return(r);
}
}
}
reserv++;
word();
{
r = makefork(0,r);
}
return(r);
}
static int
skipnl()
{
chkpr();
return(wdval);
}
static struct ionod *
{
int iof;
unsigned int c;
switch (wdval)
{
case DOCSYM: /* << */
break;
case APPSYM: /* >> */
case '>':
if (wdnum == 0)
iof |= 1;
{
break;
}
case '<':
if ((c = nextwc()) == '&')
else if (c == '>')
else
break;
default:
return(lastio);
}
chkword();
if (fndef)
else
{
}
word();
return(iop);
}
static void
chkword(void)
{
if (word())
synbad();
}
static void
{
synbad();
}
static void
{
{
sp++;
}
else
{
else
}
}
static void
synbad(void)
{
prp();
{
}
if (wdval)
else
newline();
}