/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley Software License Agreement
* specifies the terms and conditions for redistribution.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "sh.h"
#include "sh.tconst.h"
/*
* C shell
*/
void chr_blkfree(char **);
/*
* Perform aliasing on the word list lex
* Do a (very rudimentary) parse to separate into commands.
* If word 0 of a command has an alias, do it.
* Repeat a maximum of 20 times.
*/
void
{
#ifdef TRACE
tprintf("TRACE- alias()\n");
#endif
setexit();
if (haderr) {
reset();
}
if (--aleft == 0)
error("Alias loop");
}
void
{
#ifdef TRACE
tprintf("TRACE- asyntax()\n");
#endif
/* if (any(p1->word[0], ";&\n")) */ /* For char -> tchar */
else {
return;
}
}
void
{
struct wordent *p;
int l = 0;
#ifdef TRACE
tprintf("TRACE- asyn0()\n");
#endif
switch (p->word[0]) {
case '(':
l++;
continue;
case ')':
l--;
if (l < 0)
error("Too many )'s");
continue;
case '>':
p = p->next;
continue;
case '&':
case '|':
case ';':
case '\n':
if (l != 0)
continue;
return;
}
if (l == 0)
}
void
{
bool redid;
#ifdef TRACE
tprintf("TRACE- asyn3()\n");
#endif
return;
return;
return;
return;
}
if (ap == 0)
return;
alvec = 0;
if (err) {
}
}
}
reset(); /* throw! */
}
struct wordent *
{
#ifdef TRACE
tprintf("TRACE- freenod()\n");
#endif
}
return (retp);
}
/*
* syntax
* empty
* syn0
*/
struct command *
{
#ifdef TRACE
tprintf("TRACE- syntax()\n");
#endif
/* if (any(p1->word[0], ";&\n")) */ /* for char -> tchar */
else
return (0);
}
/*
* syn0
* syn1
* syn1 & syntax
*/
struct command *
{
struct wordent *p;
int l;
#ifdef TRACE
tprintf("TRACE- syn0()\n");
#endif
l = 0;
switch (p->word[0]) {
case '(':
l++;
continue;
case ')':
l--;
if (l < 0)
seterr("Too many )'s");
continue;
case '|':
continue;
/* fall into ... */
case '>':
p = p->next;
continue;
case '&':
if (l != 0)
break;
continue;
t1 = t;
} else
t->t_dflg = 0;
return (t);
}
if (l == 0)
seterr("Too many ('s");
return (0);
}
/*
* syn1
* syn1a
* syn1a ; syntax
*/
struct command *
{
struct wordent *p;
struct command *t;
int l;
#ifdef TRACE
tprintf("TRACE- syn1()\n");
#endif
l = 0;
switch (p->word[0]) {
case '(':
l++;
continue;
case ')':
l--;
continue;
case ';':
case '\n':
if (l != 0)
break;
if (t->t_dcdr == 0)
return (t);
}
}
/*
* syn1a
* syn1b
* syn1b || syn1a
*/
struct command *
{
struct wordent *p;
struct command *t;
int l = 0;
#ifdef TRACE
tprintf("TRACE- syn1a()\n");
#endif
switch (p->word[0]) {
case '(':
l++;
continue;
case ')':
l--;
continue;
case '|':
continue;
if (l == 0) {
t->t_dflg = 0;
return (t);
}
continue;
}
}
/*
* syn1b
* syn2
* syn2 && syn1b
*/
struct command *
{
struct wordent *p;
struct command *t;
int l = 0;
#ifdef TRACE
tprintf("TRACE- syn1b()\n");
#endif
l = 0;
switch (p->word[0]) {
case '(':
l++;
continue;
case ')':
l--;
continue;
case '&':
t->t_dflg = 0;
return (t);
}
continue;
}
}
/*
* syn2
* syn3
* syn3 | syn2
* syn3 |& syn2
*/
struct command *
{
struct command *t;
int l = 0;
int f;
#ifdef TRACE
tprintf("TRACE- syn2()\n");
#endif
switch (p->word[0]) {
case '(':
l++;
continue;
case ')':
l--;
continue;
case '|':
if (l != 0)
continue;
f |= PDIAG;
}
p = pn;
return (t);
}
}
/*
* syn3
* ( syn0 ) [ < in ] [ > out ]
* word word* [ < in ] [ > out ]
* KEYWORD ( word* ) word* [ < in ] [ > out ]
*
* KEYWORD = (@ exit foreach if set switch test while)
*/
struct command *
{
struct wordent *p;
struct command *t;
int l;
int n, c;
bool specp = 0;
#ifdef TRACE
tprintf("TRACE- syn3()\n");
#endif
p = p1;
case ZELSE:
p = p->next;
if (p != p2)
goto again;
break;
case ZEXIT:
case ZFOREACH:
case ZIF:
case ZLET:
case ZSET:
case ZSWITCH:
case ZWHILE:
specp = 1;
break;
}
}
n = 0;
l = 0;
switch (p->word[0]) {
case '(':
if (specp)
n++;
l++;
continue;
case ')':
if (specp)
n++;
l--;
continue;
case '>':
case '<':
if (l != 0) {
if (specp)
n++;
continue;
}
continue;
continue;
n--;
continue;
default:
if (!specp && l != 0)
continue;
n++;
continue;
}
if (n < 0)
n = 0;
n = 0;
lp = 0;
rp = 0;
l = 0;
c = p->word[0];
switch (c) {
case '(':
if (l == 0) {
seterr("Badly placed (");
}
l++;
goto savep;
case ')':
l--;
if (l == 0)
rp = p;
goto savep;
case '>':
if (l != 0)
goto savep;
goto badout;
}
seterr("Missing name for redirect");
continue;
}
p = p->next;
goto missfile;
seterr("Ambiguous output redirect");
else
continue;
case '<':
if (l != 0)
goto savep;
goto missfile;
p = p->next;
goto missfile;
seterr("Can't << within ()'s");
seterr("Ambiguous input redirect");
else
continue;
if (!specp)
continue;
default:
if (l != 0 && !specp)
continue;
if (err == 0)
n++;
continue;
}
}
if (n != 0)
seterr("Badly placed ()'s");
} else {
if (n == 0)
seterr("Invalid null command");
}
return (t);
}
void
{
#ifdef TRACE
tprintf("TRACE- freesyn()\n");
#endif
if (t == 0)
return;
switch (t->t_dtyp) {
case TCOM:
if (t->cfname)
if (t->cargs)
chr_blkfree(t->cargs);
goto lr;
case TPAR:
/* fall into ... */
lr:
break;
case TAND:
case TOR:
case TFIL:
case TLST:
break;
}
xfree(t);
}
void
{
char **av;
}