From: Zefram <zefram@dcs.warwick.ac.uk>
To: zsh-workers@math.gatech.edu (Z Shell workers mailing list)
Subject: autoloading modules
Date: Sun, 24 Nov 1996 15:29:38 +0000 (GMT) [thread overview]
Message-ID: <19781.199611241529@stone.dcs.warwick.ac.uk> (raw)
-----BEGIN PGP SIGNED MESSAGE-----
I came up with this cool function yesterday:
function zmodautoload
{
if [[ $# != 2 ]]; then
echo >&2 "zmodautoload: wrong number of arguments"
return 1
fi
eval "function $1 { if zmodload $2; then unfunction $1; $1 \$@; fi; }"
}
In order to support autoloading of modules that provide multiple builtins,
it would be helped by an option to zmodload that says "load this module,
but keep quiet if it's already loaded". The patch below adds such an
option, -i (for idempotent). To make use of it in zmodautoload, change
"zmodload" to "zmodload -i" above.
Zoltan, what is "zmodload -f" for?
-zefram
Index: Doc/zshbuiltins.man
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Doc/zshbuiltins.man,v
retrieving revision 1.13
diff -c -r1.13 zshbuiltins.man
*** zshbuiltins.man 1996/11/23 01:18:50 1.13
--- zshbuiltins.man 1996/11/23 21:57:21
***************
*** 1199,1205 ****
\fBwhich\fP [ \-\fBpam\fP ] \fIname\fP ...
Same as \fBwhence \-c\fP.
%IFDYN%.TP
! %IFDYN%\fBzmodload \fP[\fB-u\fP] \fIname
%IFDYN%Load (or, with
%IFDYN%.BR -u ,
%IFDYN%unload) a binary module.
--- 1199,1205 ----
\fBwhich\fP [ \-\fBpam\fP ] \fIname\fP ...
Same as \fBwhence \-c\fP.
%IFDYN%.TP
! %IFDYN%\fBzmodload \fP[\-\fBfiu\fP] \fIname
%IFDYN%Load (or, with
%IFDYN%.BR -u ,
%IFDYN%unload) a binary module.
***************
*** 1209,1214 ****
--- 1209,1220 ----
%IFDYN%.IR name .
%IFDYN%.RS
%IFDYN%.PP
+ %IFDYN%If the module to be loaded is already loaded, the behaviour
+ %IFDYN%depends on the options. If the \fB\-i\fP option is given,
+ %IFDYN%the duplicate module is ignored. Otherwise, if the \fB\-f\fP
+ %IFDYN%option is given, an attempt is made to load the module again.
+ %IFDYN%Otherwise (if neither option is given), it is an error.
+ %IFDYN%.PP
%IFDYN%The
%IFDYN%.IR name d
%IFDYN%module is searched for in the same way a command is, using
***************
*** 1228,1232 ****
--- 1234,1240 ----
%IFDYN%.I name
%IFDYN%must be given that was given when the module was loaded, but it is not
%IFDYN%necessary for the module to exist in the filesystem.
+ %IFDYN%The \fB\-i\fP option suppresses the error if the module is already
+ %IFDYN%unloaded (or was never loaded).
%IFDYN%.RE
.RE
Index: Src/hashtable.h
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/hashtable.h,v
retrieving revision 1.21
diff -c -r1.21 hashtable.h
*** hashtable.h 1996/11/15 00:30:54 1.21
--- hashtable.h 1996/11/23 21:58:48
***************
*** 304,310 ****
#endif
#ifdef DYNAMIC
! {NULL, "zmodload", 0, bin_zmodload, 0, -1, 0, "uf", NULL},
#endif
{NULL, "popd", 0, bin_cd, 0, 2, BIN_POPD, NULL, NULL},
{NULL, "print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "RDPnrslzNu0123456789pioOcm-", NULL},
--- 304,310 ----
#endif
#ifdef DYNAMIC
! {NULL, "zmodload", 0, bin_zmodload, 0, -1, 0, "ufi", NULL},
#endif
{NULL, "popd", 0, bin_cd, 0, 2, BIN_POPD, NULL, NULL},
{NULL, "print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "RDPnrslzNu0123456789pioOcm-", NULL},
Index: Src/module.c
===================================================================
RCS file: /home/zefram/usr/cvsroot/zsh/Src/module.c,v
retrieving revision 1.12
diff -c -r1.12 module.c
*** module.c 1996/11/23 01:18:00 1.12
--- module.c 1996/11/23 21:59:45
***************
*** 168,179 ****
}
}
if (ops['u']) {
! if (! found) {
zwarnnam(nam, "no such module %s", *args, 0);
ret++;
}
} else if (found) {
! if (! ops['f']) {
zwarnnam(nam, "module %s already loaded.", *args, 0);
ret++;
} else if ((handle = load_module(*args)) != m->handle) {
--- 168,181 ----
}
}
if (ops['u']) {
! if (!found && !ops['i']) {
zwarnnam(nam, "no such module %s", *args, 0);
ret++;
}
} else if (found) {
! if(ops['i'])
! ;
! else if(!ops['f']) {
zwarnnam(nam, "module %s already loaded.", *args, 0);
ret++;
} else if ((handle = load_module(*args)) != m->handle) {
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBMpd2+nD/+HJTpU/hAQFlEAP/TQpSXPbcyTPjibllIlSHmXBmqAkRWvO0
KszHN+5MW5UJQUQqwHIheOxfB8lbAZbcKXCD6jMClf7rzrqCYnwdp4l8VIgp6ra8
Rd/e+4fRgmubXlV6PcYlMLANR4Heyx9BjNVdjINopgd2koKnDHk+/XyjgOt3Jesm
PokPoq24rX4=
=5Sh9
-----END PGP SIGNATURE-----
next reply other threads:[~1996-11-24 15:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-11-24 15:29 Zefram [this message]
1996-11-24 22:40 ` Zoltan Hidvegi
1996-11-25 13:02 ` Zefram
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=19781.199611241529@stone.dcs.warwick.ac.uk \
--to=zefram@dcs.warwick.ac.uk \
--cc=zsh-workers@math.gatech.edu \
/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).