From cac5a679fe00aa6e57480ed6f52d120e9a0ef4a7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 25 Sep 2015 07:20:56 +0200 Subject: Quote arguments with spaces in print_process() --- build/diagnostics.cxx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'build') diff --git a/build/diagnostics.cxx b/build/diagnostics.cxx index 70dfe07..a450301 100644 --- a/build/diagnostics.cxx +++ b/build/diagnostics.cxx @@ -4,6 +4,7 @@ #include +#include // strchr() #include #include @@ -34,10 +35,22 @@ namespace build r << " |"; // Trailing space will be added inside the loop. for (m++; *p != nullptr; p++, m++) - r << (p != args ? " " : "") - << (**p == '\0' ? "\"" : "") // Quote empty arguments. - << *p - << (**p == '\0' ? "\"" : ""); + { + if (p != args) + r << ' '; + + // Quote if empty or contains spaces. + // + bool q (**p == '\0' || strchr (*p, ' ') != nullptr); + + if (q) + r << '"'; + + r << *p; + + if (q) + r << '"'; + } if (m < n) // Can we examine the next element? { -- cgit v1.1