From bd354843c2751ec6c7b5b85ef08f9145f6232e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 17 Oct 2014 12:51:13 +0200 Subject: Read stdin when given - as filename --- vis.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 087ff08..53a7dbd 100644 --- a/vis.c +++ b/vis.c @@ -1671,12 +1671,27 @@ int main(int argc, char *argv[]) { die("Could not load syntax highlighting definitions\n"); editor_statusbar_set(vis, config->statusbar); - for (int i = 1; i < MAX(argc, 2); i++) { - const char *file = i < argc ? argv[i] : NULL; - if (!editor_window_new(vis, file)) - die("Could not load `%s': %s\n", file, strerror(errno)); + for (int i = 1; i < argc; i++) { + if (argv[i][0] == '-') { + switch (argv[i][1]) { + case '\0': + if (!editor_window_new_fd(vis, STDIN_FILENO)) + die("Can not read from stdin\n"); + int fd = open("/dev/tty", O_RDONLY); + if (fd == -1) + die("Can not reopen stdin\n"); + dup2(fd, STDIN_FILENO); + close(fd); + break; + } + } else if (!editor_window_new(vis, argv[i])) { + die("Can not load `%s': %s\n", argv[i], strerror(errno)); + } } + if (!vis->windows && !editor_window_new(vis, NULL)) + die("Can not create empty buffer\n"); + mainloop(); editor_free(vis); endwin(); -- cgit v1.2.3