• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3821 (tree)
Time2018-01-13 17:52:45
Authormagicant

Log Message

Quote xtrace

The trace is now printed in a format suitable for re-parsing as a simple
command that would result in the same expansion.

Change Summary

Incremental Difference

--- yash/trunk/exec.c (revision 3820)
+++ yash/trunk/exec.c (revision 3821)
@@ -216,7 +216,11 @@
216216 /* the last assignment. */
217217 static const assign_T *last_assign;
218218
219-/* a buffer for xtrace. */
219+/* a buffer for xtrace.
220+ * When assignments are performed while executing a simple command, the trace
221+ * is appended to this buffer. Each trace of an assignment must be prefixed
222+ * with a space to separate it with the previous one. The first space will be
223+ * trimmed when the buffer is flushed to the standard error. */
220224 static xwcsbuf_T xtrace_buffer = { .contents = NULL };
221225
222226
@@ -1285,8 +1289,11 @@
12851289 for (void *const *a = argv; *a != NULL; a++) {
12861290 if (!first)
12871291 fputc(' ', stderr);
1288- fprintf(stderr, "%ls", (wchar_t *) *a);
12891292 first = false;
1293+
1294+ wchar_t *quoted = quote_as_word(*a);
1295+ fprintf(stderr, "%ls", quoted);
1296+ free(quoted);
12901297 }
12911298 }
12921299 fputc('\n', stderr);
--- yash/trunk/variable.c (revision 3820)
+++ yash/trunk/variable.c (revision 3821)
@@ -768,7 +768,10 @@
768768 void xtrace_variable(const wchar_t *name, const wchar_t *value)
769769 {
770770 xwcsbuf_T *buf = get_xtrace_buffer();
771- wb_wprintf(buf, L" %ls=%ls", name, value);
771+ wb_wccat(buf, L' ');
772+ wb_cat(buf, name);
773+ wb_wccat(buf, L'=');
774+ wb_quote_as_word(buf, value);
772775 }
773776
774777 /* Pushes a trace of the specified array assignment to the xtrace buffer. */
@@ -779,7 +782,7 @@
779782 wb_wprintf(buf, L" %ls=(", name);
780783 if (*values != NULL) {
781784 for (;;) {
782- wb_cat(buf, *values);
785+ wb_quote_as_word(buf, *values);
783786 values++;
784787 if (*values == NULL)
785788 break;
--- yash/trunk/NEWS (revision 3820)
+++ yash/trunk/NEWS (revision 3821)
@@ -10,6 +10,8 @@
1010 ----------------------------------------------------------------------
1111 Yash 2.47
1212
13+ = Expansion results printed by the -x option is now quoted to
14+ disambiguate presence of special characters.
1315 = When the shell prints aliases, variables, key bindings, etc. they
1416 are now printed with less quotes.
1517
Show on old repository browser