diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-04-01 23:41:28 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-01 23:41:28 +0200 |
| commit | ba23d97ef69e9c913775d037b58beb66b5b1384c (patch) | |
| tree | 65680dbbf11c2ab5032a9f81d634e5ee01fd14de | |
| parent | e2f4b5bd6e9d8cba940074e9959d6cebf496132a (diff) | |
| download | vis-ba23d97ef69e9c913775d037b58beb66b5b1384c.tar.gz vis-ba23d97ef69e9c913775d037b58beb66b5b1384c.tar.xz | |
vis: cleanup vis_pipe API
| -rw-r--r-- | register.c | 4 | ||||
| -rw-r--r-- | vis-cmds.c | 10 | ||||
| -rw-r--r-- | vis.h | 11 |
3 files changed, 17 insertions, 8 deletions
@@ -47,7 +47,7 @@ const char *register_get(Vis *vis, Register *reg, size_t *len) { int status = vis_pipe(vis, &clipboard, &(Filerange){ .start = 0, .end = 0 }, - (const char*[]){ "vis-clipboard", "vis-clipboard", "--paste", NULL }, + (const char*[]){ "vis-clipboard", "--paste", NULL }, read_stdout, read_stderr); if (status != 0) vis_info_show(vis, "Command failed %s", stderr.len > 0 ? stderr.data : ""); @@ -90,7 +90,7 @@ bool register_put_range(Vis *vis, Register *reg, Text *txt, Filerange *range) { }; int status = vis_pipe(vis, &clipboard, range, - (const char*[]){ "vis-clipboard", "vis-clipboard", "--copy", NULL }, + (const char*[]){ "vis-clipboard", "--copy", NULL }, NULL, read_stderr); if (status != 0) @@ -700,10 +700,10 @@ int vis_pipe(Vis *vis, void *context, Filerange *range, const char *argv[], dup2(perr[1], STDERR_FILENO); close(perr[0]); close(perr[1]); - if (!argv[2]) - execl("/bin/sh", "sh", "-c", argv[1], NULL); + if (!argv[1]) + execl("/bin/sh", "sh", "-c", argv[0], NULL); else - execvp(argv[1], (char**)argv+1); + execvp(argv[0], (char* const*)argv); vis_info_show(vis, "exec failure: %s", strerror(errno)); exit(EXIT_FAILURE); } @@ -848,7 +848,7 @@ static bool cmd_filter(Vis *vis, Filerange *range, enum CmdOpt opt, const char * text_snapshot(txt); - int status = vis_pipe(vis, &filter, range, argv, read_stdout, read_stderr); + int status = vis_pipe(vis, &filter, range, &argv[1], read_stdout, read_stderr); if (status == 0) { if (text_range_valid(range)) { @@ -902,7 +902,7 @@ static bool cmd_pipe(Vis *vis, Filerange *range, enum CmdOpt opt, const char *ar buffer_init(&filter.err); - int status = vis_pipe(vis, &filter, range, argv, read_stdout_new, read_stderr); + int status = vis_pipe(vis, &filter, range, &argv[1], read_stdout_new, read_stderr); if (vis->cancel_filter) vis_info_show(vis, "Command cancelled"); @@ -389,7 +389,16 @@ bool vis_cmd(Vis*, const char *cmd); /* execute any kind (:,?,/) of prompt command */ bool vis_prompt_cmd(Vis*, const char *cmd); -/* pipe a given file range to an external process */ +/* pipe a given file range to an external process + * + * if argv contains only one non-NULL element the command is executed using + * /bin/sh -c (i.e. argument expansion is performed by the shell). In contrast + * if argv contains more than one non-NULL element execvp(argv[0], argv); will + * be used. + * + * if read_std{out,err} are non-NULL they will be called when output from + * the forked process is available. + */ int vis_pipe(Vis *vis, void *context, Filerange *range, const char *argv[], ssize_t (*read_stdout)(void *context, char *data, size_t len), ssize_t (*read_stderr)(void *context, char *data, size_t len)); |
