summaryrefslogtreecommitdiff
path: root/src/shell_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-05-29 10:39:03 +0000
committerMaxime Coste <frrrwww@gmail.com>2012-05-29 10:39:03 +0000
commit3bfd774f4912c2397734076ec70d298dae1fe51e (patch)
tree9eefcd0d5e295753eda9ba4ccfe3fbc6d8d13929 /src/shell_manager.cc
parent84c1cad3d5304456ba1d2ea8a9977823b99757c1 (diff)
Restore piping support.
Add a ShellManager::pipe method, which pipes a string into the command. Not quite satisfied with this interface.
Diffstat (limited to 'src/shell_manager.cc')
-rw-r--r--src/shell_manager.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 48688494..b9f65766 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -6,26 +6,37 @@
namespace Kakoune
{
+String env_var_regex(R"(\$\{kak_([a-z0-9_]+)[^}]*\}|\$kak_([a-z0-9_]+))");
ShellManager::ShellManager()
- : m_regex(LR"(\$\{kak_([a-z0-9_]+)[^}]*\}|\$kak_([a-z0-9_]+))")
+ : m_regex(env_var_regex.begin(), env_var_regex.end())
{
}
String ShellManager::eval(const String& cmdline, const Context& context,
const EnvVarMap& env_vars)
{
+ return pipe("", cmdline, context, env_vars);
+}
+
+String ShellManager::pipe(const String& input,
+ const String& cmdline, const Context& context,
+ const EnvVarMap& env_vars)
+{
int write_pipe[2];
int read_pipe[2];
- pipe(write_pipe);
- pipe(read_pipe);
+ ::pipe(write_pipe);
+ ::pipe(read_pipe);
String output;
if (pid_t pid = fork())
{
close(write_pipe[0]);
close(read_pipe[1]);
+
+ memoryview<char> data = input.data();
+ write(write_pipe[1], data.pointer(), data.size());
close(write_pipe[1]);
char buffer[1024];