From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: autoload +X[zk]
Date: Mon, 27 Mar 2000 12:49:28 +0200 (MET DST) [thread overview]
Message-ID: <200003271049.MAA04375@beta.informatik.hu-berlin.de> (raw)
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@informatik.hu-berlin.de
next reply other threads:[~2000-03-27 10:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-27 10:49 Sven Wischnowsky [this message]
2000-03-27 16:48 ` Bart Schaefer
2000-03-27 11:27 Sven Wischnowsky
2000-03-28 11:40 Sven Wischnowsky
2000-03-28 11:52 Sven Wischnowsky
2000-03-28 14:10 ` Sven Wischnowsky
2000-03-28 18:27 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200003271049.MAA04375@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).