Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: zsh-4.2.1: unset does not follow spec



Recently, I read that FreeBSD's /bin/sh fails:
http://www.freebsd.org/cgi/query-pr.cgi?pr=standards/45738
the IEEE Std 1003.1-2001:
http://www.opengroup.org/onlinepubs/007904975/utilities/unset.html
when it comes to the builtin unset.  tcsh and bash do follow it.

I then checked zsh.  It also fails this specification (if it desired to
follow it for unset?).  I have attached a patch that returns zero for
unset.  It also affects unhash for functions to handle unset -f.

Sean

P.S. I am not on the list; please cc.

P.P.S.  http://www.zsh.org/mla/patches.shtml has not been updated past
March 2004.
---------------
sean@xxxxxxxxxx
--- Src/builtin.c.orig	Fri Aug 13 05:22:42 2004
+++ Src/builtin.c	Wed Sep 22 09:44:04 2004
@@ -2638,9 +2638,9 @@
 		returnval = 1;
 	    }
 	}
-	/* If we didn't match anything, we return 1. */
+	/* If we didn't match anything, we return 0. */
 	if (!match)
-	    returnval = 1;
+	    returnval = 0;
 	return returnval;
     }
 
@@ -2661,7 +2661,7 @@
 		      gethashnode2(paramtab, s) :
 		      paramtab->getnode(paramtab, s));
 	if (!pm)
-	    returnval = 1;
+	    returnval = 0;
 	else if ((pm->flags & PM_RESTRICTED) && isset(RESTRICTED)) {
 	    zerrnam(name, "%s: restricted", pm->nam, 0);
 	    returnval = 1;
@@ -3056,9 +3056,17 @@
 		returnval = 1;
 	    }
 	}
-	/* If we didn't match anything, we return 1. */
-	if (!match)
-	    returnval = 1;
+	/*
+	 * If we didn't match anything, we return 0 for functions and 1 for
+	 * all other hash types.
+	 */
+	if (!match) {
+	    if (OPT_ISSET(ops,'f')) {
+		returnval = 0;
+	    } else {
+		returnval = 1;
+	    }
+	}
 	return returnval;
     }
 
@@ -3069,7 +3077,11 @@
 	    ht->freenode(hn);
 	} else {
 	    zwarnnam(name, "no such hash table element: %s", *argv, 0);
-	    returnval = 1;
+	    if (OPT_ISSET(ops,'f')) {
+		returnval = 0;
+	    } else {
+		returnval = 1;
+	    }
 	}
     }
     unqueue_signals();


Messages sorted by: Reverse Date, Date, Thread, Author