zsh-workers
 help / color / mirror / code / Atom feed
From: Dan Nelson <dnelson@allantgroup.com>
To: Peter Stephenson <pws@csr.com>
Cc: zsh-workers@sunsite.dk
Subject: Re: Quoting in zsh -x output
Date: Tue, 30 Jul 2002 15:50:31 -0500	[thread overview]
Message-ID: <20020730205031.GD95493@dan.emsphone.com> (raw)
In-Reply-To: <21447.1028048600@csr.com>

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

In the last episode (Jul 30), Peter Stephenson said:
> Hrvoje Niksic wrote:
> > I suggest modifying the zsh `-x' output to quote its arguments the
> > way Bash does.  What do the others think?
> 
> This would be nice, but it's not a trivial change.  The xtrace output
> is done at the last minute after quoting information has been
> stripped.  This is deliberate, in order to output exactly what is
> being evaluated after all substitutions, which is the information you
> can't get any other way.  This is at odds with showing all the
> quotes.  It's possible there's some compromise position which would
> show a lot of everything --- the quotes get stripped at quite a late
> stage.  However, there's no way of doing it perfectly without a great
> deal of work --- consider expansions like "$@".

I think all bash does is check each argument for spaces, single-quotes,
or backslashes, and then quotes and escapes that argument.  It doesn't
care what quoting the user had on the commandline:

$ echo one\ two 'one two' "one two"
+ echo 'one two' 'one two' 'one two'

I did a quick hack that replaced a bunch of fprintf/zputs with
quotedzputs, and it seems to work fine.  It ends up quoting "one'two"
as 'one'\''two' for some reason, single-quoting "one",
backslash-escaping "'", and single-quoting "two".  Weird, but valid.
This is my first zsh hack, and I'm probably doing everything wrong, but
it shows that it's really not difficult.  Even "$@" works.

-- 
	Dan Nelson
	dnelson@allantgroup.com

[-- Attachment #2: patch-dn-xtrace --]
[-- Type: text/plain, Size: 2567 bytes --]

--- Src/builtin.c~	Tue Oct 16 04:49:17 2001
+++ Src/builtin.c	Tue Jul 30 15:01:53 2002
@@ -356,10 +356,14 @@ execbuiltin(LinkList args, Builtin bn)
 	if (xtr) {
 	    printprompt4();
 	    fprintf(xtrerr, "%s", name);
-	    if (xarg)
-		fprintf(xtrerr, " %s", xarg);
-	    while (*oargv)
-		fprintf(xtrerr, " %s", *oargv++);
+	    if (xarg) {
+	        fputc(' ', xtrerr);
+	        quotedzputs(xarg, xtrerr);
+	    }
+	    while (*oargv) {
+	        fputc(' ', xtrerr);
+	        quotedzputs(*oargv++, xtrerr);
+	    }
 	    fputc('\n', xtrerr);
 	    fflush(xtrerr);
 	}
--- Src/cond.c~	Wed Oct 24 11:03:02 2001
+++ Src/cond.c	Tue Jul 30 15:29:48 2002
@@ -147,9 +147,14 @@ evalcond(Estate state)
 		singsub(&rt);
 		untokenize(rt);
 	    }
-	    fprintf(xtrerr, " %s %s %s", left, condstr[ctype], rt);
-	} else
-	    fprintf(xtrerr, " -%c %s", ctype, left);
+	    fputc(' ',xtrerr);
+	    quotedzputs(left, xtrerr);
+	    fprintf(xtrerr, " %s ", condstr[ctype]);
+	    quotedzputs(rt, xtrerr);
+	} else {
+	    fprintf(xtrerr, " -%c ", ctype);
+	    quotedzputs(left, xtrerr);
+	}
     }
 
     if (ctype >= COND_EQ && ctype <= COND_GE) {
--- Src/exec.c.orig	Wed Oct 24 06:16:32 2001
+++ Src/exec.c	Tue Jul 30 14:56:50 2002
@@ -1275,7 +1275,7 @@ makecline(LinkList list)
 
 	for (node = firstnode(list); node; incnode(node)) {
 	    *ptr++ = (char *)getdata(node);
-	    zputs(getdata(node), xtrerr);
+	    quotedzputs(getdata(node), xtrerr);
 	    if (nextnode(node))
 		fputc(' ', xtrerr);
 	}
@@ -1544,8 +1544,10 @@ addvars(Estate state, Wordcode pc, int e
 		untokenize(peekfirst(vl));
 		val = ztrdup(ugetnode(vl));
 	    }
-	    if (xtr)
-		fprintf(xtrerr, "%s ", val);
+	    if (xtr) {
+		quotedzputs(val, xtrerr);
+		fputc(' ', xtrerr);
+	    }
 	    if (export && !strchr(name, '[')) {
 		if (export < 0 && isset(RESTRICTED) &&
 		    (pm = (Param) paramtab->removenode(paramtab, name)) &&
@@ -1583,8 +1585,10 @@ addvars(Estate state, Wordcode pc, int e
 	*ptr = NULL;
 	if (xtr) {
 	    fprintf(xtrerr, "( ");
-	    for (ptr = arr; *ptr; ptr++)
-		fprintf(xtrerr, "%s ", *ptr);
+	    for (ptr = arr; *ptr; ptr++) {
+		quotedzputs(*ptr, xtrerr);
+		fputc(' ', xtrerr);
+	    }
 	    fprintf(xtrerr, ") ");
 	}
 	setaparam(name, arr);
@@ -3187,7 +3191,7 @@ execshfunc(Shfunc shf, LinkList args)
 	    for (lptr = firstnode(args); lptr; incnode(lptr)) {
 		if (lptr != firstnode(args))
 		    fputc(' ', xtrerr);
-		fprintf(xtrerr, "%s", (char *)getdata(lptr));
+		quotedzputs((char *)getdata(lptr), xtrerr);
 	    }
 	fputc('\n', xtrerr);
 	fflush(xtrerr);

  reply	other threads:[~2002-07-30 20:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-30 16:26 Hrvoje Niksic
2002-07-30 17:03 ` Peter Stephenson
2002-07-30 20:50   ` Dan Nelson [this message]
2002-07-31  9:42     ` Peter Stephenson
2002-07-31 14:55       ` Bart Schaefer
2002-08-03 17:05 Hrvoje Niksic

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=20020730205031.GD95493@dan.emsphone.com \
    --to=dnelson@allantgroup.com \
    --cc=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).