1 // Copyright (c) 2016 Klemens D. Morgenstern
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_PROCESS_DETAIL_POSIX_CMD_HPP_
8 #define BOOST_PROCESS_DETAIL_POSIX_CMD_HPP_
10 #include <boost/process/detail/config.hpp>
11 #include <boost/process/detail/posix/handler.hpp>
25 template<typename Char>
26 inline std::vector<std::basic_string<Char>> build_cmd(const std::basic_string<Char> & value)
28 std::vector<std::basic_string<Char>> ret;
30 bool in_quotes = false;
31 auto beg = value.begin();
32 for (auto itr = value.begin(); itr != value.end(); itr++)
34 if (*itr == quote_sign<Char>())
35 in_quotes = !in_quotes;
37 if (!in_quotes && (*itr == space_sign<Char>()))
41 ret.emplace_back(beg, itr);
46 if (beg != value.end())
47 ret.emplace_back(beg, value.end());
52 template<typename Char>
53 struct cmd_setter_ : handler_base_ext
55 typedef Char value_type;
56 typedef std::basic_string<value_type> string_type;
58 cmd_setter_(string_type && cmd_line) : _cmd_line(api::build_cmd(std::move(cmd_line))) {}
59 cmd_setter_(const string_type & cmd_line) : _cmd_line(api::build_cmd(cmd_line)) {}
60 template <class Executor>
61 void on_setup(Executor& exec)
63 exec.exe = _cmd_impl.front();
64 exec.cmd_line = &_cmd_impl.front();
65 exec.cmd_style = true;
67 string_type str() const
71 for (auto & cmd : _cmd_line)
72 size += cmd.size() + 1;
75 for (auto & cmd : _cmd_line)
78 ret += equal_sign<Char>();
84 static inline std::vector<Char*> make_cmd(std::vector<string_type> & args);
85 std::vector<string_type> _cmd_line;
86 std::vector<Char*> _cmd_impl = make_cmd(_cmd_line);
89 template<typename Char>
90 std::vector<Char*> cmd_setter_<Char>::make_cmd(std::vector<std::basic_string<Char>> & args)
92 std::vector<Char*> vec;
95 vec.push_back(&v.front());
97 vec.push_back(nullptr);