Skip to content

Commit

Permalink
vis: add file argument to vis_pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Feb 5, 2017
1 parent bf9fc97 commit 6deb6e0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions register.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdlib.h>
#include <string.h>

#include "vis.h"
#include "vis-core.h"
#include "text.h"
#include "util.h"
#include "register.h"
Expand Down Expand Up @@ -29,7 +29,8 @@ const char *register_get(Vis *vis, Register *reg, size_t *len) {
buffer_init(&buferr);
buffer_clear(&reg->buf);

int status = vis_pipe(vis, &(Filerange){ .start = 0, .end = 0 },
int status = vis_pipe(vis, vis->win->file,
&(Filerange){ .start = 0, .end = 0 },
(const char*[]){ VIS_CLIPBOARD, "--paste", NULL },
&reg->buf, read_buffer, &buferr, read_buffer);

Expand Down Expand Up @@ -70,7 +71,8 @@ bool register_put_range(Vis *vis, Register *reg, Text *txt, Filerange *range) {
Buffer buferr;
buffer_init(&buferr);

int status = vis_pipe(vis, range, (const char*[]){ VIS_CLIPBOARD, "--copy", NULL },
int status = vis_pipe(vis, vis->win->file, range,
(const char*[]){ VIS_CLIPBOARD, "--copy", NULL },
NULL, NULL, &buferr, read_buffer);

if (status != 0)
Expand Down
4 changes: 2 additions & 2 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ static bool cmd_filter(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur
buffer_init(&bufout);
buffer_init(&buferr);

int status = vis_pipe(vis, range, &argv[1], &bufout, read_buffer, &buferr, read_buffer);
int status = vis_pipe(vis, win->file, range, &argv[1], &bufout, read_buffer, &buferr, read_buffer);

if (vis->cancel_filter) {
vis_info_show(vis, "Command cancelled");
Expand Down Expand Up @@ -1618,7 +1618,7 @@ static bool cmd_pipeout(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu
Buffer buferr;
buffer_init(&buferr);

int status = vis_pipe(vis, range, (const char*[]){ argv[1], NULL }, NULL, NULL, &buferr, read_buffer);
int status = vis_pipe(vis, win->file, range, (const char*[]){ argv[1], NULL }, NULL, NULL, &buferr, read_buffer);

if (status == 0 && cur)
view_cursors_to(cur, range->start);
Expand Down
3 changes: 2 additions & 1 deletion vis-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ static const char *file_open_dialog(Vis *vis, const char *pattern) {
return NULL;

Filerange empty = text_range_new(0,0);
int status = vis_pipe(vis, &empty, (const char*[]){ buffer_content0(&bufcmd), NULL },
int status = vis_pipe(vis, vis->win->file, &empty,
(const char*[]){ buffer_content0(&bufcmd), NULL },
&bufout, read_buffer, &buferr, read_buffer);

if (status == 0)
Expand Down
7 changes: 4 additions & 3 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,13 +1481,13 @@ Regex *vis_regex(Vis *vis, const char *pattern) {
return regex;
}

int vis_pipe(Vis *vis, Filerange *range, const char *argv[],
int vis_pipe(Vis *vis, File *file, Filerange *range, const char *argv[],
void *stdout_context, ssize_t (*read_stdout)(void *stdout_context, char *data, size_t len),
void *stderr_context, ssize_t (*read_stderr)(void *stderr_context, char *data, size_t len)) {

/* if an invalid range was given, stdin (i.e. key board input) is passed
* through the external command. */
Text *text = vis->win->file->text;
Text *text = file->text;
int pin[2], pout[2], perr[2], status = -1;
bool interactive = !text_range_valid(range);
Filerange rout = interactive ? text_range_new(0, 0) : *range;
Expand Down Expand Up @@ -1547,6 +1547,7 @@ int vis_pipe(Vis *vis, Filerange *range, const char *argv[],
close(perr[0]);
close(perr[1]);
close(null);

if (!argv[1])
execlp(vis->shell, vis->shell, "-c", argv[0], (char*)NULL);
else
Expand Down Expand Up @@ -1666,7 +1667,7 @@ int vis_pipe_collect(Vis *vis, Filerange *range, const char *argv[], char **out,
Buffer bufout, buferr;
buffer_init(&bufout);
buffer_init(&buferr);
int status = vis_pipe(vis, range, argv,
int status = vis_pipe(vis, vis->win->file, range, argv,
&bufout, out ? read_buffer : NULL,
&buferr, err ? read_buffer : NULL);
buffer_terminate(&bufout);
Expand Down
2 changes: 1 addition & 1 deletion vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ bool vis_prompt_cmd(Vis*, const char *cmd);
* 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, Filerange *range, const char *argv[],
int vis_pipe(Vis*, File*, Filerange*, const char *argv[],
void *stdout_context, ssize_t (*read_stdout)(void *stdout_context, char *data, size_t len),
void *stderr_context, ssize_t (*read_stderr)(void *stderr_context, char *data, size_t len));

Expand Down

0 comments on commit 6deb6e0

Please sign in to comment.