aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-11-14 17:59:24 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-11-15 12:56:56 +0100
commit1c56750f7b6796e850a9299358dc6a187c6278bf (patch)
tree3fe936e9b95966402dd05c29813a51f91175438b /vis.c
parente29a0da9deef521694247421e82448c0a9ab3d73 (diff)
downloadvis-1c56750f7b6796e850a9299358dc6a187c6278bf.tar.gz
vis-1c56750f7b6796e850a9299358dc6a187c6278bf.tar.xz
vis: generalize special stdin handling
In preparation to move argument parsing code out of vis.c.
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/vis.c b/vis.c
index 6782a8e..600a636 100644
--- a/vis.c
+++ b/vis.c
@@ -60,6 +60,7 @@ static File *file_new_text(Vis *vis, Text *text) {
File *file = calloc(1, sizeof(*file));
if (!file)
return NULL;
+ file->fd = -1;
file->text = text;
file->stat = text_stat(text);
if (vis->files)
@@ -364,6 +365,15 @@ bool vis_window_new(Vis *vis, const char *filename) {
return true;
}
+bool vis_window_new_fd(Vis *vis, int fd) {
+ if (fd == -1)
+ return false;
+ if (!vis_window_new(vis, NULL))
+ return false;
+ vis->win->file->fd = fd;
+ return true;
+}
+
bool vis_window_closable(Win *win) {
if (!win || !text_modified(win->file->text))
return true;
@@ -949,13 +959,11 @@ static void vis_args(Vis *vis, int argc, char *argv[]) {
if (!vis->windows && vis->running) {
if (!strcmp(argv[argc-1], "-")) {
- if (!vis_window_new(vis, NULL))
+ if (!vis_window_new_fd(vis, STDOUT_FILENO))
vis_die(vis, "Can not create empty buffer\n");
ssize_t len = 0;
char buf[PIPE_BUF];
- File *file = vis->win->file;
- Text *txt = file->text;
- file->is_stdin = true;
+ Text *txt = vis_text(vis);
while ((len = read(STDIN_FILENO, buf, sizeof buf)) > 0)
text_insert(txt, text_size(txt), buf, len);
if (len == -1)