From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6120 invoked by alias); 6 Sep 2013 19:25:59 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31706 Received: (qmail 11321 invoked from network); 6 Sep 2013 19:25:43 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 209.85.215.178 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=m4U9R8/StP8FW0akcHDLTBPufEhJbnjIdcl3kl2Y4gU=; b=Ferahtq48kdqVoEnoJQxJjKszrnXjWIpE5KMatzLKRBbutYgjzmP4VmdhFGRqPOm/G elz2eEmbjvLC64/VvL9n7mbcRUJMsISAoXYHhaLZEywDiFdbvxfsFMdqP59AXbKwg2BW IhU+JxzOU1Y2iXlZ7ibdoGYB9cDLrcy9cFUbGjTzfRkYOqv0bGbMLm4LOV6IY/sUm9/p SpWRuFmwLYiKl+Pg2UrYsn4zn8Z61OBYKE2gRuNAjowP+gni87p+PvhC9Tx94YXAWt+Q w8Vs3G8sk/TjAEZ2fX9G9KJcJfEqn3L+v258+iylXxPmkzvVinropWzCKvSDB1tZ5YiA 8NgA== X-Gm-Message-State: ALoCoQlLpv35OLE3NK1O01KG4O4OoI2tTYL0c1+PNqtQ74OJ6ZdOBjzDvNgbwUL/KNkdU0XBtuBK X-Received: by 10.14.183.2 with SMTP id p2mr6449216eem.44.1378495208444; Fri, 06 Sep 2013 12:20:08 -0700 (PDT) X-ProxyUser-IP: 86.6.30.159 Date: Fri, 6 Sep 2013 20:20:05 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Builtin test and parsing of conditionals Message-ID: <20130906202005.65b4fa84@pws-pc.ntlworld.com> In-Reply-To: <130905072545.ZM29595@torch.brasslantern.com> References: <130904091503.ZM28369@torch.brasslantern.com> <20130904173159.19c55cd1@pwslap01u.europe.root.pri> <130904103940.ZM28454@torch.brasslantern.com> <20130904200929.5028f433@pws-pc.ntlworld.com> <130905072545.ZM29595@torch.brasslantern.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 05 Sep 2013 07:25:45 -0700 Bart Schaefer wrote: > That's good, but it still doesn't fix the other case mentioned in my > original email: > > torch% /usr/bin/test ! = -a o ; print $? > 1 > torch% test ! = -a o ; print $? > test: too many arguments > 1 > > Do you want to try to handle that in parse.c, or am I correct that peeling > off the "!" in builtin.c:bin_test [the way parens are peeled off] is the > better way to go? That seems sensible. diff --git a/Src/builtin.c b/Src/builtin.c index f8be4ac..c3f0169 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5995,7 +5995,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) char **s; Eprog prog; struct estate state; - int nargs; + int nargs, sense = 0, ret; /* if "test" was invoked as "[", it needs a matching "]" * * which is subsequently ignored */ @@ -6014,7 +6014,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) /* * Implement some XSI extensions to POSIX here. * See - * http://www.opengroup.org/onlinepubs/009695399/utilities/test.html. + * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html */ nargs = arrlen(argv); if (nargs == 3 || nargs == 4) @@ -6023,6 +6023,10 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) argv[nargs-1] = NULL; argv++; } + if (nargs == 4 && !strcmp("!", argv[0])) { + sense = 1; + argv++; + } } lexsave(); @@ -6057,8 +6061,11 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) state.pc = prog->prog; state.strs = prog->strs; + ret = evalcond(&state, name); + if (ret < 2 && sense) + ret = ! ret; - return evalcond(&state, name); + return ret; } /* display a time, provided in units of 1/60s, as minutes and seconds */ diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 8562519..94fca8b 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -331,7 +331,9 @@ F:Failures in these cases do not indicate a problem in the shell. '! -o' '! -a ! -a !' '! = !' - '! !') + '! !' + '= -a o' + '! = -a o') for w in $weirdies; do eval test $w print $? @@ -344,6 +346,8 @@ F:Failures in these cases do not indicate a problem in the shell. >0 >0 >1 +>0 +>1 %clean # This works around a bug in rm -f in some versions of Cygwin