diff -Naur mc-4.7.0-pre1~/edit/edit-widget.h mc-4.7.0-pre1/edit/edit-widget.h
old
|
new
|
|
62 | 62 | int replace_mode; |
63 | 63 | int replace_backwards; |
64 | 64 | int replace_case; |
| 65 | int whole_words; |
65 | 66 | int all_codepages; |
66 | 67 | |
67 | 68 | long search_start; /* First character to start searching from */ |
diff -Naur mc-4.7.0-pre1~/edit/editcmd.c mc-4.7.0-pre1/edit/editcmd.c
old
|
new
|
|
1280 | 1280 | gsize search_end; |
1281 | 1281 | |
1282 | 1282 | if (edit->replace_backwards) { |
1283 | | search_end = edit->curs1-1; |
| 1283 | search_end = edit->last_byte; |
1284 | 1284 | 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 ) |
1288 | 1289 | { |
1289 | 1290 | return TRUE; |
1290 | 1291 | } |
… |
… |
|
1407 | 1408 | edit->search->search_type = edit->search_type; |
1408 | 1409 | edit->search->is_all_charsets = edit->all_codepages; |
1409 | 1410 | edit->search->is_case_sentitive = edit->replace_case; |
| 1411 | edit->search->whole_words = edit->whole_words; |
1410 | 1412 | edit->search->search_fn = edit_search_cmd_callback; |
1411 | 1413 | } |
1412 | 1414 | |
… |
… |
|
1536 | 1538 | |
1537 | 1539 | void edit_search_cmd (WEdit * edit, int again) |
1538 | 1540 | { |
| 1541 | static char *saved1 = NULL; /* saved default[123] */ |
1539 | 1542 | char *search_string = NULL, *search_string_dup = NULL; |
1540 | 1543 | |
1541 | 1544 | gsize len = 0; |
… |
… |
|
1545 | 1548 | |
1546 | 1549 | if (edit->search != NULL) |
1547 | 1550 | 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); |
1548 | 1553 | |
1549 | 1554 | if (!again) |
1550 | 1555 | { |
… |
… |
|
1562 | 1567 | g_string_free (tmp, FALSE); |
1563 | 1568 | } |
1564 | 1569 | #endif /* HAVE_CHARSET */ |
1565 | | editcmd_dialog_search_show (edit, &search_string); |
| 1570 | editcmd_dialog_search_show (edit, &search_string, &search_create_bookmark); |
1566 | 1571 | #ifdef HAVE_CHARSET |
1567 | 1572 | if (search_string && *search_string) |
1568 | 1573 | { |
… |
… |
|
1591 | 1596 | mc_search_free(edit->search); |
1592 | 1597 | edit->search = NULL; |
1593 | 1598 | } |
| 1599 | |
| 1600 | g_free (saved1), saved1 = g_strdup (search_string); |
1594 | 1601 | } |
1595 | 1602 | |
1596 | 1603 | if (!edit->search) |
… |
… |
|
1604 | 1611 | edit->search->search_type = edit->search_type; |
1605 | 1612 | edit->search->is_all_charsets = edit->all_codepages; |
1606 | 1613 | edit->search->is_case_sentitive = edit->replace_case; |
| 1614 | edit->search->whole_words = edit->whole_words; |
1607 | 1615 | edit->search->search_fn = edit_search_cmd_callback; |
1608 | 1616 | } |
1609 | 1617 | |
diff -Naur mc-4.7.0-pre1~/edit/editcmd_dialogs.c mc-4.7.0-pre1/edit/editcmd_dialogs.c
old
|
new
|
|
49 | 49 | /*** file scope macro definitions **************************************/ |
50 | 50 | |
51 | 51 | #define SEARCH_DLG_WIDTH 58 |
52 | | #define SEARCH_DLG_MIN_HEIGHT 11 |
| 52 | #define SEARCH_DLG_MIN_HEIGHT 12 |
53 | 53 | #define SEARCH_DLG_HEIGHT_SUPPLY 3 |
54 | 54 | |
55 | 55 | #define REPLACE_DLG_WIDTH 58 |
… |
… |
|
84 | 84 | { |
85 | 85 | int treplace_backwards = edit->replace_backwards; |
86 | 86 | int treplace_case = edit->replace_case; |
| 87 | int twhole_words = edit->whole_words; |
87 | 88 | int tall_codepages = edit->all_codepages; |
88 | 89 | mc_search_type_t ttype_of_search = edit->search_type; |
89 | 90 | int dialog_result; |
… |
… |
|
101 | 102 | 0, 0, NULL, NULL, NULL}, |
102 | 103 | |
103 | 104 | #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, |
105 | 106 | &tall_codepages, 0, NULL, NULL, NULL}, |
106 | 107 | #endif |
107 | 108 | |
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, |
109 | 110 | &treplace_backwards, 0, NULL, NULL, NULL}, |
110 | 111 | |
| 112 | {quick_checkbox, 33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Whole words"), 0, 0, |
| 113 | &twhole_words, 0, NULL, NULL, NULL}, |
| 114 | |
111 | 115 | {quick_checkbox, 33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT, N_("case &Sensitive"), 0, 0, |
112 | 116 | &treplace_case, 0, NULL, NULL, NULL}, |
113 | 117 | |
… |
… |
|
153 | 157 | edit->all_codepages = tall_codepages; |
154 | 158 | edit->replace_backwards = treplace_backwards; |
155 | 159 | edit->replace_case = treplace_case; |
| 160 | edit->whole_words = twhole_words; |
156 | 161 | return; |
157 | 162 | } else { |
158 | 163 | *replace_text = NULL; |
… |
… |
|
164 | 169 | /* --------------------------------------------------------------------------------------------- */ |
165 | 170 | |
166 | 171 | void |
167 | | editcmd_dialog_search_show (WEdit * edit, char **search_text) |
| 172 | editcmd_dialog_search_show (WEdit * edit, char **search_text, int *psearch_bookmarks) |
168 | 173 | { |
169 | 174 | int tsearch_case = edit->replace_case; |
| 175 | int twhole_words = edit->whole_words; |
170 | 176 | int tsearch_backwards = edit->replace_backwards; |
171 | 177 | int tall_codepages = edit->all_codepages; |
172 | 178 | mc_search_type_t ttype_of_search = edit->search_type; |
… |
… |
|
175 | 181 | |
176 | 182 | |
177 | 183 | 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, |
179 | 185 | 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, |
181 | 187 | 0, NULL, NULL, NULL}, |
182 | 188 | |
183 | 189 | #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, |
185 | 199 | &tall_codepages, 0, NULL, NULL, NULL}, |
186 | 200 | #endif |
187 | 201 | |
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, |
189 | 203 | &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}, |
190 | 206 | {quick_checkbox, 33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), 0, 0, |
191 | 207 | &tsearch_case, 0, NULL, NULL, NULL}, |
192 | 208 | |
… |
… |
|
213 | 229 | edit->replace_backwards = tsearch_backwards; |
214 | 230 | edit->all_codepages = tall_codepages; |
215 | 231 | edit->replace_case = tsearch_case; |
| 232 | edit->whole_words = twhole_words; |
216 | 233 | } else { |
217 | 234 | *search_text = NULL; |
218 | 235 | } |
diff -Naur mc-4.7.0-pre1~/edit/editcmd_dialogs.h mc-4.7.0-pre1/edit/editcmd_dialogs.h
old
|
new
|
|
24 | 24 | |
25 | 25 | void editcmd_dialog_replace_show (WEdit *, const char *, const char *, char **, char **); |
26 | 26 | |
27 | | void editcmd_dialog_search_show (WEdit *, char **); |
| 27 | void editcmd_dialog_search_show (WEdit *, char **, int *); |
28 | 28 | |
29 | 29 | int editcmd_dialog_raw_key_query (const char *, const char *, int); |
30 | 30 | |
diff -Naur mc-4.7.0-pre1~/src/find.c mc-4.7.0-pre1/src/find.c
old
|
new
|
|
89 | 89 | static WCheck *file_case_sens; /* "case sensitive" checkbox */ |
90 | 90 | static WCheck *find_regex_cbox; /* [x] find regular expression */ |
91 | 91 | static WCheck *content_case_sens; /* "case sensitive" checkbox */ |
| 92 | static WCheck *content_whole_words_cbox;/* "whole words" checkbox */ |
| 93 | static WCheck *content_first_only_cbox; /* "first only" checkbox */ |
92 | 94 | |
93 | 95 | static int running = 0; /* nice flag */ |
94 | 96 | static char *find_pattern = NULL; /* Pattern to search */ |
… |
… |
|
148 | 150 | static gboolean content_regexp_flag = FALSE; |
149 | 151 | static gboolean content_all_charsets_flag = FALSE; |
150 | 152 | static gboolean content_case_sensitive = TRUE; |
| 153 | static gboolean content_whole_words = FALSE; |
| 154 | static gboolean content_first_only = FALSE; |
151 | 155 | |
152 | 156 | static int find_recursively = 1; |
153 | 157 | |
… |
… |
|
261 | 265 | |
262 | 266 | static const char *file_case_label = N_("Cas&e sensitive"); |
263 | 267 | 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"); |
264 | 270 | static const char *file_recurs_label = N_("&Find recursively"); |
265 | 271 | static const char *file_skip_hidden_label = N_("S&kip hidden"); |
266 | 272 | static const char *file_all_charsets_label = N_("&All charsets"); |
… |
… |
|
327 | 333 | button_new (FIND_Y - 3, FIND_X/4 - b0/2, B_ENTER, DEFPUSH_BUTTON, buts[0], 0)); |
328 | 334 | |
329 | 335 | #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, |
331 | 337 | content_all_charsets_flag, content_all_charsets_label); |
332 | 338 | add_widget (find_dlg, content_all_charsets_cbox); |
333 | 339 | #endif |
334 | 340 | |
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); |
336 | 345 | add_widget (find_dlg, find_regex_cbox); |
337 | 346 | |
| 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 | |
338 | 350 | content_case_sens = check_new (7, FIND_X / 2 + 1, content_case_sensitive, content_case_label); |
339 | 351 | add_widget (find_dlg, content_case_sens); |
340 | 352 | |
… |
… |
|
385 | 397 | content_all_charsets_flag = content_all_charsets_cbox->state & C_BOOL; |
386 | 398 | #endif |
387 | 399 | 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; |
388 | 402 | content_regexp_flag = find_regex_cbox->state & C_BOOL; |
389 | 403 | file_pattern_flag = file_pattern_cbox->state & C_BOOL; |
390 | 404 | file_case_sensitive = file_case_sens->state & C_BOOL; |
… |
… |
|
418 | 432 | content_all_charsets_flag = content_all_charsets_cbox->state & C_BOOL; |
419 | 433 | #endif |
420 | 434 | 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; |
421 | 437 | content_regexp_flag = find_regex_cbox->state & C_BOOL; |
422 | 438 | find_recursively = recursively_cbox->state & C_BOOL; |
423 | 439 | file_pattern_flag = file_pattern_cbox->state & C_BOOL; |
… |
… |
|
680 | 696 | find_add_match (directory, fnd_info); |
681 | 697 | g_free (fnd_info); |
682 | 698 | found = TRUE; |
| 699 | if (content_first_only) { |
| 700 | g_free (p); |
| 701 | ret_val = 0; |
| 702 | break; |
| 703 | } |
683 | 704 | } |
684 | 705 | } |
685 | 706 | if (has_newline){ |
… |
… |
|
741 | 762 | { |
742 | 763 | search_content_handle->search_type = (content_regexp_flag) ? MC_SEARCH_T_REGEX : MC_SEARCH_T_NORMAL; |
743 | 764 | search_content_handle->is_case_sentitive = content_case_sensitive; |
| 765 | search_content_handle->whole_words = content_whole_words; |
744 | 766 | search_content_handle->is_all_charsets = content_all_charsets_flag; |
745 | 767 | } |
746 | 768 | search_file_handle = mc_search_new(find_pattern, -1); |
diff -Naur mc-4.7.0-pre1~/src/search/normal.c mc-4.7.0-pre1/src/search/normal.c
old
|
new
|
|
91 | 91 | mc_search__normal_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len); |
92 | 92 | |
93 | 93 | 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 | } |
94 | 99 | mc_search_cond->str = tmp; |
95 | 100 | |
96 | 101 | mc_search__cond_struct_new_init_regex (charset, mc_search, mc_search_cond); |
diff -Naur mc-4.7.0-pre1~/src/search/regex.c mc-4.7.0-pre1/src/search/regex.c
old
|
new
|
|
63 | 63 | const char *special_chars[] = { |
64 | 64 | "\\s", "\\S", |
65 | 65 | "\\d", "\\D", |
66 | | "\\B", "\\B", |
| 66 | "\\b", "\\B", |
67 | 67 | "\\w", "\\W", |
68 | 68 | "\\t", "\\n", |
69 | 69 | "\\r", "\\f", |
diff -Naur mc-4.7.0-pre1~/src/search/search.h mc-4.7.0-pre1/src/search/search.h
old
|
new
|
|
63 | 63 | /* search entire string (from begin to end). Used only with GLOB search type */ |
64 | 64 | gboolean is_entire_line; |
65 | 65 | |
| 66 | /* search entire string (from begin to end). Used only with NORMAL search type */ |
| 67 | gboolean whole_words; |
| 68 | |
66 | 69 | /* function, used for getting data. NULL if not used */ |
67 | 70 | mc_search_fn search_fn; |
68 | 71 | |
diff -Naur mc-4.7.0-pre1~/src/view.c mc-4.7.0-pre1/src/view.c
old
|
new
|
|
261 | 261 | mc_search_type_t search_type; |
262 | 262 | gboolean search_all_codepages; |
263 | 263 | gboolean search_case; |
| 264 | gboolean whole_words; |
264 | 265 | gboolean search_backwards; |
265 | 266 | |
266 | 267 | int search_numNeedSkipChar; |
… |
… |
|
3146 | 3147 | if (view->search_backwards) { |
3147 | 3148 | search_end = view_get_filesize (view); |
3148 | 3149 | 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)) |
3150 | 3151 | search_end = search_start + view->search->original_len; |
3151 | 3152 | |
3152 | 3153 | view_read_start (view, &view->search_onechar_info, search_start); |
3153 | 3154 | |
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 ) |
3155 | 3157 | return TRUE; |
3156 | 3158 | |
3157 | 3159 | search_start--; |
… |
… |
|
3268 | 3270 | int ttype_of_search = (int) view->search_type; |
3269 | 3271 | int tall_codepages = (int) view->search_all_codepages; |
3270 | 3272 | int tsearch_case = (int) view->search_case; |
| 3273 | int twhole_words = (int) view->whole_words; |
3271 | 3274 | int tsearch_backwards = (int) view->search_backwards; |
3272 | 3275 | |
3273 | 3276 | gchar **list_of_types = mc_search_get_types_strings_array(); |
… |
… |
|
3282 | 3285 | 0, 0, NULL, NULL, NULL}, |
3283 | 3286 | |
3284 | 3287 | #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, |
3286 | 3289 | &tall_codepages, 0, NULL, NULL, NULL}, |
3287 | 3290 | #endif |
3288 | 3291 | |
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, |
3290 | 3293 | N_("&Backwards"), 0, 0, &tsearch_backwards, 0, NULL, NULL, NULL}, |
3291 | 3294 | |
| 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 | |
3292 | 3298 | {quick_checkbox, SEARCH_DLG_WIDTH/2 + 3, SEARCH_DLG_WIDTH, 4, SEARCH_DLG_HEIGHT, N_("case &Sensitive"), 0, 0, |
3293 | 3299 | &tsearch_case, 0, NULL, NULL, NULL}, |
3294 | 3300 | |
… |
… |
|
3321 | 3327 | |
3322 | 3328 | view->search_all_codepages = (gboolean) tall_codepages; |
3323 | 3329 | view->search_case = (gboolean) tsearch_case; |
| 3330 | view->whole_words = (gboolean) twhole_words; |
3324 | 3331 | |
3325 | 3332 | if (exp == NULL || exp[0] == '\0') |
3326 | 3333 | goto cleanup; |
… |
… |
|
3349 | 3356 | view->search->search_type = view->search_type; |
3350 | 3357 | view->search->is_all_charsets = view->search_all_codepages; |
3351 | 3358 | view->search->is_case_sentitive = view->search_case; |
| 3359 | view->search->whole_words = view->whole_words; |
3352 | 3360 | view->search->search_fn = view_search_cmd_callback; |
3353 | 3361 | view->search->update_fn = view_search_update_cmd_callback; |
3354 | 3362 | |