From 95ee62c4079e68d9b2444b490cfb68c703023ab8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 27 Oct 2022 10:12:22 +0200 Subject: Add few more process constructor overloads for convenience --- libbutl/process.cxx | 6 ++-- libbutl/process.hxx | 39 +++++++++++++++++++++----- libbutl/process.ixx | 79 +++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 106 insertions(+), 18 deletions(-) diff --git a/libbutl/process.cxx b/libbutl/process.cxx index aee4508..5b7682e 100644 --- a/libbutl/process.cxx +++ b/libbutl/process.cxx @@ -190,7 +190,7 @@ namespace butl } void process:: - print (ostream& o, const char* const args[], size_t n) + print (ostream& o, const char* const* args, size_t n) { size_t m (0); const char* const* p (args); @@ -383,7 +383,7 @@ namespace butl } process:: - process (const process_path& pp, const char* args[], + process (const process_path& pp, const char* const* args, pipe pin, pipe pout, pipe perr, const char* cwd, const char* const* evars) @@ -1365,7 +1365,7 @@ namespace butl static map detect_msys_cache_; process:: - process (const process_path& pp, const char* args[], + process (const process_path& pp, const char* const* args, pipe pin, pipe pout, pipe perr, const char* cwd, const char* const* evars) diff --git a/libbutl/process.hxx b/libbutl/process.hxx index cf5bcd8..10e1587 100644 --- a/libbutl/process.hxx +++ b/libbutl/process.hxx @@ -287,12 +287,22 @@ namespace butl // Note that the versions without the the process_path argument may // temporarily change args[0] (see path_search() for details). // - process (const char* [], + process (const char**, int in = 0, int out = 1, int err = 2, const char* cwd = nullptr, const char* const* envvars = nullptr); - process (const process_path&, const char* [], + process (const process_path&, const char* const*, + int in = 0, int out = 1, int err = 2, + const char* cwd = nullptr, + const char* const* envvars = nullptr); + + process (std::vector&, + int in = 0, int out = 1, int err = 2, + const char* cwd = nullptr, + const char* const* envvars = nullptr); + + process (const process_path&, const std::vector&, int in = 0, int out = 1, int err = 2, const char* cwd = nullptr, const char* const* envvars = nullptr); @@ -335,11 +345,26 @@ namespace butl bool own_out = false; }; - process (const process_path&, const char* [], + process (const process_path&, const char* const*, + pipe in, pipe out, pipe err, + const char* cwd = nullptr, + const char* const* envvars = nullptr); + + process (const process_path&, const char* const*, + int in, int out, pipe err, + const char* cwd = nullptr, + const char* const* envvars = nullptr); + + process (const process_path&, const std::vector&, pipe in, pipe out, pipe err, const char* cwd = nullptr, const char* const* envvars = nullptr); + process (const process_path&, const std::vector&, + int in, int out, pipe err, + const char* cwd = nullptr, + const char* const* envvars = nullptr); + // The "piping" constructor, for example: // // process lhs (..., 0, -1); // Redirect stdout to a pipe. @@ -348,12 +373,12 @@ namespace butl // rhs.wait (); // Wait for last first. // lhs.wait (); // - process (const char* [], + process (const char**, process&, int out = 1, int err = 2, const char* cwd = nullptr, const char* const* envvars = nullptr); - process (const process_path&, const char* [], + process (const process_path&, const char* const*, process&, int out = 1, int err = 2, const char* cwd = nullptr, const char* const* envvars = nullptr); @@ -518,7 +543,7 @@ namespace butl // nameN arg arg ... nullptr nullptr // static void - print (std::ostream&, const char* const args[], size_t n = 0); + print (std::ostream&, const char* const* args, size_t n = 0); // Quote and escape the specified command line argument. If batch is true // then also quote the equal (`=`), comma (`,`) and semicolon (`;`) @@ -698,7 +723,7 @@ namespace butl // command line or similar. It should be callable with the following // signature: // - // void (const char*[], std::size_t) + // void (const char* const*, std::size_t) // template & args, + int in, int out, int err, + const char* cwd, + const char* const* envvars) + : process (pp, args.data (), + pipe (in, -1), pipe (-1, out), pipe (-1, err), + cwd, + envvars) + { + } inline process:: - process (const process_path& pp, const char* args[], + process (std::vector& args, + int in, int out, int err, + const char* cwd, + const char* const* envvars) + : process (path_search (args[0]), args.data (), + in, out, err, + cwd, + envvars) + { + } + + inline process:: + process (const process_path& pp, const char* const* args, + int in, int out, pipe err, + const char* cwd, + const char* const* envvars) + : process (pp, args, + pipe (in, -1), pipe (-1, out), std::move (err), + cwd, + envvars) + { + } + + inline process:: + process (const process_path& pp, const std::vector& args, + pipe in, pipe out, pipe err, + const char* cwd, + const char* const* envvars) + : process (pp, args.data (), + std::move (in), std::move (out), std::move (err), + cwd, + envvars) + { + } + + inline process:: + process (const process_path& pp, const std::vector& args, + int in, int out, pipe err, + const char* cwd, + const char* const* envvars) + : process (pp, args.data (), + pipe (in, -1), pipe (-1, out), std::move (err), + cwd, + envvars) + { + } + + inline process:: + process (const process_path& pp, const char* const* args, process& in, int out, int err, const char* cwd, const char* const* envvars) @@ -254,11 +315,13 @@ namespace butl } inline process:: - process (const char* args[], + process (const char** args, process& in, int out, int err, const char* cwd, const char* const* envvars) - : process (path_search (args[0]), args, in, out, err, cwd, envvars) {} + : process (path_search (args[0]), args, in, out, err, cwd, envvars) + { + } inline process:: process (process&& p) -- cgit v1.1