From 81abf8eab067eab362f180a418215f9408de41dc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Sep 2015 14:15:37 +0200 Subject: Add support for printing process command line --- bpkg/diagnostics.cxx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'bpkg/diagnostics.cxx') diff --git a/bpkg/diagnostics.cxx b/bpkg/diagnostics.cxx index 2bee18e..4c5e24b 100644 --- a/bpkg/diagnostics.cxx +++ b/bpkg/diagnostics.cxx @@ -10,6 +10,40 @@ using namespace std; namespace bpkg { + // print_process + // + void + print_process (const char* const* args, size_t n) + { + diag_record r (text); + print_process (r, args, n); + } + + void + print_process (diag_record& r, const char* const* args, size_t n) + { + size_t m (0); + const char* const* p (args); + do + { + if (m != 0) + 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 (m < n) // Can we examine the next element? + { + p++; + m++; + } + + } while (*p != nullptr); + } + // Trace verbosity level. // uint16_t verb; -- cgit v1.1