From 8c86fedc2dfcb0583761f33daced785bc9b87b1f Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 24 Feb 2008 22:12:36 +0000 Subject: [PATCH] =?UTF-8?q?=20=20*=20lex.c:=20Don't=20expand=20aliases=20i?= =?UTF-8?q?f=20there's=20an=20opening=20bracket=20just=20after=20=20=20=20?= =?UTF-8?q?=20the=20token.=20Fixes=20unreported=20problem=20with=20pdksh?= =?UTF-8?q?=20reporting=20syntax=20error=20=20=20=20=20on=20the=20init=20s?= =?UTF-8?q?cripts=20that=20define=20function=20named=20=E2=80=98stop?= =?UTF-8?q?=E2=80=99=20(clashing=20=20=20=20=20with=20an=20built-in=20alia?= =?UTF-8?q?s.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- Robert Luberda Sun, 27 Feb 2005 18:36:55 +0100 --- check.t | 25 ++++++++++++++++++++++++- lex.c | 34 +++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/check.t b/check.t index 7d33bb0..ca53648 100644 --- a/check.t +++ b/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: 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 +--- diff --git a/lex.c b/lex.c index f049953..28f9603 100644 --- a/lex.c +++ b/lex.c @@ -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; + } } }