diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-10-27 10:12:22 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-10-27 10:12:22 +0200 |
commit | 95ee62c4079e68d9b2444b490cfb68c703023ab8 (patch) | |
tree | c9a8f8359c38ad88a8256fcef3f4b876990354d3 | |
parent | 7d7f8a4b8966985da25a5ce72fdddb9e394dca5f (diff) |
Add few more process constructor overloads for convenience
-rw-r--r-- | libbutl/process.cxx | 6 | ||||
-rw-r--r-- | libbutl/process.hxx | 39 | ||||
-rw-r--r-- | 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<string, bool> 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<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 std::vector<const char*>&, 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<const char*>&, pipe in, pipe out, pipe err, const char* cwd = nullptr, const char* const* envvars = nullptr); + process (const process_path&, const std::vector<const char*>&, + 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 <typename C, typename I, diff --git a/libbutl/process.ixx b/libbutl/process.ixx index 0f04127..a346a5d 100644 --- a/libbutl/process.ixx +++ b/libbutl/process.ixx @@ -223,12 +223,11 @@ namespace butl } inline process:: - process (const process_path& pp, const char* args[], + process (const process_path& pp, const char* const* args, int in, int out, int err, const char* cwd, const char* const* envvars) - : process (pp, - args, + : process (pp, args, pipe (in, -1), pipe (-1, out), pipe (-1, err), cwd, envvars) @@ -236,14 +235,76 @@ namespace butl } inline process:: - process (const char* args[], + process (const char** args, int 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 (const process_path& pp, const std::vector<const char*>& 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<const char*>& 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<const char*>& 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<const char*>& 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) |