aboutsummaryrefslogtreecommitdiff
path: root/libbutl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-04-13 14:42:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-04-13 14:42:36 +0200
commitb0bf46a7942611729dd8d9d8b8d78cedf26c4685 (patch)
treee652b1614c892216a328108767e35c129adf7d5f /libbutl
parent6a899e04950c3ba62a238cf7a672a94df6cea527 (diff)
Add process_print_callback() function in addition to *_{start,run}_*()
Diffstat (limited to 'libbutl')
-rw-r--r--libbutl/process-run.txx69
-rw-r--r--libbutl/process.hxx9
2 files changed, 64 insertions, 14 deletions
diff --git a/libbutl/process-run.txx b/libbutl/process-run.txx
index 67426f0..6c903a8 100644
--- a/libbutl/process-run.txx
+++ b/libbutl/process-run.txx
@@ -131,13 +131,13 @@ namespace butl
typename... A,
typename std::size_t... index>
process
- process_start (std::index_sequence<index...>,
- const C& cmdc,
- I&& in,
- O&& out,
- E&& err,
- const process_env& env,
- A&&... args)
+ process_start_impl (std::index_sequence<index...>,
+ const C& cmdc,
+ I&& in,
+ O&& out,
+ E&& err,
+ const process_env& env,
+ A&&... args)
{
// Map stdin/stdout/stderr arguments to their integer values, as expected
// by the process constructor.
@@ -188,13 +188,13 @@ namespace butl
const process_env& env,
A&&... args)
{
- return process_start (std::index_sequence_for<A...> (),
- cmdc,
- std::forward<I> (in),
- std::forward<O> (out),
- std::forward<E> (err),
- env,
- std::forward<A> (args)...);
+ return process_start_impl (std::index_sequence_for<A...> (),
+ cmdc,
+ std::forward<I> (in),
+ std::forward<O> (out),
+ std::forward<E> (err),
+ env,
+ std::forward<A> (args)...);
}
template <typename I,
@@ -259,4 +259,45 @@ namespace butl
env,
std::forward<A> (args)...);
}
+
+ template <typename C,
+ typename... A,
+ typename std::size_t... index>
+ void
+ process_print_impl (std::index_sequence<index...>,
+ const C& cmdc,
+ const process_env& env,
+ A&&... args)
+ {
+ // Construct the command line array.
+ //
+ const std::size_t args_size (sizeof... (args));
+
+ small_vector<const char*, args_size + 2> cmd;
+
+ assert (env.path != nullptr);
+ cmd.push_back (env.path->recall_string ());
+
+ std::string storage[args_size != 0 ? args_size : 1];
+
+ const char* dummy[] = {
+ nullptr, process_args_as_wrapper (cmd, args, storage[index])... };
+
+ cmd.push_back (dummy[0]); // NULL (and get rid of unused warning).
+
+ cmdc (cmd.data (), cmd.size ());
+ }
+
+ template <typename C,
+ typename... A>
+ inline void
+ process_print_callback (const C& cmdc,
+ const process_env& env,
+ A&&... args)
+ {
+ process_print_impl (std::index_sequence_for<A...> (),
+ cmdc,
+ env,
+ std::forward<A> (args)...);
+ }
}
diff --git a/libbutl/process.hxx b/libbutl/process.hxx
index 8648690..5a6837f 100644
--- a/libbutl/process.hxx
+++ b/libbutl/process.hxx
@@ -827,6 +827,15 @@ namespace butl
const process_env&,
A&&... args);
+ // Call the callback without actually running/starting anything.
+ //
+ template <typename C,
+ typename... A>
+ void
+ process_print_callback (const C&,
+ const process_env&,
+ A&&... args);
+
// Conversion of types to their C string representations. Can be overloaded
// (including via ADL) for custom types. The default implementation calls
// to_string() which covers all the numeric values via std::to_string () and