Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
autoload +X[zk]
- X-seq: zsh-workers 10272
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: autoload +X[zk]
- Date: Mon, 27 Mar 2000 12:49:28 +0200 (MET DST)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Note: intentionally no PATCH in the subject, I think I let others
decide if we should use this patch, or change it before using it.
We were discussing this: make autoload accept the -z/-k options to
force zsh-/ksh-style autoloading.
I'm not sure about this because it also changes ksh-style autoloading
with `autoload +X' (independent if it's done because of giving the new
-k flag or because KSH_AUTOLOAD is set) to execute the file loaded to
get at the function definition. And `autoload +X' has been around for
some time...
The good thing is that it integrates execautofn() and loadautofn().
Bye
Sven
diff -ru ../z.old/Doc/Zsh/builtins.yo Doc/Zsh/builtins.yo
--- ../z.old/Doc/Zsh/builtins.yo Mon Mar 27 11:52:37 2000
+++ Doc/Zsh/builtins.yo Mon Mar 27 12:46:18 2000
@@ -74,9 +74,9 @@
findex(autoload)
cindex(functions, autoloading)
cindex(autoloading functions)
-item(tt(autoload) [ {tt(PLUS())|tt(-)}tt(UXmt) ] [ tt(-w) ] [ var(name) ... ])(
-Equivalent to tt(functions -u), with the exception of tt(-X)/tt(+X)
-and tt(-w).
+item(tt(autoload) [ {tt(PLUS())|tt(-)}tt(UXmt) ] [ tt(-wkz) ] [ var(name) ... ])(
+Equivalent to tt(functions -u), with the exception of tt(-X)/tt(+X),
+tt(-w), tt(-k) and tt(-z).
The flag tt(-X) may be used only inside a shell function, and may not be
followed by a var(name). It causes the calling function to be marked for
@@ -92,6 +92,13 @@
exit status is nonzero (failure) if the function was already defined or
when no definition was found. In the latter case the function remains
undefined and marked for autoloading.
+
+The flag tt(+X) may be combined with either tt(-k) or tt(-z) to make
+the function be loaded using ksh-style or zsh-style autoloading,
+respectively. If neither is given, the current setting of the
+tt(KSH_AUTOLOAD) options determines how the function is loaded. Note
+that with ksh-style autoloading the contents of the loaded file is
+executed to make the function be defined.
With the tt(-w) flag, the var(name)s are taken as names of files compiled
with the tt(zcompile) builtin, and all functions defined in them are
diff -ru ../z.old/Src/builtin.c Src/builtin.c
--- ../z.old/Src/builtin.c Mon Mar 27 11:52:26 2000
+++ Src/builtin.c Mon Mar 27 12:46:18 2000
@@ -43,7 +43,7 @@
BUILTIN(".", BINF_PSPECIAL, bin_dot, 1, -1, 0, NULL, NULL),
BUILTIN(":", BINF_PSPECIAL, bin_true, 0, -1, 0, NULL, NULL),
BUILTIN("alias", BINF_MAGICEQUALS | BINF_PLUSOPTS, bin_alias, 0, -1, 0, "Lgmr", NULL),
- BUILTIN("autoload", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "tUXw", "u"),
+ BUILTIN("autoload", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "tUXwkz", "u"),
BUILTIN("bg", 0, bin_fg, 0, -1, BIN_BG, NULL, NULL),
BUILTIN("break", BINF_PSPECIAL, bin_break, 0, 1, BIN_BREAK, NULL, NULL),
BUILTIN("bye", 0, bin_break, 0, 1, BIN_EXIT, NULL, NULL),
@@ -2003,9 +2003,10 @@
if (!(shf->flags & PM_UNDEFINED))
return 1;
- if (shf->funcdef)
+ if (shf->funcdef) {
freeeprog(shf->funcdef);
-
+ shf->funcdef = &dummy_eprog;
+ }
if (ops['X'] == 1) {
char *fargv[3];
fargv[0] = name;
@@ -2015,7 +2016,7 @@
return bin_eval(name, fargv, ops, func);
}
- return loadautofn(shf);
+ return loadautofn(shf, (ops['k'] ? 2 : (ops['z'] ? 0 : 1)));
}
/* Display or change the attributes of shell functions. *
@@ -2045,7 +2046,8 @@
else if (ops['t'] == 2)
off |= PM_TAGGED;
- if ((off & PM_UNDEFINED) ||
+ if ((off & PM_UNDEFINED) || (ops['k'] && ops['z']) ||
+ (ops['X'] != 2 && (ops['k'] || ops['z'])) ||
(ops['X'] == 1 && (ops['m'] || *argv || !scriptname))) {
zwarnnam(name, "invalid option(s)", NULL, 0);
return 1;
diff -ru ../z.old/Src/exec.c Src/exec.c
--- ../z.old/Src/exec.c Mon Mar 27 11:52:27 2000
+++ Src/exec.c Mon Mar 27 12:46:18 2000
@@ -3166,7 +3166,18 @@
static int
execautofn(Estate state, int do_exec)
{
- Shfunc shf = state->prog->shf;
+ if (loadautofn(state->prog->shf, 1))
+ return 1;
+
+
+ execode(state->prog->shf->funcdef, 1, 0);
+ return lastval;
+}
+
+/**/
+int
+loadautofn(Shfunc shf, int fksh)
+{
int noalias = noaliases, ksh = 1;
Eprog prog;
@@ -3176,6 +3187,9 @@
prog = getfpfunc(shf->nam, &ksh);
noaliases = noalias;
+ if (ksh == 1)
+ ksh = fksh;
+
if (prog == &dummy_eprog) {
zerr("%s: function definition file not found", shf->nam, 0);
popheap();
@@ -3201,40 +3215,6 @@
shf->funcdef = dupeprog(stripkshdef(prog, shf->nam), 0);
shf->flags &= ~PM_UNDEFINED;
}
- popheap();
-
- execode(shf->funcdef, 1, 0);
- return lastval;
-}
-
-/**/
-int
-loadautofn(Shfunc shf)
-{
- /* Copied from execautofn() -- should consolidate someday */
-
- int noalias = noaliases;
- Eprog prog;
-
- pushheap();
-
- noaliases = (shf->flags & PM_UNALIASED);
- prog = getfpfunc(shf->nam, NULL);
- noaliases = noalias;
-
- if (prog == &dummy_eprog) {
- zerr("%s: function definition file not found", shf->nam, 0);
- shf->funcdef = prog;
- return 1;
- }
- if (!prog)
- prog = &dummy_eprog;
- if (prog->alloc == EA_MAP)
- shf->funcdef = stripkshdef(prog, shf->nam);
- else
- shf->funcdef = dupeprog(stripkshdef(prog, shf->nam), 0);
- shf->flags &= ~PM_UNDEFINED;
-
popheap();
return 0;
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author