Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit901ad1d

Browse files
committed
exec arguments splitter
1 parent1f003c8 commit901ad1d

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

‎CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ if(APPLE)
111111
get_filename_component(ICU_LIBDATA_DIR"${ICU_DATA_LIBRARY}"DIRECTORY)
112112
set_target_properties(${PROJECT_NAME}PROPERTIESLINK_FLAGS"-L${ICU_LIBDATA_DIR}")
113113
set_target_properties(${PLEXUS_SHARED}PROPERTIESLINK_FLAGS"-L${ICU_LIBDATA_DIR}")
114-
target_link_libraries(${PLEXUS_SHARED}Boost::program_options)
115114
endif()
116115

117116
# install executable

‎exec.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,36 @@ void exec(const std::string& prog, const std::string& args, const std::string& d
135135
#include<fcntl.h>
136136
#include<spawn.h>
137137
#include<sys/wait.h>
138-
#include<boost/program_options.hpp>
138+
#include<boost/tokenizer.hpp>
139+
#include<boost/shared_array.hpp>
139140
#include<vector>
140141

141142
externchar **environ;
142143

143144
namespaceplexus {
144145

146+
boost::shared_array<char*>make_arguments(const std::string& exe,const std::string& args)
147+
{
148+
auto holder = std::make_shared<std::vector<std::string>>();
149+
holder->push_back(boost::replace_all_copy(exe,"","\\"));
150+
151+
boost::tokenizer<boost::escaped_list_separator<char>>tokenizer(args.begin(), args.end(), boost::escaped_list_separator<char>("\\","\t","'\""));
152+
auto iter = tokenizer.begin();
153+
while (iter != tokenizer.end())
154+
{
155+
if (!iter->empty())
156+
holder->push_back(iter->c_str());
157+
++iter;
158+
}
159+
160+
boost::shared_array<char*>array(newchar*[holder->size() +1], [holder](char** ptr) {delete[] ptr; });
161+
for (size_t i =0; i < holder->size(); ++i)
162+
array[i] = holder->at(i).data();
163+
array[holder->size()] =0;
164+
165+
return array;
166+
}
167+
145168
voidexec(const std::string& prog,const std::string& args,const std::string& dir,const std::string& log,bool wait)noexcept(false)
146169
{
147170
_dbg_ <<"execute: cmd=\"" << prog <<"\" args=\"" << args <<"\" pwd=\"" << dir <<"\" log=\"" << log <<"\"";
@@ -160,14 +183,7 @@ void exec(const std::string& prog, const std::string& args, const std::string& d
160183
});
161184
});
162185

163-
auto exe =boost::replace_all_copy(prog,"","\\");
164-
auto arguments =boost::program_options::split_unix(args);
165-
166-
std::vector<char*> argv;
167-
argv.push_back(exe.data());
168-
for (auto& arg : arguments)
169-
argv.push_back(arg.data());
170-
argv.push_back(0);
186+
auto argv =make_arguments(prog, args);
171187

172188
posix_spawn_file_actions_t action;
173189
int status =posix_spawn_file_actions_init(&action);
@@ -219,7 +235,7 @@ void exec(const std::string& prog, const std::string& args, const std::string& d
219235
throwstd::runtime_error(utils::format("posix_spawnattr_setflags: error=%d", status));
220236

221237
pid_t pid;
222-
status =posix_spawnp(&pid,exe.data(), &action, &attr, argv.data(), environ);
238+
status =posix_spawnp(&pid,argv[0], &action, &attr, argv.get(), environ);
223239
if (status)
224240
throwstd::runtime_error(utils::format("posix_spawn: error=%d", status));
225241

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp