Ticket #2229: mc-null_viewer.patch

File mc-null_viewer.patch, 8.3 KB (added by gotar, 14 years ago)
  • src/viewer/dialogs.c

    diff -urNp mc-4.7.4/src/viewer/dialogs.c mc-4.7.4.viewer/src/viewer/dialogs.c
    old new mcview_dialog_goto (mcview_t * view, off 
    280280            default: 
    281281                break; 
    282282            } 
    283             *offset = mcview_bol (view, *offset); 
     283            *offset = mcview_bol (view, *offset, 0); 
    284284        } 
    285285    } 
    286286 
  • src/viewer/internal.h

    diff -urNp mc-4.7.4/src/viewer/internal.h mc-4.7.4.viewer/src/viewer/internal.h
    old new void mcview_done (mcview_t * view); 
    290290void mcview_select_encoding (mcview_t * view); 
    291291void mcview_set_codeset (mcview_t * view); 
    292292void mcview_show_error (mcview_t * view, const char *error); 
    293 off_t mcview_bol (mcview_t * view, off_t current); 
    294 off_t mcview_eol (mcview_t * view, off_t current); 
     293off_t mcview_bol (mcview_t * view, off_t current, off_t limit); 
     294off_t mcview_eol (mcview_t * view, off_t current, off_t limit); 
    295295char *mcview_get_title (const Dlg_head * h, size_t len); 
    296296gboolean mcview_lock_file (mcview_t * view); 
    297297gboolean mcview_unlock_file (mcview_t * view); 
  • src/viewer/lib.c

    diff -urNp mc-4.7.4/src/viewer/lib.c mc-4.7.4.viewer/src/viewer/lib.c
    old new void 
    9696mcview_toggle_wrap_mode (mcview_t * view) 
    9797{ 
    9898    if (view->text_wrap_mode) 
    99         view->dpy_start = mcview_bol (view, view->dpy_start); 
     99        view->dpy_start = mcview_bol (view, view->dpy_start, 0); 
    100100    view->text_wrap_mode = !view->text_wrap_mode; 
    101101    view->dpy_bbar_dirty = TRUE; 
    102102    view->dirty++; 
    mcview_show_error (mcview_t * view, cons 
    339339/* returns index of the first char in the line */ 
    340340/* it is constant for all line characters */ 
    341341off_t 
    342 mcview_bol (mcview_t * view, off_t current) 
     342mcview_bol (mcview_t * view, off_t current, off_t limit) 
    343343{ 
    344344    int c; 
    345345    off_t filesize; 
    mcview_bol (mcview_t * view, off_t curre 
    357357        if (c == '\r') 
    358358            current--; 
    359359    } 
    360     while (current > 0) 
     360    while (current > 0 && current >= limit) 
    361361    { 
    362362        if (!mcview_get_byte (view, current - 1, &c)) 
    363363            break; 
    mcview_bol (mcview_t * view, off_t curre 
    373373/* returns index of last char on line + width EOL */ 
    374374/* mcview_eol of the current line == mcview_bol next line */ 
    375375off_t 
    376 mcview_eol (mcview_t * view, off_t current) 
     376mcview_eol (mcview_t * view, off_t current, off_t limit) 
    377377{ 
    378378    int c, prev_ch = 0; 
    379379    off_t filesize; 
    mcview_eol (mcview_t * view, off_t curre 
    382382        return 0; 
    383383    if (current >= filesize) 
    384384        return filesize; 
    385     while (current < filesize) 
     385    while (current < filesize && current < limit) 
    386386    { 
    387387        if (!mcview_get_byte (view, current, &c)) 
    388388            break; 
  • src/viewer/mcviewer.c

    diff -urNp mc-4.7.4/src/viewer/mcviewer.c mc-4.7.4.viewer/src/viewer/mcviewer.c
    old new mcview_load (mcview_t * view, const char 
    414414        canon_fname = vfs_canon (view->filename); 
    415415        load_file_position (canon_fname, &line, &col, &new_offset); 
    416416        new_offset = min (new_offset, mcview_get_filesize (view)); 
    417         view->dpy_start = mcview_bol (view, new_offset); 
     417        view->dpy_start = mcview_bol (view, new_offset, 0); 
    418418        g_free (canon_fname); 
    419419    } 
    420420    else if (start_line > 0) 
  • src/viewer/move.c

    diff -urNp mc-4.7.4/src/viewer/move.c mc-4.7.4.viewer/src/viewer/move.c
    old new mcview_move_up (mcview_t * view, off_t l 
    108108        off_t i; 
    109109        for (i = 0; i < lines; i++) 
    110110        { 
    111             off_t cur_bol; 
    112             cur_bol = new_offset = mcview_bol (view, view->dpy_start); 
    113             if (new_offset > 0) 
    114                 new_offset--; 
    115             new_offset = mcview_bol (view, new_offset); 
    116             if (new_offset < 0) 
    117                 new_offset = 0; 
     111            if (view->dpy_start==0) break; 
    118112            if (view->text_wrap_mode) 
    119113            { 
    120                 size_t last_row_length = (view->dpy_start - new_offset) % view->data_area.width; 
    121                 if (last_row_length != 0 && cur_bol == view->dpy_start) 
    122                     new_offset = max (new_offset, (off_t) (view->dpy_start - last_row_length)); 
    123                 else 
    124                     new_offset = max (new_offset, view->dpy_start - view->data_area.width); 
     114                new_offset = mcview_bol (view, view->dpy_start, view->dpy_start - 1);   // check if dpy_start==BOL or not (then new_offset=dpy_start-1, no need to check more) 
     115            if (new_offset == view->dpy_start) { 
     116                new_offset--; 
     117                new_offset = mcview_bol (view, new_offset, 0); 
     118                size_t last_row_length = (view->dpy_start - new_offset) % view->data_area.width; 
     119                if (last_row_length > 0) 
     120                        new_offset = view->dpy_start - last_row_length;         // if dpy_start==BOL in wrapped mode, find BOL of previous line and move down all but the last rows 
     121            } else      new_offset = view->dpy_start - view->data_area.width;   // if dpy_start!=BOL in wrapped mode, just move one row up; no need to check if > 0 as there is at least exactly one wrap between dpy_start and BOL 
     122                view->dpy_start = new_offset; 
     123            } else {    // if unwrapped -> current BOL equals dpy_start, just find BOL of previous line 
     124                new_offset = view->dpy_start; 
     125                new_offset--; 
     126                view->dpy_start = mcview_bol (view, new_offset, 0); 
    125127            } 
    126             view->dpy_start = new_offset; 
    127128        } 
    128129    } 
    129130    mcview_movement_fixups (view, TRUE); 
    mcview_move_down (mcview_t * view, off_t 
    160161        { 
    161162            while (lines-- > 0) 
    162163            { 
    163                 new_offset = mcview_eol (view, view->dpy_end); 
    164164                if (view->text_wrap_mode) 
    165                     new_offset = min (new_offset, view->dpy_end + view->data_area.width); 
    166                 view->dpy_end = new_offset; 
     165                        view->dpy_end = mcview_eol (view, view->dpy_end, view->dpy_end + view->data_area.width); 
     166                else    view->dpy_end = mcview_eol (view, view->dpy_end, last_byte); 
    167167                if(view->dpy_end>=last_byte) lines=0; 
    168168 
    169                 new_offset = mcview_eol (view, view->dpy_start); 
    170169                if (view->text_wrap_mode) 
    171                     new_offset = min (new_offset, view->dpy_start + view->data_area.width); 
     170                        new_offset = mcview_eol (view, view->dpy_start, view->dpy_start + view->data_area.width); 
     171                else    new_offset = mcview_eol (view, view->dpy_start, last_byte); 
    172172                if(new_offset<last_byte) view->dpy_start = new_offset; 
    173173            } 
    174174        } 
    mcview_move_down (mcview_t * view, off_t 
    177177 
    178178            for (i = 0; i < lines && new_offset < last_byte; i++) 
    179179            { 
    180                 new_offset = mcview_eol (view, view->dpy_start); 
    181180                if (view->text_wrap_mode) 
    182                     new_offset = min (new_offset, view->dpy_start + view->data_area.width); 
     181                        new_offset = mcview_eol (view, view->dpy_start, view->dpy_start + view->data_area.width); 
     182                else    new_offset = mcview_eol (view, view->dpy_start, last_byte); 
    183183                if(new_offset<last_byte) view->dpy_start = new_offset; 
    184184            } 
    185185        } 
    mcview_moveto_bol (mcview_t * view) 
    312312    } 
    313313    else if (!view->text_wrap_mode) 
    314314    { 
    315         view->dpy_start = mcview_bol (view, view->dpy_start); 
     315        view->dpy_start = mcview_bol (view, view->dpy_start, 0); 
    316316    } 
    317317    view->dpy_text_column = 0; 
    318318    mcview_movement_fixups (view, TRUE); 
    mcview_moveto_eol (mcview_t * view) 
    342342    else 
    343343    { 
    344344        off_t eol; 
    345         bol = mcview_bol (view, view->dpy_start); 
    346         eol = mcview_eol (view, view->dpy_start); 
     345        bol = mcview_bol (view, view->dpy_start, 0); 
     346        eol = mcview_eol (view, view->dpy_start, mcview_get_filesize (view)); 
    347347        if (!view->utf8) 
    348348        { 
    349349            if (eol > bol) 
    mcview_moveto_match (mcview_t * view) 
    465465    } 
    466466    else 
    467467    { 
    468         view->dpy_start = mcview_bol (view, offset); 
     468        view->dpy_start = mcview_bol (view, offset, 0); 
    469469    } 
    470470 
    471471    mcview_scroll_to_cursor (view);