diff --git a/src/args.c b/src/args.c
index 15bd506..b55f401 100644
a
|
b
|
mc_setup_by_args (int argc, char *argv[]) |
516 | 516 | |
517 | 517 | if (tmp != NULL) |
518 | 518 | mc_run_param0 = g_strdup (tmp); |
| 519 | #ifdef HAVE_UNISTD_H |
| 520 | /* If fd0 is non-interactive, a file is being piped */ |
| 521 | else if (!isatty(fileno(stdin))) |
| 522 | mc_run_param0 = g_strdup("-"); |
| 523 | #endif |
519 | 524 | else |
520 | 525 | { |
521 | 526 | fprintf (stderr, "%s\n", _("No arguments given to the viewer.")); |
diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c
index 765bc82..9c3a66b 100644
a
|
b
|
prepend_cwd_on_local (const char *filename) |
907 | 907 | size_t l; |
908 | 908 | vfs_path_t *vpath; |
909 | 909 | |
| 910 | if (filename[0] == '-' && filename[1] == '\0') /* don't let it reach vfs */ |
| 911 | return g_strdup (filename); |
| 912 | |
910 | 913 | vpath = vfs_path_from_str (filename); |
911 | 914 | if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename)) |
912 | 915 | { |
diff --git a/src/viewer/datasource.c b/src/viewer/datasource.c
index 008183e..fde7399 100644
a
|
b
|
mcview_set_datasource_stdio_pipe (mcview_t * view, FILE * fp) |
91 | 91 | /* --------------------------------------------------------------------------------------------- */ |
92 | 92 | |
93 | 93 | void |
| 94 | mcview_set_datasource_stdin_pipe (mcview_t * view) |
| 95 | { |
| 96 | view->datasource = DS_STDIN_PIPE; |
| 97 | view->ds_stdio_pipe = stdin; |
| 98 | |
| 99 | mcview_growbuf_init (view); |
| 100 | } |
| 101 | |
| 102 | /* --------------------------------------------------------------------------------------------- */ |
| 103 | |
| 104 | void |
94 | 105 | mcview_set_datasource_none (mcview_t * view) |
95 | 106 | { |
96 | 107 | view->datasource = DS_NONE; |
… |
… |
mcview_get_filesize (mcview_t * view) |
106 | 117 | case DS_NONE: |
107 | 118 | return 0; |
108 | 119 | case DS_STDIO_PIPE: |
| 120 | case DS_STDIN_PIPE: |
109 | 121 | case DS_VFS_PIPE: |
110 | 122 | return mcview_growbuf_filesize (view); |
111 | 123 | case DS_FILE: |
… |
… |
mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r |
171 | 183 | switch (view->datasource) |
172 | 184 | { |
173 | 185 | case DS_STDIO_PIPE: |
| 186 | case DS_STDIN_PIPE: |
174 | 187 | case DS_VFS_PIPE: |
175 | 188 | str = mcview_get_ptr_growing_buffer (view, byte_index); |
176 | 189 | break; |
… |
… |
mcview_close_datasource (mcview_t * view) |
318 | 331 | } |
319 | 332 | mcview_growbuf_free (view); |
320 | 333 | break; |
| 334 | case DS_STDIN_PIPE: |
| 335 | view->ds_stdio_pipe = NULL; |
| 336 | mcview_growbuf_free (view); |
| 337 | break; |
321 | 338 | case DS_VFS_PIPE: |
322 | 339 | if (view->ds_vfs_pipe != -1) |
323 | 340 | { |
diff --git a/src/viewer/display.c b/src/viewer/display.c
index bf02049..83437c0 100644
a
|
b
|
mcview_set_buttonbar (mcview_t * view) |
110 | 110 | } |
111 | 111 | |
112 | 112 | buttonbar_set_label (b, 5, Q_ ("ButtonBar|Goto"), keymap, (Widget *) view); |
113 | | buttonbar_set_label (b, 8, view->magic_mode ? Q_ ("ButtonBar|Raw") |
114 | | : Q_ ("ButtonBar|Parse"), keymap, (Widget *) view); |
| 113 | |
| 114 | if (view->datasource == DS_STDIN_PIPE) |
| 115 | buttonbar_set_label (b, 8, NULL, NULL, NULL); |
| 116 | else |
| 117 | buttonbar_set_label (b, 8, view->magic_mode ? Q_ ("ButtonBar|Raw") |
| 118 | : Q_ ("ButtonBar|Parse"), keymap, (Widget *) view); |
115 | 119 | |
116 | 120 | if (mcview_is_in_panel (view)) |
117 | 121 | buttonbar_set_label (b, 10, "", keymap, (Widget *) view); |
diff --git a/src/viewer/growbuf.c b/src/viewer/growbuf.c
index a98bf93..05a9657 100644
a
|
b
|
mcview_growbuf_read_until (mcview_t * view, off_t ofs) |
150 | 150 | return; |
151 | 151 | } |
152 | 152 | } |
| 153 | else if (view->datasource == DS_STDIN_PIPE) |
| 154 | { |
| 155 | nread = fread (p, 1, bytesfree, view->ds_stdio_pipe); |
| 156 | if (nread == 0) |
| 157 | { |
| 158 | view->growbuf_finished = TRUE; |
| 159 | view->ds_stdio_pipe = NULL; |
| 160 | return; |
| 161 | } |
| 162 | } |
153 | 163 | else |
154 | 164 | { |
155 | 165 | assert (view->datasource == DS_VFS_PIPE); |
diff --git a/src/viewer/inlines.h b/src/viewer/inlines.h
index 8a3233f..3dfb349 100644
a
|
b
|
mcview_get_byte (mcview_t * view, off_t offset, int *retval) |
102 | 102 | switch (view->datasource) |
103 | 103 | { |
104 | 104 | case DS_STDIO_PIPE: |
| 105 | case DS_STDIN_PIPE: |
105 | 106 | case DS_VFS_PIPE: |
106 | 107 | return mcview_get_byte_growing_buffer (view, offset, retval); |
107 | 108 | case DS_FILE: |
diff --git a/src/viewer/internal.h b/src/viewer/internal.h
index 249df6c..75c6f94 100644
a
|
b
|
enum view_ds |
29 | 29 | { |
30 | 30 | DS_NONE, /* No data available */ |
31 | 31 | DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */ |
| 32 | DS_STDIN_PIPE, /* Data comes from a pipe using standart input */ |
32 | 33 | DS_VFS_PIPE, /* Data comes from a piped-in VFS file */ |
33 | 34 | DS_FILE, /* Data comes from a VFS file */ |
34 | 35 | DS_STRING /* Data comes from a string in memory */ |
… |
… |
void mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord, |
228 | 229 | |
229 | 230 | /* datasource.c: */ |
230 | 231 | void mcview_set_datasource_none (mcview_t *); |
| 232 | void mcview_set_datasource_stdin_pipe (mcview_t *); |
231 | 233 | off_t mcview_get_filesize (mcview_t *); |
232 | 234 | void mcview_update_filesize (mcview_t * view); |
233 | 235 | char *mcview_get_ptr_file (mcview_t *, off_t); |
diff --git a/src/viewer/lib.c b/src/viewer/lib.c
index 6863dff..9a91a90 100644
a
|
b
|
mcview_toggle_magic_mode (mcview_t * view) |
78 | 78 | { |
79 | 79 | char *filename, *command; |
80 | 80 | |
| 81 | if (view->datasource == DS_STDIN_PIPE) /* stdin can't be "re-opened" */ |
| 82 | return; /* and we can't do magic toggle without reopen, yet */ |
| 83 | |
81 | 84 | mcview_altered_magic_flag = 1; |
82 | 85 | view->magic_mode = !view->magic_mode; |
83 | 86 | filename = g_strdup (view->filename); |
diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c
index a67895b..405bf6c 100644
a
|
b
|
mcview_load (mcview_t * view, const char *command, const char *file, int start_l |
312 | 312 | char tmp[BUF_MEDIUM]; |
313 | 313 | struct stat st; |
314 | 314 | |
| 315 | #ifdef HAVE_UNISTD_H |
| 316 | /* See if "-" filename refers to a standart input pipe */ |
| 317 | if (file[0] == '-' && file[1] == '\0' && !isatty (fileno(stdin))) |
| 318 | { |
| 319 | mcview_set_datasource_stdin_pipe (view); |
| 320 | retval = TRUE; |
| 321 | goto finish; |
| 322 | } |
| 323 | #endif |
315 | 324 | /* Open the file */ |
316 | 325 | fd = mc_open (file, O_RDONLY | O_NONBLOCK); |
317 | 326 | if (fd == -1) |