zsh-workers
 help / color / mirror / code / Atom feed
* 'command -pv zsh' => 'zsh: command not found: -pv'
@ 2011-07-20 15:23 Daniel Shahaf
  2011-07-21  2:59 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2011-07-20 15:23 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 963 bytes --]

Actual behaviour:
t1% command -pv zsh
zsh: command not found: -pv

Expected behaviour:
Look for a 'zsh' executable in the default $PATH and print its path.
(i.e., print '/usr/local/bin/zsh'.)

Environment:
t1% zsh -f
t1% echo $ZSH_VERSION
4.3.10

Mikael Magnusson reported on IRC that he can reproduce that locally,
using a more recent zsh.

---

Looking into the cause, I guess that it's due to this bit of argument
parsing in ./Src/exec.c:2433:

[[[
	    if ((cflags & BINF_COMMAND) && nextnode(firstnode(args))) {
		/* check for options to command builtin */
		char *next = (char *) getdata(nextnode(firstnode(args)));
		char *cmdopt;
		if (next && *next == '-' && strlen(next) == 2 &&
		        (cmdopt = strchr("pvV", next[1])))
		{
		    if (*cmdopt == 'p') {
]]]

I've looked into converting that parsing to a while() loop (as used by
other if() blocks in the vicinity), but haven't got a working patch yet
and didn't want to delay this email until I did.

[-- Attachment #2: command-argparse-testsarefailing.diff --]
[-- Type: text/x-diff, Size: 1392 bytes --]

diff --git Src/exec.c Src/exec.c
index f5b59a3..cc1682d 100644
--- Src/exec.c
+++ Src/exec.c
@@ -2433,22 +2433,31 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		/* check for options to command builtin */
 		char *next = (char *) getdata(nextnode(firstnode(args)));
 		char *cmdopt;
-		if (next && *next == '-' && strlen(next) == 2 &&
-		        (cmdopt = strchr("pvV", next[1])))
-		{
-		    if (*cmdopt == 'p') {
-			uremnode(args, firstnode(args));
-			use_defpath = 1;
-			if (nextnode(firstnode(args)))
-			    next = (char *) getdata(nextnode(firstnode(args)));
-		    } else {
-			hn = &commandbn.node;
-			is_builtin = 1;
+		while (next && *next == '-' && strlen(next) >= 2) {
+		    uremnode(args, firstnode(args));
+		    if (!strcmp(next, "--"))
 			break;
+		    for (cmdopt = &next[1]; *cmdopt; ++cmdopt) {
+			switch (*cmdopt) {
+			case 'p':
+			    use_defpath = 1;
+			    break;
+			case 'v':
+			case 'V':
+			    is_builtin = 1;
+			    break;
+			default:
+			    zerr("unknown command flag -%c", *cmdopt);
+			    errflag = lastval = 1;
+			    return;
+			}
 		    }
+		    next = (char *) getdata(nextnode(firstnode(args)));
+		}
+		if (is_builtin) {
+		    hn = &commandbn.node;
+		    break;
 		}
-		if (!strcmp(next, "--"))
-		     uremnode(args, firstnode(args));
 	    }
 	    if ((cflags & BINF_EXEC) && nextnode(firstnode(args))) {
 		/*

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: 'command -pv zsh' => 'zsh: command not found: -pv'
  2011-07-20 15:23 'command -pv zsh' => 'zsh: command not found: -pv' Daniel Shahaf
@ 2011-07-21  2:59 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2011-07-21  2:59 UTC (permalink / raw)
  To: Daniel Shahaf, zsh-workers

On Jul 20,  6:23pm, Daniel Shahaf wrote:
}
} Looking into the cause, I guess that it's due to this bit of argument
} parsing in ./Src/exec.c:2433:

[...]

} I've looked into converting that parsing to a while() loop (as used by
} other if() blocks in the vicinity), but haven't got a working patch yet
} and didn't want to delay this email until I did.

All of the code around there is a bit tangled.  Consider this thread

http://www.zsh.org/mla/workers/2011/msg00034.html (workers/28595)

in particular

http://www.zsh.org/mla/workers/2011/msg00035.html (28596)
http://www.zsh.org/mla/workers/2011/msg00043.html (28604)

before you dive too far into anything.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-21  2:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-20 15:23 'command -pv zsh' => 'zsh: command not found: -pv' Daniel Shahaf
2011-07-21  2:59 ` Bart Schaefer

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).