summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/input.c27
-rw-r--r--Src/options.c1
-rw-r--r--Src/parse.c14
-rw-r--r--Src/zsh.h1
4 files changed, 43 insertions, 0 deletions
diff --git a/Src/input.c b/Src/input.c
index eb968ea72..92abaec92 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -670,3 +670,30 @@ ingetptr(void)
{
return inbufptr;
}
+
+/*
+ * Check if the current input line, including continuations, is
+ * expanding an alias. This does not detect alias expansions that
+ * have been fully processed and popped from the input stack.
+ * If there is an alias, the most recently expanded is returned,
+ * else NULL.
+ */
+
+/**/
+char *input_hasalias(void)
+{
+ int flags = inbufflags;
+ struct instacks *instackptr = instacktop;
+
+ for (;;)
+ {
+ if (!(flags & INP_CONT))
+ break;
+ instackptr--;
+ if (instackptr->alias)
+ return instackptr->alias->node.nam;
+ flags = instackptr->flags;
+ }
+
+ return NULL;
+}
diff --git a/Src/options.c b/Src/options.c
index 18619c851..4729ba54a 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -78,6 +78,7 @@ mod_export HashTable optiontab;
*/
static struct optname optns[] = {
{{NULL, "aliases", OPT_EMULATE|OPT_ALL}, ALIASESOPT},
+{{NULL, "aliasfuncdef", OPT_EMULATE|OPT_BOURNE}, ALIASFUNCDEF},
{{NULL, "allexport", OPT_EMULATE}, ALLEXPORT},
{{NULL, "alwayslastprompt", OPT_ALL}, ALWAYSLASTPROMPT},
{{NULL, "alwaystoend", 0}, ALWAYSTOEND},
diff --git a/Src/parse.c b/Src/parse.c
index 50a0d5f9f..ed6c4a8dd 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -1738,6 +1738,7 @@ par_simple(int *cmplx, int nr)
{
int oecused = ecused, isnull = 1, r, argc = 0, p, isfunc = 0, sr = 0;
int c = *cmplx, nrediradd, assignments = 0, ppost = 0, is_typeset = 0;
+ char *hasalias = input_hasalias();
wordcode postassigns = 0;
r = ecused;
@@ -1809,6 +1810,8 @@ par_simple(int *cmplx, int nr)
} else
break;
zshlex();
+ if (!hasalias)
+ hasalias = input_hasalias();
}
if (tok == AMPER || tok == AMPERBANG)
YYERROR(oecused);
@@ -1839,6 +1842,8 @@ par_simple(int *cmplx, int nr)
char *idstring = dupstrpfx(tokstr+1, eptr-tokstr-1);
redir_var = 1;
zshlex();
+ if (!hasalias)
+ hasalias = input_hasalias();
if (IS_REDIROP(tok) && tokfd == -1)
{
@@ -1874,6 +1879,8 @@ par_simple(int *cmplx, int nr)
argc++;
}
zshlex();
+ if (!hasalias)
+ hasalias = input_hasalias();
}
} else if (IS_REDIROP(tok)) {
*cmplx = c = 1;
@@ -1902,6 +1909,8 @@ par_simple(int *cmplx, int nr)
ecstr(name);
ecstr(str);
zshlex();
+ if (!hasalias)
+ hasalias = input_hasalias();
} else if (tok == ENVARRAY) {
int n, parr;
@@ -1936,6 +1945,11 @@ par_simple(int *cmplx, int nr)
/* Error if preceding assignments */
if (assignments || postassigns)
YYERROR(oecused);
+ if (hasalias && !isset(ALIASFUNCDEF) && argc &&
+ hasalias != input_hasalias()) {
+ zwarn("defining function based on alias `%s'", hasalias);
+ YYERROR(oecused);
+ }
*cmplx = c;
lineno = 0;
diff --git a/Src/zsh.h b/Src/zsh.h
index f22d8b135..2a41638db 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2222,6 +2222,7 @@ struct histent {
enum {
OPT_INVALID,
ALIASESOPT,
+ ALIASFUNCDEF,
ALLEXPORT,
ALWAYSLASTPROMPT,
ALWAYSTOEND,