From 21bd787023aa83df2ae92ee21de920d01c5c90ce Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Mon, 26 Sep 2016 00:24:38 +0200 Subject: [PATCH] added cmd-converter && worked on posix stuff --- include/boost/process/cmd.hpp | 21 +++++++++++ include/boost/process/detail/config.hpp | 19 +++++----- .../boost/process/detail/posix/basic_cmd.hpp | 8 ++-- include/boost/process/detail/posix/cmd.hpp | 37 +++++++++++-------- .../boost/process/detail/posix/env_init.hpp | 6 ++- .../process/detail/posix/environment.hpp | 8 ++-- .../boost/process/detail/posix/start_dir.hpp | 11 +++--- include/boost/process/detail/windows/cmd.hpp | 4 +- include/boost/process/environment.hpp | 8 ++-- 9 files changed, 80 insertions(+), 42 deletions(-) diff --git a/include/boost/process/cmd.hpp b/include/boost/process/cmd.hpp index 7739a209..800ce77f 100644 --- a/include/boost/process/cmd.hpp +++ b/include/boost/process/cmd.hpp @@ -62,6 +62,27 @@ struct cmd_ template<> struct is_wchar_t> : std::true_type {}; + +template<> +struct char_converter> +{ + static api::cmd_setter_ conv(const api::cmd_setter_ & in) + { + return { ::boost::process::detail::convert(in.str()) }; + } +}; + +template<> +struct char_converter> +{ + static api::cmd_setter_ conv(const api::cmd_setter_ & in) + { + return { ::boost::process::detail::convert(in.str()) }; + } +}; + + + constexpr static cmd_ cmd; diff --git a/include/boost/process/detail/config.hpp b/include/boost/process/detail/config.hpp index c32f086a..ceb9478e 100644 --- a/include/boost/process/detail/config.hpp +++ b/include/boost/process/detail/config.hpp @@ -72,22 +72,23 @@ inline void throw_last_error() throw std::system_error(get_last_error()); } -} - - - template constexpr static Char null_char(); template<> constexpr char null_char (){return '\0';} template<> constexpr wchar_t null_char (){return L'\0';} -template<> constexpr char16_t null_char (){return u'\0';} -template<> constexpr char32_t null_char (){return U'\0';} template constexpr static Char equal_sign(); template<> constexpr char equal_sign () {return '='; } template<> constexpr wchar_t equal_sign () {return L'='; } -template<> constexpr char16_t equal_sign() {return u'='; } -template<> constexpr char32_t equal_sign() {return U'='; } -}} +template constexpr static Char quote_sign(); +template<> constexpr char quote_sign () {return '"'; } +template<> constexpr wchar_t quote_sign () {return L'"'; } + +template constexpr static Char space_sign(); +template<> constexpr char space_sign () {return ' '; } +template<> constexpr wchar_t space_sign () {return L' '; } + + +}}} #endif diff --git a/include/boost/process/detail/posix/basic_cmd.hpp b/include/boost/process/detail/posix/basic_cmd.hpp index 87354cc7..9779e019 100644 --- a/include/boost/process/detail/posix/basic_cmd.hpp +++ b/include/boost/process/detail/posix/basic_cmd.hpp @@ -97,9 +97,11 @@ inline std::vector build_args(const std::string & data) return st; } +template +struct exe_cmd_init; - -struct exe_cmd_init : boost::process::detail::api::handler_base_ext +template<> +struct exe_cmd_init : boost::process::detail::api::handler_base_ext { exe_cmd_init(const exe_cmd_init & ) = delete; exe_cmd_init(exe_cmd_init && ) = default; @@ -152,7 +154,7 @@ private: std::vector cmd_impl; }; -std::vector exe_cmd_init::make_cmd() +std::vector exe_cmd_init::make_cmd() { std::vector vec; if (!exe.empty()) diff --git a/include/boost/process/detail/posix/cmd.hpp b/include/boost/process/detail/posix/cmd.hpp index 7b99dd16..33449b68 100644 --- a/include/boost/process/detail/posix/cmd.hpp +++ b/include/boost/process/detail/posix/cmd.hpp @@ -7,6 +7,7 @@ #ifndef BOOST_PROCESS_DETAIL_POSIX_CMD_HPP_ #define BOOST_PROCESS_DETAIL_POSIX_CMD_HPP_ +#include #include #include #include @@ -22,19 +23,19 @@ namespace posix -inline std::vector build_cmd(const std::string & value) +template +inline std::vector> build_cmd(const std::basic_string & value) { - std::vector ret; - + std::vector> ret; - bool in_quotes = false; - auto beg = value.begin(); + bool in_quotes = false; + auto beg = value.begin(); for (auto itr = value.begin(); itr != value.end(); itr++) { - if (*itr == '"') + if (*itr == quote_sign()) in_quotes = !in_quotes; - if (!in_quotes && (*itr == ' ')) + if (!in_quotes && (*itr == space_sign())) { if (itr != beg) { @@ -49,25 +50,31 @@ inline std::vector build_cmd(const std::string & value) return ret; } +template struct cmd_setter_ : handler_base_ext { - cmd_setter_(std::string && cmd_line) : _cmd_line(api::build_cmd(std::move(cmd_line))) {} - cmd_setter_(const std::string & cmd_line) : _cmd_line(api::build_cmd(cmd_line)) {} + typedef Char value_type; + typedef std::basic_string string_type; + + cmd_setter_(string_type && cmd_line) : _cmd_line(api::build_cmd(std::move(cmd_line))) {} + cmd_setter_(const string_type & cmd_line) : _cmd_line(api::build_cmd(cmd_line)) {} template void on_setup(Executor& exec) { exec.cmd_line = &_cmd_impl.front(); } + const string_type & str() const {return _cmd_line;} + private: - static inline std::vector make_cmd(std::vector & args); - std::vector _cmd_line; - std::vector _cmd_impl = make_cmd(_cmd_line); + static inline std::vector make_cmd(std::vector & args); + std::vector _cmd_line; + std::vector _cmd_impl = make_cmd(_cmd_line); }; - -std::vector cmd_setter_::make_cmd(std::vector & args) +template +std::vector cmd_setter_::make_cmd(std::vector> & args) { - std::vector vec; + std::vector vec; for (auto & v : args) vec.push_back(&v.front()); diff --git a/include/boost/process/detail/posix/env_init.hpp b/include/boost/process/detail/posix/env_init.hpp index d212b3ac..4d01cdad 100644 --- a/include/boost/process/detail/posix/env_init.hpp +++ b/include/boost/process/detail/posix/env_init.hpp @@ -14,7 +14,11 @@ namespace boost { namespace process { namespace detail { namespace posix { -struct env_init : handler_base_ext +template +struct env_init; + +template<> +struct env_init : handler_base_ext { boost::process::environment env; diff --git a/include/boost/process/detail/posix/environment.hpp b/include/boost/process/detail/posix/environment.hpp index 8274791a..b699f7bb 100644 --- a/include/boost/process/detail/posix/environment.hpp +++ b/include/boost/process/detail/posix/environment.hpp @@ -47,10 +47,10 @@ class native_environment_impl std::vector> _buffer = _load(); std::vector _impl = _load_var(_buffer); public: - using char_type = char; + using char_type = Char; using pointer_type = const char_type*; using string_type = std::basic_string; - using native_handle_type = char **; + using native_handle_type = char_type **; void reload() { @@ -68,7 +68,7 @@ public: string_type get(const string_type & id) { std::string id_c = ::boost::process::detail::convert(id); - string_type g = ::getenv(id_c.c_str()); + std::string g = ::getenv(id_c.c_str()); return ::boost::process::detail::convert(g.c_str()); } void set(const string_type & id, const string_type & value) @@ -104,7 +104,7 @@ public: using char_type = char; using pointer_type = const char_type*; using string_type = std::basic_string; - using native_handle_type = char **; + using native_handle_type = char_type **; void reload() {} diff --git a/include/boost/process/detail/posix/start_dir.hpp b/include/boost/process/detail/posix/start_dir.hpp index 8b2ee111..35894b5d 100644 --- a/include/boost/process/detail/posix/start_dir.hpp +++ b/include/boost/process/detail/posix/start_dir.hpp @@ -16,20 +16,21 @@ namespace boost { namespace process { namespace detail { namespace posix { - +template struct start_dir_init : handler_base_ext { -public: - explicit start_dir_init(const std::string &s) : s_(s) {} + typedef Char value_type; + typedef std::basic_string string_type; + explicit start_dir_init(const string_type &s) : s_(s) {} template void on_exec_setup(PosixExecutor&) const { ::chdir(s_.c_str()); } - + const string_type & str() const {return s_;} private: - std::string s_; + string_type s_; }; }}}} diff --git a/include/boost/process/detail/windows/cmd.hpp b/include/boost/process/detail/windows/cmd.hpp index 2c3d5415..ed78ca73 100644 --- a/include/boost/process/detail/windows/cmd.hpp +++ b/include/boost/process/detail/windows/cmd.hpp @@ -31,7 +31,9 @@ struct cmd_setter_ : ::boost::process::detail::handler_base { exec.cmd_line = _cmd_line.c_str(); } -public: + const string_type & str() const {return _cmd_line;} + +private: string_type _cmd_line; }; diff --git a/include/boost/process/environment.hpp b/include/boost/process/environment.hpp index 0368b14e..2ffc498d 100644 --- a/include/boost/process/environment.hpp +++ b/include/boost/process/environment.hpp @@ -235,7 +235,7 @@ public: iterator find( const string_type& key ) { auto p = this->_env_impl; - auto st1 = key + equal_sign(); + auto st1 = key + ::boost::process::detail::equal_sign(); while (*p != nullptr) { if (std::equal(st1.begin(), st1.end(), *p)) @@ -247,7 +247,7 @@ public: const_iterator find( const string_type& key ) const { auto p = this->_env_impl; - auto st1 = key + equal_sign(); + auto st1 = key + ::boost::process::detail::equal_sign(); while (*p != nullptr) { if (std::equal(st1.begin(), st1.end(), *p)) @@ -260,7 +260,7 @@ public: std::size_t count(const string_type & st) const { auto p = this->_env_impl; - auto st1 = st + equal_sign(); + auto st1 = st + ::boost::process::detail::equal_sign(); while (*p != nullptr) { if (std::equal(st1.begin(), st1.end(), *p)) @@ -276,7 +276,7 @@ public: std::pair emplace(const string_type & id, const string_type & value) { auto p = this->_env_impl; - auto st1 = id + equal_sign(); + auto st1 = id + ::boost::process::detail::equal_sign(); auto f = find(id); if (f != end()) {