* 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

25
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.144 2008/02/24 15:57:20 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.145 2008/02/24 22:12:36 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -4169,3 +4169,26 @@ expected-exit: e != 0
expected-stderr-pattern:
/\.: missing argument.*\n.*\.: missing argument/
---
name: alias-function-no-conflict
description:
make aliases not conflict with functions
note: for ksh-like functions, the order of preference is
different; bash outputs baz instead of bar in line 2 below
stdin:
alias foo='echo bar'
foo() {
echo baz
}
alias korn='echo bar'
function korn {
echo baz
}
foo
korn
unset -f foo
foo 2>&- || echo rab
expected-stdout:
baz
bar
rab
---

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;
}
}
}