From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: Builtin test and parsing of conditionals
Date: Fri, 6 Sep 2013 20:20:05 +0100 [thread overview]
Message-ID: <20130906202005.65b4fa84@pws-pc.ntlworld.com> (raw)
In-Reply-To: <130905072545.ZM29595@torch.brasslantern.com>
On Thu, 05 Sep 2013 07:25:45 -0700
Bart Schaefer <schaefer@brasslantern.com> 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
next prev parent reply other threads:[~2013-09-06 19:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-04 16:15 Bart Schaefer
2013-09-04 16:31 ` Peter Stephenson
2013-09-04 17:39 ` Bart Schaefer
2013-09-04 19:09 ` Peter Stephenson
2013-09-05 14:25 ` Bart Schaefer
2013-09-06 19:20 ` Peter Stephenson [this message]
2013-09-04 20:15 ` Chet Ramey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130906202005.65b4fa84@pws-pc.ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).