From 58580d31f593021e2ed4bfad8362e3b01bf396f3 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 11 May 2008 19:55:21 +0000 Subject: 24996: improve xtrace output for patterns --- Src/exec.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'Src/exec.c') 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 -- cgit v1.2.3