* Copyright (c) 1980, 1991, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)parse.c 8.1 (Berkeley) %G%";
static void asyntax
__P((struct wordent
*, struct wordent
*));
static void asyn0
__P((struct wordent
*, struct wordent
*));
static void asyn3
__P((struct wordent
*, struct wordent
*));
*freenod
__P((struct wordent
*, struct wordent
*));
*syn0
__P((struct wordent
*, struct wordent
*, int));
*syn1
__P((struct wordent
*, struct wordent
*, int));
*syn1a
__P((struct wordent
*, struct wordent
*, int));
*syn1b
__P((struct wordent
*, struct wordent
*, int));
*syn2
__P((struct wordent
*, struct wordent
*, int));
*syn3
__P((struct wordent
*, struct wordent
*, int));
#define ALEFT 21 /* max of 20 alias expansions */
#define HLEFT 11 /* max of 10 history expansions */
* 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(";&\n", p1
->word
[0]))
register struct wordent
*p2
;
register struct wordent
*p
;
for (p
= p1
; p
!= p2
; p
= p
->next
)
if (p
->next
!= p2
&& eq(p
->next
->word
, STRand
))
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(STRQNULL
, 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((ptr_t
) alout
.prev
->word
);
xfree((ptr_t
) (alout
.prev
));
register struct wordent
*p1
, *p2
;
register struct wordent
*retp
= p1
->prev
;
xfree((ptr_t
) (p1
->prev
));
register struct wordent
*p1
, *p2
;
if (any(";&\n", p1
->word
[0]))
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
, STRand
))
if (t1
->t_dtyp
== NODE_LIST
||
t1
->t_dtyp
== NODE_AND
||
t
= (struct command
*) xcalloc(1, sizeof(*t
));
t
->t_dflg
= F_AMPERSAND
| F_NOINTERRUPT
;
t1
->t_dflg
|= F_AMPERSAND
| F_NOINTERRUPT
;
t
= (struct command
*) xcalloc(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
*) xcalloc(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
*) xcalloc(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
*) xcalloc(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
*) xcalloc(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
));
static char RELPAR
[] = {'<', '>', '(', ')', '\0'};
* ( 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(RELPAR
, p
->next
->word
[0]))
t
= (struct command
*) xcalloc(1, sizeof(*t
));
av
= (Char
**) xcalloc((size_t) (n
+ 1), sizeof(Char
**));
for (p
= p1
; p
!= p2
; p
= p
->next
) {
if (p
->next
!= p2
&& eq(p
->next
->word
, STRand
)) {
t
->t_dflg
|= F_STDERR
, p
= p
->next
;
if (flags
& (POUT
| PERR
)) {
if (p
->next
!= p2
&& eq(p
->next
->word
, STRbang
))
t
->t_dflg
|= F_OVERWRITE
, p
= p
->next
;
if (any(RELPAR
, p
->word
[0])) {
if ((flags
& POUT
) && ((flags
& PERR
) == 0 || t
->t_drit
))
t
->t_drit
= Strsave(p
->word
);
if (any(RELPAR
, p
->word
[0])) {
if ((flags
& PHERE
) && (t
->t_dflg
& F_READ
))
else if ((flags
& PIN
) || t
->t_dlef
)
t
->t_dlef
= Strsave(p
->word
);
av
[n
] = Strsave(p
->word
);
t
->t_dspr
= syn0(lp
, rp
, PHERE
);
t
->t_dtyp
= NODE_COMMAND
;
register struct command
*t
;
for (v
= t
->t_dcom
; *v
; v
++)
xfree((ptr_t
) (t
->t_dcom
));
xfree((ptr_t
) t
->t_dlef
);
xfree((ptr_t
) t
->t_drit
);
xfree((ptr_t
) t
->t_dlef
);
xfree((ptr_t
) t
->t_drit
);
freesyn(t
->t_dcar
), freesyn(t
->t_dcdr
);