about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-05-11 19:55:21 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-05-11 19:55:21 +0000
commit58580d31f593021e2ed4bfad8362e3b01bf396f3 (patch)
tree580a8b44393b087cba28e4a740641f32d3537fd3 /Src/exec.c
parentbab70abe6bcdd28b829adbe582069dc08d9d1c02 (diff)
downloadzsh-58580d31f593021e2ed4bfad8362e3b01bf396f3.tar.gz
zsh-58580d31f593021e2ed4bfad8362e3b01bf396f3.tar.xz
zsh-58580d31f593021e2ed4bfad8362e3b01bf396f3.zip
24996: improve xtrace output for patterns
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 9ec49e11a..fd6f45f93 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1609,6 +1609,66 @@ untokenize(char *s)
     }
 }
 
+
+/*
+ * Given a tokenized string, output it to standard output in
+ * such a way that it's clear which tokens are active.
+ * Hence Star becomes an unquoted "*", while a "*" becomes "\*".
+ *
+ * The code here is a kind of amalgamation of the tests in
+ * zshtokenize() and untokenize() with some outputting.
+ */
+
+/**/
+void
+quote_tokenized_output(char *str, FILE *file)
+{
+    char *s = str;
+
+    for (; *s; s++) {
+	switch (*s) {
+	case Meta:
+	    putc(*++s ^ 32, file);
+	    continue;
+
+	case Nularg:
+	    /* Do nothing.  I think. */
+	    continue;
+
+	case '\\':
+	case '<':
+	case '>':
+	case '(':
+	case '|':
+	case ')':
+	case '^':
+	case '#':
+	case '~':
+	case '[':
+	case ']':
+	case '*':
+	case '?':
+	case '$':
+	    putc('\\', file);
+	    break;
+
+	case '=':
+	    if (s == str)
+		putc('\\', file);
+	    break;
+
+	default:
+	    if (itok(*s)) {
+		putc(ztokens[*s - Pound], file);
+		continue;
+	    }
+	    break;
+	}
+
+	putc(*s, file);
+    }
+}
+
 /* Check that we can use a parameter for allocating a file descriptor. */
 
 static int