* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley Software License Agreement
* specifies the terms and conditions for redistribution.
static char *sccsid
= "@(#)parse.c 5.3 (Berkeley) %G%";
* 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.
register struct wordent
*lex
;
register struct wordent
*p1
, *p2
;
if (any(p1
->word
[0], ";&\n"))
register struct wordent
*p2
;
register struct wordent
*p
;
for (p
= p1
; p
!= p2
; p
= p
->next
)
if (p
->next
!= p2
&& eq(p
->next
->word
, "&"))
register struct wordent
*p2
;
register struct varent
*ap
;
if (p1
->word
[0] == '(') {
for (p2
= p2
->prev
; p2
->word
[0] != ')'; p2
= p2
->prev
)
ap
= adrof1(p1
->word
, &aliases
);
if (p1
->word
[0] && eq(p1
->word
, alout
.next
->word
)) {
char *cp
= alout
.next
->word
;
alout
.next
->word
= strspl("\200", cp
);
p1
= freenod(p1
, redid
? p2
: p1
->next
);
if (alout
.next
!= &alout
) {
p1
->next
->prev
= alout
.prev
->prev
;
alout
.prev
->prev
->next
= p1
->next
;
XFREE((char *)alout
.prev
)
register struct wordent
*p1
, *p2
;
register struct wordent
*retp
= p1
->prev
;
register struct wordent
*p1
, *p2
;
if (any(p1
->word
[0], ";&\n"))
return (syn0(p1
, p2
, flags
));
register struct wordent
*p
;
register struct command
*t
, *t1
;
for (p
= p1
; p
!= p2
; p
= p
->next
)
if (p
->next
!= p2
&& eq(p
->next
->word
, "&"))
if (t1
->t_dtyp
== TLST
||
t
= (struct command
*) calloc(1, sizeof (*t
));
t
= (struct command
*) calloc(1, sizeof (*t
));
t
->t_dcdr
= syntax(p
, p2
, flags
);
return (syn1(p1
, p2
, flags
));
register struct wordent
*p
;
register struct command
*t
;
for (p
= p1
; p
!= p2
; p
= p
->next
)
t
= (struct command
*) calloc(1, sizeof (*t
));
t
->t_dcar
= syn1a(p1
, p
, flags
);
t
->t_dcdr
= syntax(p
->next
, p2
, flags
);
t
->t_dcdr
= t
->t_dcar
, t
->t_dcar
= 0;
return (syn1a(p1
, p2
, flags
));
register struct wordent
*p
;
register struct command
*t
;
for (p
= p1
; p
!= p2
; p
= p
->next
)
t
= (struct command
*) calloc(1, sizeof (*t
));
t
->t_dcar
= syn1b(p1
, p
, flags
);
t
->t_dcdr
= syn1a(p
->next
, p2
, flags
);
return (syn1b(p1
, p2
, flags
));
register struct wordent
*p
;
register struct command
*t
;
for (p
= p1
; p
!= p2
; p
= p
->next
)
if (p
->word
[1] == '&' && l
== 0) {
t
= (struct command
*) calloc(1, sizeof (*t
));
t
->t_dcar
= syn2(p1
, p
, flags
);
t
->t_dcdr
= syn1b(p
->next
, p2
, flags
);
return (syn2(p1
, p2
, flags
));
register struct wordent
*p
, *pn
;
register struct command
*t
;
for (p
= p1
; p
!= p2
; p
= p
->next
)
t
= (struct command
*) calloc(1, sizeof (*t
));
if (pn
!= p2
&& pn
->word
[0] == '&') {
t
->t_dcar
= syn3(p1
, p
, f
);
if (pn
!= p2
&& pn
->word
[0] == '&')
t
->t_dcdr
= syn2(p
->next
, p2
, flags
| PIN
);
return (syn3(p1
, p2
, flags
));
* ( syn0 ) [ < in ] [ > out ]
* word word* [ < in ] [ > out ]
* KEYWORD ( word* ) word* [ < in ] [ > out ]
* KEYWORD = (@ exit foreach if set switch test while)
register struct wordent
*p
;
register struct command
*t
;
switch (srchx(p
->word
)) {
for (p
= p1
; p
!= p2
; p
= p
->next
)
if (any(p
->next
->word
[0], RELPAR
))
t
= (struct command
*) calloc(1, sizeof (*t
));
av
= (char **) calloc((unsigned) (n
+ 1), sizeof (char **));
for (p
= p1
; p
!= p2
; p
= p
->next
) {
seterr("Badly placed (");
if (p
->next
!= p2
&& eq(p
->next
->word
, "&")) {
t
->t_dflg
|= FDIAG
, p
= p
->next
;
if (flags
& (POUT
|PDIAG
))
if (p
->next
!= p2
&& eq(p
->next
->word
, "!"))
t
->t_dflg
|= FANY
, p
= p
->next
;
seterr("Missing name for redirect");
if (any(p
->word
[0], RELPAR
))
if ((flags
& POUT
) && (flags
& PDIAG
) == 0 || t
->t_drit
)
seterr("Ambiguous output redirect");
t
->t_drit
= savestr(p
->word
);
if (any(p
->word
[0], RELPAR
))
if ((flags
& PHERE
) && (t
->t_dflg
& FHERE
))
seterr("Can't << within ()'s");
else if ((flags
& PIN
) || t
->t_dlef
)
seterr("Ambiguous input redirect");
t
->t_dlef
= savestr(p
->word
);
av
[n
] = savestr(p
->word
);
seterr("Badly placed ()'s");
t
->t_dspr
= syn0(lp
, rp
, PHERE
);
seterr("Invalid null command");
register struct command
*t
;
for (v
= t
->t_dcom
; *v
; v
++)
freesyn(t
->t_dcar
), freesyn(t
->t_dcdr
);