mirror of
https://github.com/boostorg/process.git
synced 2026-01-30 20:12:31 +00:00
added cmd-converter && worked on posix stuff
This commit is contained in:
@@ -62,6 +62,27 @@ struct cmd_
|
||||
template<> struct is_wchar_t<api::cmd_setter_<wchar_t>> : std::true_type {};
|
||||
|
||||
|
||||
|
||||
template<>
|
||||
struct char_converter<char, api::cmd_setter_<wchar_t>>
|
||||
{
|
||||
static api::cmd_setter_<char> conv(const api::cmd_setter_<wchar_t> & in)
|
||||
{
|
||||
return { ::boost::process::detail::convert(in.str()) };
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct char_converter<wchar_t, api::cmd_setter_<char>>
|
||||
{
|
||||
static api::cmd_setter_<wchar_t> conv(const api::cmd_setter_<char> & in)
|
||||
{
|
||||
return { ::boost::process::detail::convert(in.str()) };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
constexpr static cmd_ cmd;
|
||||
|
||||
|
||||
|
||||
@@ -72,22 +72,23 @@ inline void throw_last_error()
|
||||
throw std::system_error(get_last_error());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename Char> constexpr static Char null_char();
|
||||
template<> constexpr char null_char<char> (){return '\0';}
|
||||
template<> constexpr wchar_t null_char<wchar_t> (){return L'\0';}
|
||||
template<> constexpr char16_t null_char<char16_t> (){return u'\0';}
|
||||
template<> constexpr char32_t null_char<char32_t> (){return U'\0';}
|
||||
|
||||
template<typename Char> constexpr static Char equal_sign();
|
||||
template<> constexpr char equal_sign<char> () {return '='; }
|
||||
template<> constexpr wchar_t equal_sign<wchar_t> () {return L'='; }
|
||||
template<> constexpr char16_t equal_sign<char16_t>() {return u'='; }
|
||||
template<> constexpr char32_t equal_sign<char32_t>() {return U'='; }
|
||||
|
||||
}}
|
||||
template<typename Char> constexpr static Char quote_sign();
|
||||
template<> constexpr char quote_sign<char> () {return '"'; }
|
||||
template<> constexpr wchar_t quote_sign<wchar_t> () {return L'"'; }
|
||||
|
||||
template<typename Char> constexpr static Char space_sign();
|
||||
template<> constexpr char space_sign<char> () {return ' '; }
|
||||
template<> constexpr wchar_t space_sign<wchar_t> () {return L' '; }
|
||||
|
||||
|
||||
}}}
|
||||
#endif
|
||||
|
||||
@@ -97,9 +97,11 @@ inline std::vector<std::string> build_args(const std::string & data)
|
||||
return st;
|
||||
}
|
||||
|
||||
template<typename Char>
|
||||
struct exe_cmd_init;
|
||||
|
||||
|
||||
struct exe_cmd_init : boost::process::detail::api::handler_base_ext
|
||||
template<>
|
||||
struct exe_cmd_init<char> : 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<char*> cmd_impl;
|
||||
};
|
||||
|
||||
std::vector<char*> exe_cmd_init::make_cmd()
|
||||
std::vector<char*> exe_cmd_init<char>::make_cmd()
|
||||
{
|
||||
std::vector<char*> vec;
|
||||
if (!exe.empty())
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#ifndef BOOST_PROCESS_DETAIL_POSIX_CMD_HPP_
|
||||
#define BOOST_PROCESS_DETAIL_POSIX_CMD_HPP_
|
||||
|
||||
#include <boost/process/detail/config.hpp>
|
||||
#include <boost/process/detail/posix/handler.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -22,19 +23,19 @@ namespace posix
|
||||
|
||||
|
||||
|
||||
inline std::vector<std::string> build_cmd(const std::string & value)
|
||||
template<typename Char>
|
||||
inline std::vector<std::basic_string<Char>> build_cmd(const std::basic_string<Char> & value)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
|
||||
std::vector<std::basic_string<Char>> 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<Char>())
|
||||
in_quotes = !in_quotes;
|
||||
|
||||
if (!in_quotes && (*itr == ' '))
|
||||
if (!in_quotes && (*itr == space_sign<Char>()))
|
||||
{
|
||||
if (itr != beg)
|
||||
{
|
||||
@@ -49,25 +50,31 @@ inline std::vector<std::string> build_cmd(const std::string & value)
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename Char>
|
||||
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<value_type> 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 <class Executor>
|
||||
void on_setup(Executor& exec)
|
||||
{
|
||||
exec.cmd_line = &_cmd_impl.front();
|
||||
}
|
||||
const string_type & str() const {return _cmd_line;}
|
||||
|
||||
private:
|
||||
static inline std::vector<char*> make_cmd(std::vector<std::string> & args);
|
||||
std::vector<std::string> _cmd_line;
|
||||
std::vector<char*> _cmd_impl = make_cmd(_cmd_line);
|
||||
static inline std::vector<Char*> make_cmd(std::vector<string_type> & args);
|
||||
std::vector<string_type> _cmd_line;
|
||||
std::vector<Char*> _cmd_impl = make_cmd(_cmd_line);
|
||||
};
|
||||
|
||||
|
||||
std::vector<char*> cmd_setter_::make_cmd(std::vector<std::string> & args)
|
||||
template<typename Char>
|
||||
std::vector<Char*> cmd_setter_<Char>::make_cmd(std::vector<std::basic_string<Char>> & args)
|
||||
{
|
||||
std::vector<char*> vec;
|
||||
std::vector<Char*> vec;
|
||||
|
||||
for (auto & v : args)
|
||||
vec.push_back(&v.front());
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
|
||||
namespace boost { namespace process { namespace detail { namespace posix {
|
||||
|
||||
struct env_init : handler_base_ext
|
||||
template<typename Char>
|
||||
struct env_init;
|
||||
|
||||
template<>
|
||||
struct env_init<char> : handler_base_ext
|
||||
{
|
||||
boost::process::environment env;
|
||||
|
||||
|
||||
@@ -47,10 +47,10 @@ class native_environment_impl
|
||||
std::vector<std::basic_string<Char>> _buffer = _load();
|
||||
std::vector<Char*> _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<char_type>;
|
||||
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<char_type>;
|
||||
using native_handle_type = char **;
|
||||
using native_handle_type = char_type **;
|
||||
|
||||
void reload() {}
|
||||
|
||||
|
||||
@@ -16,20 +16,21 @@
|
||||
|
||||
namespace boost { namespace process { namespace detail { namespace posix {
|
||||
|
||||
|
||||
template<typename Char>
|
||||
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<value_type> string_type;
|
||||
explicit start_dir_init(const string_type &s) : s_(s) {}
|
||||
|
||||
template <class PosixExecutor>
|
||||
void on_exec_setup(PosixExecutor&) const
|
||||
{
|
||||
::chdir(s_.c_str());
|
||||
}
|
||||
|
||||
const string_type & str() const {return s_;}
|
||||
private:
|
||||
std::string s_;
|
||||
string_type s_;
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ public:
|
||||
iterator find( const string_type& key )
|
||||
{
|
||||
auto p = this->_env_impl;
|
||||
auto st1 = key + equal_sign<Char>();
|
||||
auto st1 = key + ::boost::process::detail::equal_sign<Char>();
|
||||
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<Char>();
|
||||
auto st1 = key + ::boost::process::detail::equal_sign<Char>();
|
||||
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<Char>();
|
||||
auto st1 = st + ::boost::process::detail::equal_sign<Char>();
|
||||
while (*p != nullptr)
|
||||
{
|
||||
if (std::equal(st1.begin(), st1.end(), *p))
|
||||
@@ -276,7 +276,7 @@ public:
|
||||
std::pair<iterator,bool> emplace(const string_type & id, const string_type & value)
|
||||
{
|
||||
auto p = this->_env_impl;
|
||||
auto st1 = id + equal_sign<Char>();
|
||||
auto st1 = id + ::boost::process::detail::equal_sign<Char>();
|
||||
auto f = find(id);
|
||||
if (f != end())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user