aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-25 07:20:56 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-25 07:20:56 +0200
commitcac5a679fe00aa6e57480ed6f52d120e9a0ef4a7 (patch)
tree9264b9eb6cd767c1249ead0c2a3ecb55072ec83e
parent451f4a48f60965af980913d46a28947a834b3cd8 (diff)
Quote arguments with spaces in print_process()
-rw-r--r--build/diagnostics.cxx21
1 files changed, 17 insertions, 4 deletions
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 <build/diagnostics>
+#include <cstring> // strchr()
#include <iostream>
#include <build/utility>
@@ -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?
{