about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-06-01 10:45:32 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-06-01 10:45:32 +0000
commit772007e76c430588b0b0a234e4db90e5ad50293d (patch)
tree2cab428a1c72d496435e885a9b6a889e4516c529
parent9f63db611a8ee2becff902949398447fd55dfccc (diff)
downloadzsh-772007e76c430588b0b0a234e4db90e5ad50293d.tar.gz
zsh-772007e76c430588b0b0a234e4db90e5ad50293d.tar.xz
zsh-772007e76c430588b0b0a234e4db90e5ad50293d.zip
21296: Add ERR alias for ZERR where possible.
"trap" reports alias names.
-rw-r--r--ChangeLog8
-rw-r--r--Doc/Zsh/builtins.yo4
-rw-r--r--Doc/Zsh/func.yo5
-rw-r--r--Src/builtin.c18
-rw-r--r--Src/jobs.c54
-rw-r--r--Src/zsh.h3
6 files changed, 63 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index b2ba49d7b..3d03b8cb6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-06-01  Peter Stephenson  <pws@csr.com>
+
+	* 21296: Doc/Zsh/builtins.yo [this hunk missing from post],
+	Doc/Zsh/func.yo, Src/builtin.c, Src/jobs.c, Src/zsh.h:
+	Allow ERR signal as alias for ZERR on systems that don't
+	have SIGERR.  Make "trap" report the name used when the trap
+	was set rather than the canonical name.
+
 2005-06-01  Doug Kearns  <djkea2@gus.gscit.monash.edu.au>
 
 	* 21294: Completion/Cygwin/Command/_cygstart,
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index a5b6ea620..6eb94cbfb 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -1165,7 +1165,9 @@ default values.  If var(arg) is the empty string, then this signal
 is ignored by the shell and by the commands it invokes.
 
 If var(sig) is tt(ZERR) then var(arg) will be executed
-after each command with a nonzero exit status.
+after each command with a nonzero exit status.  tt(ERR) is an alias
+for tt(ZERR) on systems that have no tt(SIGERR) signal (this is the
+usual case).
 If var(sig) is tt(DEBUG) then var(arg) will be executed
 after each command.
 If var(sig) is tt(0) or tt(EXIT)
diff --git a/Doc/Zsh/func.yo b/Doc/Zsh/func.yo
index bf5a9b2ae..2f6445873 100644
--- a/Doc/Zsh/func.yo
+++ b/Doc/Zsh/func.yo
@@ -222,11 +222,14 @@ Executed when the shell exits,
 or when the current function exits if defined inside a function.
 )
 findex(TRAPZERR)
+findex(TRAPERR)
 item(tt(TRAPZERR))(
 Executed whenever a command has a non-zero exit status.  However, the
 function is not executed if the command occurred in a sublist followed by
 `tt(&&)' or `tt(||)'; only the final command in a sublist of this type
-causes the trap to be executed.
+causes the trap to be executed.  The function tt(TRAPERR) acts the same as
+tt(TRAPZERR) on systems where there is no tt(SIGERR) (this is the usual
+case).
 )
 enditem()
 
diff --git a/Src/builtin.c b/Src/builtin.c
index 09034c514..69d78c926 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4978,13 +4978,14 @@ bin_trap(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
 		    shfunctab->printnode(hn, 0);
 		DPUTS(!hn, "BUG: I did not find any trap functions!");
 	    } else if (sigtrapped[sig]) {
+		char *name = getsigname(sig);
 		if (!siglists[sig])
-		    printf("trap -- '' %s\n", sigs[sig]);
+		    printf("trap -- '' %s\n", name);
 		else {
 		    s = getpermtext(siglists[sig], NULL);
 		    printf("trap -- ");
 		    quotedzputs(s, stdout);
-		    printf(" %s\n", sigs[sig]);
+		    printf(" %s\n", name);
 		    zsfree(s);
 		}
 	    }
@@ -5017,14 +5018,25 @@ bin_trap(char *name, char **argv, UNUSED(Options ops), UNUSED(int func))
     /* set traps */
     for (; *argv; argv++) {
 	Eprog t;
+	int flags;
 
 	sig = getsignum(*argv);
 	if (sig == -1) {
 	    zwarnnam(name, "undefined signal: %s", *argv, 0);
 	    break;
 	}
+	if (!strcmp(sigs[sig], *argv))
+	    flags = 0;
+	else {
+	    /*
+	     * Record that the signal is used under an assumed name.
+	     * If we ever have more than one alias per signal this
+	     * will need improving.
+	     */
+	    flags = ZSIG_ALIAS;
+	}
 	t = dupeprog(prog, 0);
-	if (settrap(sig, t, 0))
+	if (settrap(sig, t, flags))
 	    freeeprog(t);
     }
     return *argv != NULL;
diff --git a/Src/jobs.c b/Src/jobs.c
index 5c1574acf..f5ade7c2b 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1819,18 +1819,6 @@ bin_fg(char *name, char **argv, Options ops, int func)
     return retval;
 }
 
-#if defined(SIGCHLD) && defined(SIGCLD)
-#if SIGCHLD == SIGCLD
-#define ALT_SIGS 1
-#endif
-#endif
-#if defined(SIGPOLL) && defined(SIGIO)
-#if SIGPOLL == SIGIO
-#define ALT_SIGS 1
-#endif
-#endif
-
-#ifdef ALT_SIGS
 const struct {
     const char *name;
     int num;
@@ -1845,9 +1833,15 @@ const struct {
     { "IO", SIGIO },
 #endif
 #endif
+#if !defined(SIGERR)
+    /*
+     * If SIGERR is not defined by the operating system, use it
+     * as an alias for SIGZERR.
+     */
+    { "ERR", SIGZERR },
+#endif
     { NULL, 0 }
 };
-#endif
 
 /* kill: send a signal to a process.  The process(es) may be specified *
  * by job specifier (see above) or pid.  A signal, defaulting to       *
@@ -1879,7 +1873,6 @@ bin_kill(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
 			    for (sig = 1; sig <= SIGCOUNT; sig++)
 				if (!cstrpcmp(sigs + sig, &signame))
 				    break;
-#ifdef ALT_SIGS
 			    if (sig > SIGCOUNT) {
 				int i;
 
@@ -1890,7 +1883,6 @@ bin_kill(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
 					break;
 				    }
 			    }
-#endif
 			    if (sig > SIGCOUNT) {
 				zwarnnam(nam, "unknown signal: SIG%s",
 					 signame, 0);
@@ -1953,7 +1945,6 @@ bin_kill(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
 			break;
 		if (*signame == '0' && !signame[1])
 		    sig = 0;
-#ifdef ALT_SIGS
 		if (sig > SIGCOUNT) {
 		    int i;
 
@@ -1964,7 +1955,6 @@ bin_kill(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
 			    break;
 			}
 		}
-#endif
 		if (sig > SIGCOUNT) {
 		    zwarnnam(nam, "unknown signal: SIG%s", signame, 0);
 		    zwarnnam(nam, "type kill -l for a List of signals", NULL, 0);
@@ -2042,18 +2032,40 @@ getsignum(char *s)
 	if (!strcmp(s, sigs[i]))
 	    return i;
 
-#ifdef ALT_SIGS
     for (i = 0; alt_sigs[i].name; i++)
     {
 	if (!strcmp(s, alt_sigs[i].name))
 	    return alt_sigs[i].num;
     }
-#endif
 
     /* no matching signal */
     return -1;
 }
 
+/* Get the name for a signal. */
+
+/**/
+mod_export const char *
+getsigname(int sig)
+{
+    if (sigtrapped[sig] & ZSIG_ALIAS)
+    {
+	int i;
+	for (i = 0; alt_sigs[i].name; i++)
+	    if (sig == alt_sigs[i].num)
+		return alt_sigs[i].name;
+    }
+    else
+	return sigs[sig];
+
+    /* shouldn't reach here */
+#ifdef DEBUG
+    dputs("Bad alias flag for signal");
+#endif
+    return "";
+}
+
+
 /* Get the function node for a trap, taking care about alternative names */
 /**/
 HashNode
@@ -2062,9 +2074,7 @@ gettrapnode(int sig, int ignoredisable)
     char fname[20];
     HashNode hn;
     HashNode (*getptr)(HashTable ht, char *name);
-#ifdef ALT_SIGS
     int i;
-#endif
     if (ignoredisable)
 	getptr = shfunctab->getnode2;
     else
@@ -2074,7 +2084,6 @@ gettrapnode(int sig, int ignoredisable)
     if ((hn = getptr(shfunctab, fname)))
 	return hn;
 
-#ifdef ALT_SIGS
     for (i = 0; alt_sigs[i].name; i++) {
 	if (alt_sigs[i].num == sig) {
 	    sprintf(fname, "TRAP%s", alt_sigs[i].name);
@@ -2082,7 +2091,6 @@ gettrapnode(int sig, int ignoredisable)
 		return hn;
 	}
     }
-#endif
 
     return NULL;
 }
diff --git a/Src/zsh.h b/Src/zsh.h
index 6e1916690..3dacf637f 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1852,7 +1852,8 @@ struct heap {
 /* Mask to get the above flags */
 #define ZSIG_MASK	(ZSIG_TRAPPED|ZSIG_IGNORED|ZSIG_FUNC)
 /* No. of bits to shift local level when storing in sigtrapped */
-#define ZSIG_SHIFT	3
+#define ZSIG_ALIAS	(1<<3)  /* Trap is stored under an alias */
+#define ZSIG_SHIFT	4
 
 /**********************************/
 /* Flags to third argument of zle */