PATCH: show ARGV0 and - precommand more clearly in xtrace output

Mikael Magnusson <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
Reported in 48901.

Also has a secondary effect of correcting the string sent to the
command_not_found_handler. If you don't have such a handler, then the
errors are correct before the patch as well.

command_not_found_handler() { echo -E >&2 command not found: $1 }

Before:
% ARGV0=foobar blurg
zsh:1> ARGV0=foobar foobar
command not found: foobar
% - blurg
+zsh:1> -blurg
command not found: -blurg
% ARGV0=foobar - blurg
+zsh:1> ARGV0=foobar foobar
command not found: foobar

After:
% ARGV0=foobar blurg
+zsh:1> ARGV0=foobar blurg
command not found: blurg
% - blurg
+zsh:1> - blurg
command not found: blurg
% ARGV0=foobar - blurg
+zsh:1> ARGV0=foobar - blurg
command not found: blurg
---
 Src/exec.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Src/exec.c b/Src/exec.c
index c1393a3843..4240c14910 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -753,10 +753,12 @@ execute(LinkList args, int flags, int defpath)
 	zsfree(s);
     }
 
+    argv = makecline(args, flags & BINF_DASH);
+
     /* If ARGV0 is in the commands environment, we use *
      * that as argv[0] for this external command       */
     if ((z = zgetenv("ARGV0"))) {
-	setdata(firstnode(args), (void *) ztrdup(z));
+	argv[0] = ztrdup(z);
 	/*
 	 * Note we don't do anything with the parameter structure
 	 * for ARGV0: that's OK since we're about to exec or exit
@@ -771,10 +773,9 @@ execute(LinkList args, int flags, int defpath)
     /* Else if the pre-command `-' was given, we add `-' *
      * to the front of argv[0] for this command.         */
 	sprintf(buf2, "-%s", arg0);
-	setdata(firstnode(args), (void *) ztrdup(buf2));
+	argv[0] = ztrdup(buf2);
     }
 
-    argv = makecline(args);
     if (flags & BINF_CLEARENV)
 	newenvp = blank_env;
 
@@ -2098,7 +2099,7 @@ execpline2(Estate state, wordcode pcode,
 
 /**/
 static char **
-makecline(LinkList list)
+makecline(LinkList list, int dash)
 {
     LinkNode node;
     char **argv, **ptr;
@@ -2111,6 +2112,7 @@ makecline(LinkList list)
 	if (!doneps4)
 	    printprompt4();
 
+	if (dash) fputs("- ", xtrerr);
 	for (node = firstnode(list); node; incnode(node)) {
 	    *ptr++ = (char *)getdata(node);
 	    quotedzputs(getdata(node), xtrerr);
-- 
2.38.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.