* lex.c: Don't expand aliases if there's an opening bracket just after

the token. Fixes unreported problem with pdksh reporting syntax error
    on the init scripts that define function named ‘stop’ (clashing
    with an built-in alias.)

 -- Robert Luberda <robert@debian.org>  Sun, 27 Feb 2005 18:36:55 +0100
This commit is contained in:
tg
2008-02-24 22:12:36 +00:00
parent 635bdac720
commit 8c86fedc2d
2 changed files with 45 additions and 14 deletions

34
lex.c
View File

@@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.48 2007/10/25 15:27:54 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.49 2008/02/24 22:12:36 tg Exp $");
/* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state. */
@@ -124,6 +124,7 @@ yylex(int cf)
char *wp; /* output word pointer */
char *sp, *dp;
int c2;
bool last_terminal_was_bracket;
Again:
states[0].ls_state = -1;
@@ -793,6 +794,8 @@ yylex(int cf)
if (state == SWORD || state == SLETPAREN ||
state == SLETARRAY) /* ONEWORD? */
return LWORD;
last_terminal_was_bracket = c == '(';
ungetsc(c); /* unget terminator */
/* copy word to unprefixed string ident */
@@ -815,19 +818,24 @@ yylex(int cf)
}
if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
(p->flag & ISSET)) {
Source *s;
if (last_terminal_was_bracket)
/* prefer functions over aliases */
ktdelete(p);
else {
Source *s;
for (s = source; s->type == SALIAS; s = s->next)
if (s->u.tblp == p)
return LWORD;
/* push alias expansion */
s = pushs(SALIAS, source->areap);
s->start = s->str = p->val.s;
s->u.tblp = p;
s->next = source;
source = s;
afree(yylval.cp, ATEMP);
goto Again;
for (s = source; s->type == SALIAS; s = s->next)
if (s->u.tblp == p)
return LWORD;
/* push alias expansion */
s = pushs(SALIAS, source->areap);
s->start = s->str = p->val.s;
s->u.tblp = p;
s->next = source;
source = s;
afree(yylval.cp, ATEMP);
goto Again;
}
}
}