diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-10-17 12:51:13 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-10-17 14:15:31 +0200 |
| commit | bd354843c2751ec6c7b5b85ef08f9145f6232e6e (patch) | |
| tree | 384528ba3c384160b5a07159f7e49fe6efdd0f01 /vis.c | |
| parent | 9c4999fc9ee4a071bba068e68d690ba637ec28f5 (diff) | |
| download | vis-bd354843c2751ec6c7b5b85ef08f9145f6232e6e.tar.gz vis-bd354843c2751ec6c7b5b85ef08f9145f6232e6e.tar.xz | |
Read stdin when given - as filename
Diffstat (limited to 'vis.c')
| -rw-r--r-- | vis.c | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -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(); |
