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

Re: 4.3.4-dev-4 and 4.2.6-dev-2 available



On Wed, 12 Dec 2007 15:10:28 +0000
Peter Stephenson <pws@xxxxxxx> wrote:
> Vincent Lefevre wrote:
> > > Furthermore, this change makes
> > >   ( ! -e ) )
> > > an error:
> > 
> > Hmm... I don't think so.
> 
> I'm now inclined to leave this alone and just make the explicit tests
> for numbers of arguments up to and including 4.

I think all we need to change is the following (the other rules are already
handled either by the normal syntax or explicit tests), which is
reassuringly simple and localized and worries me a lot less than the
previous patch.

I have, however, attempted to worry users more.

Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.100
diff -u -r1.100 builtins.yo
--- Doc/Zsh/builtins.yo	12 Dec 2007 13:46:37 -0000	1.100
+++ Doc/Zsh/builtins.yo	12 Dec 2007 16:53:25 -0000
@@ -1235,7 +1235,15 @@
 syntactically, so for example an empty variable expansion may cause an
 argument to be omitted; syntax errors cause status 2 to be returned instead
 of a shell error; and arithmetic operators expect integer arguments rather
-than arithemetic expressions.
+than arithmetic expressions.
+
+The command attempts to implement POSIX and its extensions where these
+are specified.  Unfortunately there are intrinisic ambiguities in
+the syntax; in particular there is no distinction between test operators
+and strings that resemble them.  The standard attempts to resolve these
+for small numbers of arguments (up to four); for five or more arguments
+compatibility cannot be relied on.  Users are urged wherever possible to
+use the `tt([[)' test syntax which does not have these ambiguities.
 )
 findex(times)
 cindex(shell, timing)
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.182
diff -u -r1.182 builtin.c
--- Src/builtin.c	11 Dec 2007 14:05:53 -0000	1.182
+++ Src/builtin.c	12 Dec 2007 16:53:26 -0000
@@ -5506,6 +5506,7 @@
     char **s;
     Eprog prog;
     struct estate state;
+    int nargs;
 
     /* if "test" was invoked as "[", it needs a matching "]" *
      * which is subsequently ignored                         */
@@ -5521,6 +5522,20 @@
     if (!*argv)
 	return 1;
 
+    /*
+     * Implement some XSI extensions to POSIX here.
+     * See
+     * http://www.opengroup.org/onlinepubs/009695399/utilities/test.html.
+     */
+    nargs = arrlen(argv);
+    if (nargs == 3 || nargs == 4)
+    {
+	if (*argv[0] == '(' && *argv[nargs-1] == ')') {
+	    argv[nargs-1] = NULL;
+	    argv++;
+	}
+    }
+
     testargs = argv;
     tok = NULLTOK;
     condlex = testlex;

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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