Ticket #1449: mc-4.7.0-pre1.view_tail.patch

File mc-4.7.0-pre1.view_tail.patch, 4.1 KB (added by dborca, 15 years ago)

A quick and dirty hack, against 4.7.0-pre1. Very dirty :)

  • mc-4.7.0-pre1

    diff -Naur mc-4.7.0-pre1~/src/view.c mc-4.7.0-pre1/src/view.c
    old new  
    194194    gboolean text_nroff_mode;   /* Nroff-style highlighting */ 
    195195    gboolean text_wrap_mode;    /* Wrap text lines to fit them on the screen */ 
    196196    gboolean magic_mode;        /* Preprocess the file using external programs */ 
     197    gboolean monitor_mode;      /* Monitor mode a la "tail -f" */ 
     198    offset_type monitor_size;   /* Last known size */ 
    197199 
    198200    /* Additional editor state */ 
    199201    gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */ 
     
    11491151            do { 
    11501152                nread = mc_read (view->ds_vfs_pipe, p, bytesfree); 
    11511153            } while (nread == -1 && errno == EINTR); 
     1154            if (nread == 0 && view->monitor_mode) { 
     1155                return; 
     1156            } 
    11521157            if (nread == -1 || nread == 0) { 
    11531158                view->growbuf_finished = TRUE; 
    11541159                (void) mc_close (view->ds_vfs_pipe); 
     
    15151520    struct cache_line *line; 
    15161521 
    15171522    if (view->growbuf_in_use) 
    1518         view_growbuf_read_until (view, OFFSETTYPE_MAX); 
     1523        view_growbuf_read_until (view, view->monitor_mode ? view_get_filesize(view) + 1024 * 1024 : OFFSETTYPE_MAX); 
    15191524 
    15201525    filesize = view_get_filesize (view); 
    15211526    last_offset = offset_doz(filesize, 1); 
     
    15271532        view_move_up (view, lines_up); 
    15281533        view->hex_cursor = last_offset; 
    15291534    } else { 
     1535        if (view->monitor_mode && view->monitor_size != filesize) { 
     1536            view->monitor_size = filesize; 
     1537#if 0 
     1538            /* XXX way too heavy */ 
     1539            view_reset_cache_lines (view); 
     1540#else 
     1541            /* XXX dangerous trick */ 
     1542            view->lines_end = NULL; 
     1543            view->nroff_lines_end = NULL; 
     1544            if (view->first_showed_line != NULL) { 
     1545                view_load_cache_line (view, view->first_showed_line); 
     1546            } 
     1547#endif 
     1548        } 
    15301549        line = view_get_last_line (view); 
    15311550        if (!view->text_wrap_mode) 
    15321551            line = view_get_start_of_whole_line (view, line); 
     
    18581877    view->dirty++; 
    18591878} 
    18601879 
     1880static void 
     1881view_toggle_monitor_mode (WView *view) 
     1882{ 
     1883    char *filename, *command; 
     1884 
     1885    int line_number = 0; 
     1886    struct cache_line *line = view_get_first_showed_line (view); 
     1887    if (line != NULL) { 
     1888        line_number = line->number + 1; 
     1889    } 
     1890 
     1891    view->monitor_size = 0; 
     1892    view->monitor_mode = !view->monitor_mode; 
     1893    filename = g_strdup (view->filename); 
     1894    command = g_strdup (view->command); 
     1895 
     1896    view_done (view); 
     1897    view_load (view, command, filename, line_number); 
     1898    g_free (filename); 
     1899    g_free (command); 
     1900    view->dpy_bbar_dirty = TRUE; 
     1901    view->dirty++; 
     1902 
     1903    set_idle_proc(view->widget.parent, view->monitor_mode); 
     1904} 
     1905 
    18611906/* {{{ Miscellaneous functions }}} */ 
    18621907 
    18631908static void 
     
    20162061            goto finish; 
    20172062        } 
    20182063 
    2019         if (st.st_size == 0 || mc_lseek (fd, 0, SEEK_SET) == -1) { 
     2064        if (view->monitor_mode || st.st_size == 0 || mc_lseek (fd, 0, SEEK_SET) == -1) { 
    20202065            /* Must be one of those nice files that grow (/proc) */ 
    20212066            view_set_datasource_vfs_pipe (view, fd); 
    20222067        } else { 
     
    21032148 
    21042149    if (height < 1 || right < 4) 
    21052150        return; 
     2151    if (view->monitor_mode) { 
     2152        widget_move (view, top, right - 4); 
     2153        tty_print_string("tail"); 
     2154        return; 
     2155    } 
    21062156    if (view_may_still_grow (view)) 
    21072157        return; 
    21082158    filesize = view_get_filesize (view); 
     
    36683718        view->dirty++; 
    36693719        return MSG_HANDLED; 
    36703720 
     3721    case 'F': 
     3722        if (!view_is_in_panel(view)) { 
     3723            view_toggle_monitor_mode(view); 
     3724        } 
     3725        return MSG_HANDLED; 
     3726 
    36713727        /*  Use to indicate parent that we want to see the next/previous file */ 
    36723728        /* Does not work in panel mode */ 
    36733729    case XCTRL ('f'): 
     
    37993855    case DLG_RESIZE: 
    38003856        view_adjust_size (h); 
    38013857        return MSG_HANDLED; 
     3858    case DLG_IDLE: { 
     3859        int c; 
     3860        Gpm_Event event; 
     3861        WView *view = (WView *)find_widget_type(h, view_callback); 
     3862        /* XXX can't handle file truncations */ 
     3863        view_moveto_bottom(view); 
     3864        view_update(view); 
     3865        event.x = -1; 
     3866        c = get_event (&event, h->mouse_status == MOU_REPEAT, 0); 
     3867        if (c != EV_NONE) { 
     3868            dlg_process_event (h, c, &event); 
     3869            if (!h->running) { 
     3870                set_idle_proc(h, 0); 
     3871            } 
     3872        } else { 
     3873            sleep(1); 
     3874        } 
     3875        return MSG_HANDLED; 
     3876    } 
    38023877 
    38033878    default: 
    38043879        return default_dlg_callback (h, msg, parm);