From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-request@euclid.skiles.gatech.edu Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.6/8.7.3) with ESMTP id CAA26715 for ; Mon, 25 Nov 1996 02:36:35 +1100 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id KAA29118; Sun, 24 Nov 1996 10:29:06 -0500 (EST) Resent-Date: Sun, 24 Nov 1996 10:29:06 -0500 (EST) From: Zefram Message-Id: <19781.199611241529@stone.dcs.warwick.ac.uk> Subject: autoloading modules To: zsh-workers@math.gatech.edu (Z Shell workers mailing list) Date: Sun, 24 Nov 1996 15:29:38 +0000 (GMT) X-Patch: 132 X-Loop: zefram@dcs.warwick.ac.uk X-Stardate: [-31]8473.22 X-US-Congress: Moronic fuckers Content-Type: text Resent-Message-ID: <"7zJfN.0.u67.1d6co"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2463 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----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-----