Ticket #2370: 2370_viewer_stdin_fix-1a.patch

File 2370_viewer_stdin_fix-1a.patch, 5.6 KB (added by keasy, 13 years ago)

disables magic toggle for stdin input

  • src/args.c

    diff --git a/src/args.c b/src/args.c
    index 15bd506..b55f401 100644
    a b mc_setup_by_args (int argc, char *argv[]) 
    516516 
    517517        if (tmp != NULL) 
    518518            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 
    519524        else 
    520525        { 
    521526            fprintf (stderr, "%s\n", _("No arguments given to the viewer.")); 
  • src/filemanager/midnight.c

    diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c
    index 765bc82..e85eea3 100644
    a b prepend_cwd_on_local (const char *filename) 
    907907    size_t l; 
    908908    vfs_path_t *vpath; 
    909909 
     910    if (filename[0] == '-') /* don't let it reach vfs */ 
     911        return g_strdup (filename); 
     912 
    910913    vpath = vfs_path_from_str (filename); 
    911914    if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename)) 
    912915    { 
  • src/viewer/datasource.c

    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) 
    9191/* --------------------------------------------------------------------------------------------- */ 
    9292 
    9393void 
     94mcview_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 
     104void 
    94105mcview_set_datasource_none (mcview_t * view) 
    95106{ 
    96107    view->datasource = DS_NONE; 
    mcview_get_filesize (mcview_t * view) 
    106117    case DS_NONE: 
    107118        return 0; 
    108119    case DS_STDIO_PIPE: 
     120    case DS_STDIN_PIPE: 
    109121    case DS_VFS_PIPE: 
    110122        return mcview_growbuf_filesize (view); 
    111123    case DS_FILE: 
    mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r 
    171183    switch (view->datasource) 
    172184    { 
    173185    case DS_STDIO_PIPE: 
     186    case DS_STDIN_PIPE: 
    174187    case DS_VFS_PIPE: 
    175188        str = mcview_get_ptr_growing_buffer (view, byte_index); 
    176189        break; 
    mcview_close_datasource (mcview_t * view) 
    318331        } 
    319332        mcview_growbuf_free (view); 
    320333        break; 
     334    case DS_STDIN_PIPE: 
     335        view->ds_stdio_pipe = NULL; 
     336        mcview_growbuf_free (view); 
     337        break; 
    321338    case DS_VFS_PIPE: 
    322339        if (view->ds_vfs_pipe != -1) 
    323340        { 
  • src/viewer/growbuf.c

    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) 
    150150                return; 
    151151            } 
    152152        } 
     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        } 
    153163        else 
    154164        { 
    155165            assert (view->datasource == DS_VFS_PIPE); 
  • src/viewer/inlines.h

    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) 
    102102    switch (view->datasource) 
    103103    { 
    104104    case DS_STDIO_PIPE: 
     105    case DS_STDIN_PIPE: 
    105106    case DS_VFS_PIPE: 
    106107        return mcview_get_byte_growing_buffer (view, offset, retval); 
    107108    case DS_FILE: 
  • src/viewer/internal.h

    diff --git a/src/viewer/internal.h b/src/viewer/internal.h
    index 249df6c..75c6f94 100644
    a b enum view_ds 
    2929{ 
    3030    DS_NONE,                    /* No data available */ 
    3131    DS_STDIO_PIPE,              /* Data comes from a pipe using popen/pclose */ 
     32    DS_STDIN_PIPE,              /* Data comes from a pipe using standart input */ 
    3233    DS_VFS_PIPE,                /* Data comes from a piped-in VFS file */ 
    3334    DS_FILE,                    /* Data comes from a VFS file */ 
    3435    DS_STRING                   /* Data comes from a string in memory */ 
    void mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord, 
    228229 
    229230/* datasource.c: */ 
    230231void mcview_set_datasource_none (mcview_t *); 
     232void mcview_set_datasource_stdin_pipe (mcview_t *); 
    231233off_t mcview_get_filesize (mcview_t *); 
    232234void mcview_update_filesize (mcview_t * view); 
    233235char *mcview_get_ptr_file (mcview_t *, off_t); 
  • src/viewer/lib.c

    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) 
    7878{ 
    7979    char *filename, *command; 
    8080 
     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 
    8184    mcview_altered_magic_flag = 1; 
    8285    view->magic_mode = !view->magic_mode; 
    8386    filename = g_strdup (view->filename); 
  • src/viewer/mcviewer.c

    diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c
    index a67895b..7e5d851 100644
    a b mcview_load (mcview_t * view, const char *command, const char *file, int start_l 
    306306 
    307307    if (command != NULL && (view->magic_mode || file == NULL || file[0] == '\0')) 
    308308        retval = mcview_load_command_output (view, command); 
     309    else if (file != NULL && file[0] == '-') 
     310    { 
     311        /* "-" is a special case, a standart input pipe */ 
     312        mcview_set_datasource_stdin_pipe (view); 
     313        retval = TRUE; 
     314    } 
    309315    else if (file != NULL && file[0] != '\0') 
    310316    { 
    311317        int fd = -1;