Ticket #1487: mc-4.7.0-pre1.search.patch

File mc-4.7.0-pre1.search.patch, 16.3 KB (added by angel_il, 15 years ago)
  • edit/edit-widget.h

    diff -Naur mc-4.7.0-pre1~/edit/edit-widget.h mc-4.7.0-pre1/edit/edit-widget.h
    old new  
    6262    int replace_mode; 
    6363    int replace_backwards; 
    6464    int replace_case; 
     65    int whole_words; 
    6566    int all_codepages; 
    6667 
    6768    long search_start;          /* First character to start searching from */ 
  • edit/editcmd.c

    diff -Naur mc-4.7.0-pre1~/edit/editcmd.c mc-4.7.0-pre1/edit/editcmd.c
    old new  
    12801280    gsize search_end; 
    12811281 
    12821282    if (edit->replace_backwards) { 
    1283         search_end = edit->curs1-1; 
     1283        search_end = edit->last_byte; 
    12841284        while ((int) search_start >= 0) { 
    1285             if (search_end - search_start > edit->search->original_len && mc_search_is_fixed_search_str(edit->search)) 
    1286                 search_end = search_start + edit->search->original_len +1; 
    1287             if ( mc_search_run(edit->search, (void *) edit, search_start, search_end, len)) 
     1285            if (search_end > search_start + edit->search->original_len && mc_search_is_fixed_search_str(edit->search)) 
     1286                search_end = search_start + edit->search->original_len; 
     1287            if ( mc_search_run(edit->search, (void *) edit, search_start, search_end, len) 
     1288                && edit->search->normal_offset == search_start ) 
    12881289            { 
    12891290                return TRUE; 
    12901291            } 
     
    14071408        edit->search->search_type = edit->search_type; 
    14081409        edit->search->is_all_charsets = edit->all_codepages; 
    14091410        edit->search->is_case_sentitive = edit->replace_case; 
     1411        edit->search->whole_words = edit->whole_words; 
    14101412        edit->search->search_fn = edit_search_cmd_callback; 
    14111413    } 
    14121414 
     
    15361538 
    15371539void edit_search_cmd (WEdit * edit, int again) 
    15381540{ 
     1541    static char *saved1 = NULL; /* saved default[123] */ 
    15391542    char *search_string = NULL, *search_string_dup = NULL; 
    15401543 
    15411544    gsize len = 0; 
     
    15451548 
    15461549    if (edit->search != NULL) 
    15471550        search_string_dup = search_string = g_strndup(edit->search->original, edit->search->original_len); 
     1551    else if (saved1 != NULL) 
     1552        search_string_dup = search_string = g_strdup(saved1); 
    15481553 
    15491554    if (!again) 
    15501555    { 
     
    15621567            g_string_free (tmp, FALSE); 
    15631568        } 
    15641569#endif /* HAVE_CHARSET */ 
    1565         editcmd_dialog_search_show (edit, &search_string); 
     1570        editcmd_dialog_search_show (edit, &search_string, &search_create_bookmark); 
    15661571#ifdef HAVE_CHARSET 
    15671572        if (search_string && *search_string) 
    15681573        { 
     
    15911596            mc_search_free(edit->search); 
    15921597            edit->search = NULL; 
    15931598        } 
     1599 
     1600        g_free (saved1), saved1 = g_strdup (search_string); 
    15941601    } 
    15951602 
    15961603    if (!edit->search) 
     
    16041611        edit->search->search_type = edit->search_type; 
    16051612        edit->search->is_all_charsets = edit->all_codepages; 
    16061613        edit->search->is_case_sentitive = edit->replace_case; 
     1614        edit->search->whole_words = edit->whole_words; 
    16071615        edit->search->search_fn = edit_search_cmd_callback; 
    16081616    } 
    16091617 
  • edit/editcmd_dialogs.c

    diff -Naur mc-4.7.0-pre1~/edit/editcmd_dialogs.c mc-4.7.0-pre1/edit/editcmd_dialogs.c
    old new  
    4949/*** file scope macro definitions **************************************/ 
    5050 
    5151#define SEARCH_DLG_WIDTH 58 
    52 #define SEARCH_DLG_MIN_HEIGHT 11 
     52#define SEARCH_DLG_MIN_HEIGHT 12 
    5353#define SEARCH_DLG_HEIGHT_SUPPLY 3 
    5454 
    5555#define REPLACE_DLG_WIDTH 58 
     
    8484{ 
    8585    int treplace_backwards = edit->replace_backwards; 
    8686    int treplace_case = edit->replace_case; 
     87    int twhole_words = edit->whole_words; 
    8788    int tall_codepages = edit->all_codepages; 
    8889    mc_search_type_t ttype_of_search = edit->search_type; 
    8990    int dialog_result; 
     
    101102         0, 0, NULL, NULL, NULL}, 
    102103 
    103104#ifdef HAVE_CHARSET 
    104         {quick_checkbox, 33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("All charsets"), 0, 0, 
     105        {quick_checkbox, 33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT, N_("All charsets"), 0, 0, 
    105106         &tall_codepages, 0, NULL, NULL, NULL}, 
    106107#endif 
    107108 
    108         {quick_checkbox, 33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"), 0, 0, 
     109        {quick_checkbox, 33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT, N_("&Backwards"), 0, 0, 
    109110         &treplace_backwards, 0, NULL, NULL, NULL}, 
    110111 
     112        {quick_checkbox, 33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Whole words"), 0, 0, 
     113         &twhole_words, 0, NULL, NULL, NULL}, 
     114 
    111115        {quick_checkbox, 33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"), 0, 0, 
    112116         &treplace_case, 0, NULL, NULL, NULL}, 
    113117 
     
    153157        edit->all_codepages = tall_codepages; 
    154158        edit->replace_backwards = treplace_backwards; 
    155159        edit->replace_case = treplace_case; 
     160        edit->whole_words = twhole_words; 
    156161        return; 
    157162    } else { 
    158163        *replace_text = NULL; 
     
    164169/* --------------------------------------------------------------------------------------------- */ 
    165170 
    166171void 
    167 editcmd_dialog_search_show (WEdit * edit, char **search_text) 
     172editcmd_dialog_search_show (WEdit * edit, char **search_text, int *psearch_bookmarks) 
    168173{ 
    169174    int tsearch_case = edit->replace_case; 
     175    int twhole_words = edit->whole_words; 
    170176    int tsearch_backwards = edit->replace_backwards; 
    171177    int tall_codepages = edit->all_codepages; 
    172178    mc_search_type_t ttype_of_search = edit->search_type; 
     
    175181 
    176182 
    177183    QuickWidget quick_widgets[] = { 
    178         {quick_button, 6, 10, 9, SEARCH_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 0, 
     184        {quick_button, 6, 10, 10, SEARCH_DLG_HEIGHT, N_("&Cancel"), 0, B_CANCEL, 0, 
    179185         0, NULL, NULL, NULL}, 
    180         {quick_button, 2, 10, 9, SEARCH_DLG_HEIGHT, N_("&OK"), 0, B_ENTER, 0, 
     186        {quick_button, 2, 10, 10, SEARCH_DLG_HEIGHT, N_("&OK"), 0, B_ENTER, 0, 
    181187         0, NULL, NULL, NULL}, 
    182188 
    183189#ifdef HAVE_CHARSET 
    184         {quick_checkbox, 33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("All charsets"), 0, 0, 
     190#define BOOKMARK_Y 9 
     191#else 
     192#define BOOKMARK_Y 8 
     193#endif 
     194        {quick_checkbox, 33, SEARCH_DLG_WIDTH, BOOKMARK_Y, SEARCH_DLG_HEIGHT, N_("set boo&kmarks"), 0, 0, 
     195         psearch_bookmarks, 0, NULL, NULL, NULL}, 
     196 
     197#ifdef HAVE_CHARSET 
     198        {quick_checkbox, 33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("All charsets"), 0, 0, 
    185199         &tall_codepages, 0, NULL, NULL, NULL}, 
    186200#endif 
    187201 
    188         {quick_checkbox, 33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"), 0, 0, 
     202        {quick_checkbox, 33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("&Backwards"), 0, 0, 
    189203         &tsearch_backwards, 0, NULL, NULL, NULL}, 
     204        {quick_checkbox, 33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Whole words"), 0, 0, 
     205         &twhole_words, 0, NULL, NULL, NULL}, 
    190206        {quick_checkbox, 33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), 0, 0, 
    191207         &tsearch_case, 0, NULL, NULL, NULL}, 
    192208 
     
    213229        edit->replace_backwards = tsearch_backwards; 
    214230        edit->all_codepages = tall_codepages; 
    215231        edit->replace_case = tsearch_case; 
     232        edit->whole_words = twhole_words; 
    216233    } else { 
    217234        *search_text = NULL; 
    218235    } 
  • edit/editcmd_dialogs.h

    diff -Naur mc-4.7.0-pre1~/edit/editcmd_dialogs.h mc-4.7.0-pre1/edit/editcmd_dialogs.h
    old new  
    2424 
    2525void editcmd_dialog_replace_show (WEdit *, const char *, const char *, char **, char **); 
    2626 
    27 void editcmd_dialog_search_show (WEdit *, char **); 
     27void editcmd_dialog_search_show (WEdit *, char **, int *); 
    2828 
    2929int editcmd_dialog_raw_key_query (const char *, const char *, int); 
    3030 
  • mc-4.7.0-pre1

    diff -Naur mc-4.7.0-pre1~/src/find.c mc-4.7.0-pre1/src/find.c
    old new  
    8989static WCheck *file_case_sens;          /* "case sensitive" checkbox */ 
    9090static WCheck *find_regex_cbox;         /* [x] find regular expression */ 
    9191static WCheck *content_case_sens;       /* "case sensitive" checkbox */ 
     92static WCheck *content_whole_words_cbox;/* "whole words" checkbox */ 
     93static WCheck *content_first_only_cbox; /* "first only" checkbox */ 
    9294 
    9395static int running = 0;                 /* nice flag */ 
    9496static char *find_pattern = NULL;       /* Pattern to search */ 
     
    148150static gboolean content_regexp_flag = FALSE; 
    149151static gboolean content_all_charsets_flag = FALSE; 
    150152static gboolean content_case_sensitive = TRUE; 
     153static gboolean content_whole_words = FALSE; 
     154static gboolean content_first_only = FALSE; 
    151155 
    152156static int find_recursively = 1; 
    153157 
     
    261265 
    262266    static const char *file_case_label = N_("Cas&e sensitive"); 
    263267    static const char *content_case_label = N_("Case sens&itive"); 
     268    static const char *content_whole_words_label = N_("&Whole words"); 
     269    static const char *content_first_only_label = N_("First &occurence only"); 
    264270    static const char *file_recurs_label = N_("&Find recursively"); 
    265271    static const char *file_skip_hidden_label = N_("S&kip hidden"); 
    266272    static const char *file_all_charsets_label = N_("&All charsets"); 
     
    327333                button_new (FIND_Y - 3, FIND_X/4 - b0/2, B_ENTER, DEFPUSH_BUTTON, buts[0], 0)); 
    328334 
    329335#ifdef HAVE_CHARSET 
    330     content_all_charsets_cbox = check_new (9, FIND_X / 2 + 1, 
     336    content_all_charsets_cbox = check_new (11, FIND_X / 2 + 1, 
    331337                content_all_charsets_flag, content_all_charsets_label); 
    332338    add_widget (find_dlg, content_all_charsets_cbox); 
    333339#endif 
    334340 
    335     find_regex_cbox = check_new (8, FIND_X / 2 + 1, content_regexp_flag, content_regexp_label); 
     341    content_first_only_cbox = check_new (10, FIND_X / 2 + 1, content_first_only, content_first_only_label); 
     342    add_widget (find_dlg, content_first_only_cbox); 
     343 
     344    find_regex_cbox = check_new (9, FIND_X / 2 + 1, content_regexp_flag, content_regexp_label); 
    336345    add_widget (find_dlg, find_regex_cbox); 
    337346 
     347    content_whole_words_cbox = check_new (8, FIND_X / 2 + 1, content_whole_words, content_whole_words_label); 
     348    add_widget (find_dlg, content_whole_words_cbox); 
     349 
    338350    content_case_sens = check_new (7, FIND_X / 2 + 1, content_case_sensitive, content_case_label); 
    339351    add_widget (find_dlg, content_case_sens); 
    340352 
     
    385397        content_all_charsets_flag = content_all_charsets_cbox->state & C_BOOL; 
    386398#endif 
    387399        content_case_sensitive = content_case_sens->state & C_BOOL; 
     400        content_whole_words = content_whole_words_cbox->state & C_BOOL; 
     401        content_first_only = content_first_only_cbox->state & C_BOOL; 
    388402        content_regexp_flag = find_regex_cbox->state & C_BOOL; 
    389403        file_pattern_flag = file_pattern_cbox->state & C_BOOL; 
    390404        file_case_sensitive = file_case_sens->state & C_BOOL; 
     
    418432        content_all_charsets_flag = content_all_charsets_cbox->state & C_BOOL; 
    419433#endif 
    420434        content_case_sensitive = content_case_sens->state & C_BOOL; 
     435        content_whole_words = content_whole_words_cbox->state & C_BOOL; 
     436        content_first_only = content_first_only_cbox->state & C_BOOL; 
    421437        content_regexp_flag = find_regex_cbox->state & C_BOOL; 
    422438        find_recursively = recursively_cbox->state & C_BOOL; 
    423439        file_pattern_flag = file_pattern_cbox->state & C_BOOL; 
     
    680696                    find_add_match (directory, fnd_info); 
    681697                    g_free (fnd_info); 
    682698                    found = TRUE; 
     699                    if (content_first_only) { 
     700                        g_free (p); 
     701                        ret_val = 0; 
     702                        break; 
     703                    } 
    683704                } 
    684705            } 
    685706            if (has_newline){ 
     
    741762    { 
    742763        search_content_handle->search_type = (content_regexp_flag) ? MC_SEARCH_T_REGEX : MC_SEARCH_T_NORMAL; 
    743764        search_content_handle->is_case_sentitive = content_case_sensitive; 
     765        search_content_handle->whole_words = content_whole_words; 
    744766        search_content_handle->is_all_charsets = content_all_charsets_flag; 
    745767    } 
    746768    search_file_handle = mc_search_new(find_pattern, -1); 
  • src/search/normal.c

    diff -Naur mc-4.7.0-pre1~/src/search/normal.c mc-4.7.0-pre1/src/search/normal.c
    old new  
    9191        mc_search__normal_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len); 
    9292 
    9393    g_string_free (mc_search_cond->str, TRUE); 
     94 
     95    if (mc_search->whole_words) { 
     96        g_string_prepend (tmp, "\\b"); 
     97        g_string_append (tmp, "\\b"); 
     98    } 
    9499    mc_search_cond->str = tmp; 
    95100 
    96101    mc_search__cond_struct_new_init_regex (charset, mc_search, mc_search_cond); 
  • src/search/regex.c

    diff -Naur mc-4.7.0-pre1~/src/search/regex.c mc-4.7.0-pre1/src/search/regex.c
    old new  
    6363    const char *special_chars[] = { 
    6464        "\\s", "\\S", 
    6565        "\\d", "\\D", 
    66         "\\B", "\\B", 
     66        "\\b", "\\B", 
    6767        "\\w", "\\W", 
    6868        "\\t", "\\n", 
    6969        "\\r", "\\f", 
  • src/search/search.h

    diff -Naur mc-4.7.0-pre1~/src/search/search.h mc-4.7.0-pre1/src/search/search.h
    old new  
    6363    /* search entire string (from begin to end). Used only with GLOB search type */ 
    6464    gboolean is_entire_line; 
    6565 
     66    /* search entire string (from begin to end). Used only with NORMAL search type */ 
     67    gboolean whole_words; 
     68 
    6669    /* function, used for getting data. NULL if not used */ 
    6770    mc_search_fn search_fn; 
    6871 
  • 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  
    261261    mc_search_type_t search_type; 
    262262    gboolean search_all_codepages; 
    263263    gboolean search_case; 
     264    gboolean whole_words; 
    264265    gboolean search_backwards; 
    265266 
    266267    int search_numNeedSkipChar; 
     
    31463147    if (view->search_backwards) { 
    31473148        search_end = view_get_filesize (view); 
    31483149        while ((int) search_start >= 0) { 
    3149             if (search_end - search_start > view->search->original_len && mc_search_is_fixed_search_str(view->search)) 
     3150            if (search_end > search_start + view->search->original_len && mc_search_is_fixed_search_str(view->search)) 
    31503151                search_end = search_start + view->search->original_len; 
    31513152 
    31523153            view_read_start (view, &view->search_onechar_info, search_start); 
    31533154 
    3154             if ( mc_search_run(view->search, (void *) view, search_start, search_end, len)) 
     3155            if ( mc_search_run(view->search, (void *) view, search_start, search_end, len) 
     3156                && view->search->normal_offset == search_start ) 
    31553157                return TRUE; 
    31563158 
    31573159            search_start--; 
     
    32683270    int ttype_of_search = (int) view->search_type; 
    32693271    int tall_codepages = (int) view->search_all_codepages; 
    32703272    int tsearch_case = (int) view->search_case; 
     3273    int twhole_words = (int) view->whole_words; 
    32713274    int tsearch_backwards = (int) view->search_backwards; 
    32723275 
    32733276    gchar **list_of_types = mc_search_get_types_strings_array(); 
     
    32823285         0, 0, NULL, NULL, NULL}, 
    32833286 
    32843287#ifdef HAVE_CHARSET 
    3285         {quick_checkbox, SEARCH_DLG_WIDTH/2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("All charsets"), 0, 0, 
     3288        {quick_checkbox, SEARCH_DLG_WIDTH/2 + 3, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("All charsets"), 0, 0, 
    32863289         &tall_codepages, 0, NULL, NULL, NULL}, 
    32873290#endif 
    32883291 
    3289         {quick_checkbox, SEARCH_DLG_WIDTH/2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, 
     3292        {quick_checkbox, SEARCH_DLG_WIDTH/2 + 3, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, 
    32903293         N_("&Backwards"), 0, 0, &tsearch_backwards, 0, NULL, NULL, NULL}, 
    32913294 
     3295        {quick_checkbox, SEARCH_DLG_WIDTH/2 + 3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("&Whole words"), 0, 0, 
     3296         &twhole_words, 0, NULL, NULL, NULL}, 
     3297 
    32923298        {quick_checkbox, SEARCH_DLG_WIDTH/2 + 3, SEARCH_DLG_WIDTH, 4, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), 0, 0, 
    32933299         &tsearch_case, 0, NULL, NULL, NULL}, 
    32943300 
     
    33213327 
    33223328    view->search_all_codepages = (gboolean) tall_codepages; 
    33233329    view->search_case = (gboolean) tsearch_case; 
     3330    view->whole_words = (gboolean) twhole_words; 
    33243331 
    33253332    if (exp == NULL || exp[0] == '\0') 
    33263333        goto cleanup; 
     
    33493356    view->search->search_type = view->search_type; 
    33503357    view->search->is_all_charsets = view->search_all_codepages; 
    33513358    view->search->is_case_sentitive = view->search_case; 
     3359    view->search->whole_words = view->whole_words; 
    33523360    view->search->search_fn = view_search_cmd_callback; 
    33533361    view->search->update_fn = view_search_update_cmd_callback; 
    33543362