* 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:
parent
635bdac720
commit
8c86fedc2d
25
check.t
25
check.t
|
@ -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: 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: 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 $
|
# $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:
|
expected-stderr-pattern:
|
||||||
/\.: missing argument.*\n.*\.: missing argument/
|
/\.: 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
|
||||||
|
---
|
||||||
|
|
10
lex.c
10
lex.c
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "sh.h"
|
#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
|
/* Structure to keep track of the lexing state and the various pieces of info
|
||||||
* needed for each particular state. */
|
* needed for each particular state. */
|
||||||
|
@ -124,6 +124,7 @@ yylex(int cf)
|
||||||
char *wp; /* output word pointer */
|
char *wp; /* output word pointer */
|
||||||
char *sp, *dp;
|
char *sp, *dp;
|
||||||
int c2;
|
int c2;
|
||||||
|
bool last_terminal_was_bracket;
|
||||||
|
|
||||||
Again:
|
Again:
|
||||||
states[0].ls_state = -1;
|
states[0].ls_state = -1;
|
||||||
|
@ -793,6 +794,8 @@ yylex(int cf)
|
||||||
if (state == SWORD || state == SLETPAREN ||
|
if (state == SWORD || state == SLETPAREN ||
|
||||||
state == SLETARRAY) /* ONEWORD? */
|
state == SLETARRAY) /* ONEWORD? */
|
||||||
return LWORD;
|
return LWORD;
|
||||||
|
|
||||||
|
last_terminal_was_bracket = c == '(';
|
||||||
ungetsc(c); /* unget terminator */
|
ungetsc(c); /* unget terminator */
|
||||||
|
|
||||||
/* copy word to unprefixed string ident */
|
/* copy word to unprefixed string ident */
|
||||||
|
@ -815,6 +818,10 @@ yylex(int cf)
|
||||||
}
|
}
|
||||||
if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
|
if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
|
||||||
(p->flag & ISSET)) {
|
(p->flag & ISSET)) {
|
||||||
|
if (last_terminal_was_bracket)
|
||||||
|
/* prefer functions over aliases */
|
||||||
|
ktdelete(p);
|
||||||
|
else {
|
||||||
Source *s;
|
Source *s;
|
||||||
|
|
||||||
for (s = source; s->type == SALIAS; s = s->next)
|
for (s = source; s->type == SALIAS; s = s->next)
|
||||||
|
@ -830,6 +837,7 @@ yylex(int cf)
|
||||||
goto Again;
|
goto Again;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return LWORD;
|
return LWORD;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue