From 7158aa00b77e7c4286eabda822dcacc9f20fef36 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 3 May 2012 07:33:13 +0000 Subject: [PATCH] use ShellManager in do_pipe --- src/main.cc | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/src/main.cc b/src/main.cc index 0af2824e..599ef62a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -580,44 +580,9 @@ void do_pipe(Editor& editor, int count) editor.buffer().begin_undo_group(); for (auto& sel : const_cast(editor).selections()) { - int write_pipe[2]; - int read_pipe[2]; - - pipe(write_pipe); - pipe(read_pipe); - - if (pid_t pid = fork()) - { - close(write_pipe[0]); - close(read_pipe[1]); - - String content = editor.buffer().string(sel.begin(), sel.end()); - memoryview data = content.data(); - write(write_pipe[1], data.pointer(), data.size()); - close(write_pipe[1]); - - String new_content; - char buffer[1024]; - while (size_t size = read(read_pipe[0], buffer, 1024)) - { - new_content += String(buffer, buffer+size); - } - close(read_pipe[0]); - waitpid(pid, NULL, 0); - - editor.buffer().modify(Modification::make_erase(sel.begin(), sel.end())); - editor.buffer().modify(Modification::make_insert(sel.begin(), new_content)); - } - else - { - close(write_pipe[1]); - close(read_pipe[0]); - - dup2(read_pipe[1], 1); - dup2(write_pipe[0], 0); - - execlp("sh", "sh", "-c", cmdline.c_str(), NULL); - } + String new_content = ShellManager::instance().eval(cmdline, main_context); + editor.buffer().modify(Modification::make_erase(sel.begin(), sel.end())); + editor.buffer().modify(Modification::make_insert(sel.begin(), new_content)); } editor.buffer().end_undo_group(); }