about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-04-20 12:57:27 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-04-20 12:57:27 +0000
commitc1e47cb71f9f974eba00e780746e092296ceb958 (patch)
treedc5df257605614e56d6d5e4d0b80dea7ffc1796a /Src
parent2c1f42366d43b7eb2395ae2979c26828409c7693 (diff)
downloadzsh-c1e47cb71f9f974eba00e780746e092296ceb958.tar.gz
zsh-c1e47cb71f9f974eba00e780746e092296ceb958.tar.xz
zsh-c1e47cb71f9f974eba00e780746e092296ceb958.zip
19801: implement autoloading of trap functions
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 6f443851a..010c8c1f3 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2508,14 +2508,32 @@ bin_functions(char *name, char **argv, Options ops, int func)
 		/* no flags, so just print */
 		shfunctab->printnode((HashNode) shf, pflags);
 	} else if (on & PM_UNDEFINED) {
+	    int signum, ok = 1;
+
 	    /* Add a new undefined (autoloaded) function to the *
 	     * hash table with the corresponding flags set.     */
 	    shf = (Shfunc) zshcalloc(sizeof *shf);
 	    shf->flags = on;
 	    shf->funcdef = mkautofn(shf);
-	    shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
-	    if (OPT_ISSET(ops,'X') && eval_autoload(shf, shf->nam, ops, func))
-		returnval = 1;
+
+	    if (!strncmp(*argv, "TRAP", 4) &&
+		(signum = getsignum(*argv + 4)) != -1) {
+		if (settrap(signum, shf->funcdef)) {
+		    freeeprog(shf->funcdef);
+		    zfree(shf, sizeof(*shf));
+		    returnval = 1;
+		    ok = 0;
+		}
+		else
+		    sigtrapped[signum] |= ZSIG_FUNC;
+	    }
+
+	    if (ok) {
+		shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
+		if (OPT_ISSET(ops,'X') &&
+		    eval_autoload(shf, shf->nam, ops, func))
+		    returnval = 1;
+	    }
 	} else
 	    returnval = 1;
     }