Ticket #2371: mc-search_position.patch

File mc-search_position.patch, 10.2 KB (added by gotar, 13 years ago)
  • lib/search/internal.h

    diff -urp mc-4.7.5.4/lib/search/internal.h mc-4.7.5.4.new/lib/search/internal.h
    old new GString *mc_search__toupper_case_str (co 
    5757 
    5858void mc_search__cond_struct_new_init_regex (const char *, mc_search_t *, mc_search_cond_t *); 
    5959 
    60 gboolean mc_search__run_regex (mc_search_t *, const void *, gsize, gsize, gsize *); 
     60long mc_search__run_regex (mc_search_t *, const void *, gsize, gsize, gsize *); 
    6161 
    6262GString *mc_search_regex_prepare_replace_str (mc_search_t *, GString *); 
    6363 
    GString *mc_search_regex_prepare_replace 
    6565 
    6666void mc_search__cond_struct_new_init_normal (const char *, mc_search_t *, mc_search_cond_t *); 
    6767 
    68 gboolean mc_search__run_normal (mc_search_t *, const void *, gsize, gsize, gsize *); 
     68long mc_search__run_normal (mc_search_t *, const void *, gsize, gsize, gsize *); 
    6969 
    7070GString *mc_search_normal_prepare_replace_str (mc_search_t *, GString *); 
    7171 
  • lib/search/normal.c

    diff -urp mc-4.7.5.4/lib/search/normal.c mc-4.7.5.4.new/lib/search/normal.c
    old new mc_search__cond_struct_new_init_normal ( 
    108108 
    109109/* --------------------------------------------------------------------------------------------- */ 
    110110 
    111 gboolean 
     111long 
    112112mc_search__run_normal (mc_search_t * lc_mc_search, const void *user_data, 
    113113                       gsize start_search, gsize end_search, gsize * found_len) 
    114114{ 
  • lib/search/regex.c

    diff -urp mc-4.7.5.4/lib/search/regex.c mc-4.7.5.4.new/lib/search/regex.c
    old new mc_search__cond_struct_new_init_regex (c 
    576576 
    577577/* --------------------------------------------------------------------------------------------- */ 
    578578 
    579 gboolean 
     579long 
    580580mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data, 
    581581                      gsize start_search, gsize end_search, gsize * found_len) 
    582582{ 
    mc_search__run_regex (mc_search_t * lc_m 
    584584    int current_chr = 0; 
    585585    gint start_pos; 
    586586    gint end_pos; 
     587    ulong lines = 0; 
    587588 
    588589    if (lc_mc_search->regex_buffer != NULL) 
    589590        g_string_free (lc_mc_search->regex_buffer, TRUE); 
    mc_search__run_regex (mc_search_t * lc_m 
    615616            g_string_append_c (lc_mc_search->regex_buffer, (char) current_chr); 
    616617 
    617618 
    618             if (current_chr == 0 || (char) current_chr == '\n') 
     619            if (current_chr == 0 || (char) current_chr == '\n') { 
     620                lines++; 
    619621                break; 
     622            } 
    620623 
    621624            if (virtual_pos > end_search) 
    622625                break; 
    mc_search__run_regex (mc_search_t * lc_m 
    649652            if (found_len) 
    650653                *found_len = end_pos - start_pos; 
    651654            lc_mc_search->normal_offset = lc_mc_search->start_buffer + start_pos; 
    652             return TRUE; 
     655            return 1+lines; 
    653656        case COND__NOT_ALL_FOUND: 
    654657            break; 
    655658        default: 
    656659            g_string_free (lc_mc_search->regex_buffer, TRUE); 
    657660            lc_mc_search->regex_buffer = NULL; 
    658             return FALSE; 
     661            return 0; 
    659662        } 
    660663        if ((lc_mc_search->update_fn != NULL) && 
    661664            ((lc_mc_search->update_fn) (user_data, current_pos) == MC_SEARCH_CB_ABORT)) 
    mc_search__run_regex (mc_search_t * lc_m 
    673676    else 
    674677        lc_mc_search->error_str = NULL; 
    675678 
    676     return FALSE; 
     679    return 1-lines; 
    677680} 
    678681 
    679682/* --------------------------------------------------------------------------------------------- */ 
  • lib/search/search.c

    diff -urp mc-4.7.5.4/lib/search/search.c mc-4.7.5.4.new/lib/search/search.c
    old new mc_search_prepare (mc_search_t * lc_mc_s 
    232232 
    233233/* --------------------------------------------------------------------------------------------- */ 
    234234 
    235 gboolean 
     235long 
    236236mc_search_run (mc_search_t * lc_mc_search, const void *user_data, 
    237237               gsize start_search, gsize end_search, gsize * found_len) 
    238238{ 
    239     gboolean ret = FALSE; 
    240  
     239    long ret = 0; 
    241240    if (!lc_mc_search) 
    242         return FALSE; 
     241        return 0; 
    243242    if (!mc_search_is_type_avail (lc_mc_search->search_type)) 
    244243    { 
    245244        lc_mc_search->error = MC_SEARCH_E_INPUT; 
    246245        lc_mc_search->error_str = g_strdup (_(STR_E_UNKNOWN_TYPE)); 
    247         return FALSE; 
     246        return 0; 
    248247    } 
    249248#ifdef SEARCH_TYPE_GLIB 
    250249    if (lc_mc_search->regex_match_info) 
    mc_search_run (mc_search_t * lc_mc_searc 
    259258    lc_mc_search->error_str = NULL; 
    260259 
    261260    if ((lc_mc_search->conditions == NULL) && !mc_search_prepare (lc_mc_search)) 
    262         return FALSE; 
     261        return 0; 
    263262 
    264263    switch (lc_mc_search->search_type) 
    265264    { 
  • lib/search.h

    diff -urp mc-4.7.5.4/lib/search.h mc-4.7.5.4.new/lib/search.h
    old new void mc_search_free (mc_search_t * lc_mc 
    127127 
    128128gboolean mc_search_prepare (mc_search_t * mc_search); 
    129129 
    130 gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search, 
     130long mc_search_run (mc_search_t * mc_search, const void *user_data, gsize start_search, 
    131131                        gsize end_search, gsize * found_len); 
    132132 
    133133gboolean mc_search_is_type_avail (mc_search_type_t); 
  • src/viewer/search.c

    diff -urp mc-4.7.5.4/src/viewer/search.c mc-4.7.5.4.new/src/viewer/search.c
    old new mcview_search_update_steps (mcview_t * v 
    7676/* --------------------------------------------------------------------------------------------- */ 
    7777 
    7878static gboolean 
    79 mcview_find (mcview_t * view, gsize search_start, gsize * len) 
     79mcview_find (mcview_t * view, gsize search_start, gsize * len, gboolean secondPass) 
    8080{ 
    8181    gsize search_end; 
     82    long skip_lines; 
    8283 
    8384    view->search_numNeedSkipChar = 0; 
    8485    search_cb_char_curr_index = -1; 
    mcview_find (mcview_t * view, gsize sear 
    9596                && mc_search_is_fixed_search_str (view->search)) 
    9697                search_end = search_start + view->search->original_len; 
    9798 
    98             if (mc_search_run (view->search, (void *) view, search_start, search_end, len) 
     99            skip_lines = mc_search_run (view->search, (void *) view, search_start, search_end, len); 
     100            if (skip_lines 
    99101                && view->search->normal_offset == (off_t) search_start) 
    100102            { 
    101103                if (view->text_nroff_mode) 
    102104                    view->search->normal_offset++; 
     105                view->dpy_start_line-=skip_lines; 
    103106                return TRUE; 
    104107            } 
    105108 
    mcview_find (mcview_t * view, gsize sear 
    111114    view->search_nroff_seq->index = search_start; 
    112115    mcview_nroff_seq_info (view->search_nroff_seq); 
    113116 
    114     return mc_search_run (view->search, (void *) view, search_start, mcview_get_filesize (view), 
     117    skip_lines = mc_search_run (view->search, (void *) view, search_start, mcview_get_filesize (view), 
    115118                          len); 
     119    if (skip_lines>1) { 
     120        view->dpy_start_line+=skip_lines-2; 
     121        if(secondPass && view->dpy_lines_status != -1) view->dpy_start_line-=view->dpy_lines_total-view->dpy_visible_lines; 
     122        if(secondPass && view->dpy_lines_status == -1) { view->dpy_start_line+=view->dpy_visible_lines; view->dpy_lines_status = 0; } 
     123        return TRUE; 
     124    } 
     125    if (view->dpy_lines_status==0) { 
     126        view->dpy_lines_total=view->dpy_start_line-skip_lines; 
     127        view->dpy_lines_status=1; 
     128    } else if (view->dpy_lines_status==-1 && view->dpy_lines_total<-skip_lines) { 
     129        view->dpy_lines_total=-skip_lines; 
     130    } 
     131    return FALSE; 
    116132} 
    117133 
    118134/* --------------------------------------------------------------------------------------------- */ 
    mcview_do_search (mcview_t * view) 
    247263    off_t search_start = 0; 
    248264    gboolean isFound = FALSE; 
    249265    gboolean need_search_again = TRUE; 
     266    long saved_lines_total = view->dpy_lines_total; 
    250267 
    251268    Dlg_head *d = NULL; 
    252269 
    mcview_do_search (mcview_t * view) 
    293310    /* Compute the percent steps */ 
    294311    mcview_search_update_steps (view); 
    295312    view->update_activate = 0; 
     313//    view->dpy_visible_lines = 0;      // mcview_search_show_result -> destroy_dlg sets lines_total as start_line (already calculated) + visible_lines (currently shown) 
    296314 
    297315    tty_enable_interrupt_key (); 
    298316 
    mcview_do_search (mcview_t * view) 
    305323        else 
    306324            growbufsize = view->search->original_len; 
    307325 
    308         if (mcview_find (view, search_start, &match_len)) 
     326        if (mcview_find (view, search_start, &match_len, FALSE)) 
    309327        { 
    310328            mcview_search_show_result (view, &d, match_len); 
    311329            need_search_again = FALSE; 
    mcview_do_search (mcview_t * view) 
    336354            query_dialog (_("Search done"), _("Continue from beginning?"), D_NORMAL, 2, _("&Yes"), 
    337355                          _("&No")); 
    338356 
    339         if (result != 0) 
     357        if (result != 0) { 
     358            saved_lines_total=view->dpy_lines_total; 
    340359            isFound = TRUE; 
    341         else 
     360        } 
     361        else { 
    342362            search_start = 0; 
     363            if (view->dpy_lines_status == -1) { 
     364//              view->dpy_lines_status = 0; 
     365//              view->dpy_lines_total = saved_lines_total;      // for mcview_find below 
     366            } 
     367        } 
    343368    } 
    344369 
    345     if (!isFound && view->search->error_str != NULL && mcview_find (view, search_start, &match_len)) 
     370    if (!isFound && view->search->error_str != NULL) { if(mcview_find (view, search_start, &match_len, TRUE)) 
    346371    { 
    347372        mcview_search_show_result (view, &d, match_len); 
    348373        isFound = TRUE; 
    349     } 
     374    } else { 
     375        saved_lines_total=view->dpy_lines_total; 
     376        if(view->dpy_lines_status==-1) { 
     377        view->dpy_lines_status=1; 
     378        view->dpy_start_line+=view->dpy_lines_total; 
     379        } 
     380    }} 
    350381 
    351382    if (!isFound && view->search->error_str != NULL) 
    352383        message (D_NORMAL, _("Search"), "%s", view->search->error_str); 
    353384 
    354385    view->dirty++; 
     386    view->dpy_lines_total = saved_lines_total; 
    355387    mcview_update (view); 
    356388 
    357389    tty_disable_interrupt_key ();