diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c
index 557964e..fabafc1 100644
a
|
b
|
set_basic_panel_listing_to (int panel_index, int listing_mode) |
541 | 541 | |
542 | 542 | gboolean |
543 | 543 | view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal, |
544 | | long start_line) |
| 544 | long start_line, off_t search_start, off_t search_end) |
545 | 545 | { |
546 | 546 | gboolean ret = TRUE; |
547 | 547 | |
… |
… |
view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gbool |
564 | 564 | mcview_default_nroff_flag = 0; |
565 | 565 | mcview_default_magic_flag = 0; |
566 | 566 | |
567 | | ret = mcview_viewer (NULL, filename_vpath, start_line); |
| 567 | ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end); |
568 | 568 | |
569 | 569 | if (changed_hex_mode && !mcview_altered_hex_mode) |
570 | 570 | mcview_default_hex_mode = 1; |
… |
… |
view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gbool |
587 | 587 | ret = (regex_command (filename_vpath, view_entry) == 0); |
588 | 588 | if (ret) |
589 | 589 | { |
590 | | ret = mcview_viewer (NULL, filename_vpath, start_line); |
| 590 | ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end); |
591 | 591 | dialog_switch_process_pending (); |
592 | 592 | } |
593 | 593 | } |
… |
… |
view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gbool |
623 | 623 | gboolean |
624 | 624 | view_file (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal) |
625 | 625 | { |
626 | | return view_file_at_line (filename_vpath, plain_view, internal, 0); |
| 626 | return view_file_at_line (filename_vpath, plain_view, internal, 0, 0, 0); |
627 | 627 | } |
628 | 628 | |
629 | 629 | |
… |
… |
view_filtered_cmd (void) |
687 | 687 | |
688 | 688 | if (command != NULL) |
689 | 689 | { |
690 | | mcview_viewer (command, NULL, 0); |
| 690 | mcview_viewer (command, NULL, 0, 0, 0); |
691 | 691 | g_free (command); |
692 | 692 | dialog_switch_process_pending (); |
693 | 693 | } |
diff --git a/src/filemanager/cmd.h b/src/filemanager/cmd.h
index 892f1ce..33f713d 100644
a
|
b
|
void smart_dirsize_cmd (void); |
44 | 44 | void single_dirsize_cmd (void); |
45 | 45 | void dirsizes_cmd (void); |
46 | 46 | gboolean view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, |
47 | | gboolean internal, long start_line); |
| 47 | gboolean internal, long start_line, off_t search_start, off_t search_end); |
48 | 48 | gboolean view_file (const vfs_path_t * filename_vpath, gboolean normal, gboolean internal); |
49 | 49 | void view_cmd (void); |
50 | 50 | void view_file_cmd (void); |
diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c
index 2fa9ae5..b8f7da3 100644
a
|
b
|
exec_extension_view (void *target, char *cmd, const vfs_path_t * filename_vpath, |
364 | 364 | changed_nroff_flag = 1; |
365 | 365 | |
366 | 366 | if (target == NULL) |
367 | | mcview_viewer (cmd, filename_vpath, start_line); |
| 367 | mcview_viewer (cmd, filename_vpath, start_line, 0, 0); |
368 | 368 | else |
369 | | mcview_load ((mcview_t *) target, cmd, vfs_path_as_str (filename_vpath), start_line); |
| 369 | mcview_load ((mcview_t *) target, cmd, vfs_path_as_str (filename_vpath), start_line, 0, 0); |
370 | 370 | |
371 | 371 | if (changed_hex_mode && !mcview_altered_hex_mode) |
372 | 372 | mcview_default_hex_mode = def_hex_mode; |
diff --git a/src/filemanager/find.c b/src/filemanager/find.c
index 1b829b3..9eb2b37 100644
a
|
b
|
typedef struct |
111 | 111 | char *ignore_dirs; |
112 | 112 | } find_file_options_t; |
113 | 113 | |
| 114 | typedef struct |
| 115 | { |
| 116 | char *dir; |
| 117 | gsize start; |
| 118 | gsize end; |
| 119 | } find_match_location_t; |
| 120 | |
114 | 121 | /*** file scope variables ************************************************************************/ |
115 | 122 | |
116 | 123 | /* button callbacks */ |
… |
… |
static struct timeval last_refresh; |
157 | 164 | static gboolean resuming; |
158 | 165 | static int last_line; |
159 | 166 | static int last_pos; |
| 167 | static off_t last_off; |
| 168 | static int last_i; |
160 | 169 | |
161 | 170 | static size_t ignore_count = 0; |
162 | 171 | |
… |
… |
found_num_update (void) |
364 | 373 | /* --------------------------------------------------------------------------------------------- */ |
365 | 374 | |
366 | 375 | static void |
367 | | get_list_info (char **file, char **dir) |
| 376 | get_list_info (char **file, char **dir, gsize *start, gsize *end) |
368 | 377 | { |
369 | | listbox_get_current (find_list, file, (void **) dir); |
| 378 | find_match_location_t *location = NULL; |
| 379 | listbox_get_current (find_list, file, (void **) &location); |
| 380 | if (location != NULL) |
| 381 | { |
| 382 | *dir = location->dir; |
| 383 | *start = location->start; |
| 384 | *end = location->end; |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | *dir = NULL; |
| 389 | } |
370 | 390 | } |
371 | 391 | |
372 | 392 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
clear_stack (void) |
825 | 845 | /* --------------------------------------------------------------------------------------------- */ |
826 | 846 | |
827 | 847 | static void |
828 | | insert_file (const char *dir, const char *file) |
| 848 | insert_file (const char *dir, const char *file, gsize start, gsize end) |
829 | 849 | { |
830 | 850 | char *tmp_name = NULL; |
831 | 851 | static char *dirname = NULL; |
| 852 | find_match_location_t *location; |
832 | 853 | |
833 | 854 | while (IS_PATH_SEP (dir[0]) && IS_PATH_SEP (dir[1])) |
834 | 855 | dir++; |
… |
… |
insert_file (const char *dir, const char *file) |
849 | 870 | } |
850 | 871 | |
851 | 872 | tmp_name = g_strdup_printf (" %s", file); |
852 | | add_to_list (tmp_name, dirname); |
| 873 | location = g_malloc (sizeof location); // TODO FIXME how to free this? |
| 874 | location->dir = dirname; |
| 875 | location->start = start; |
| 876 | location->end = end; |
| 877 | add_to_list (tmp_name, location); |
853 | 878 | g_free (tmp_name); |
854 | 879 | } |
855 | 880 | |
856 | 881 | /* --------------------------------------------------------------------------------------------- */ |
857 | 882 | |
858 | 883 | static void |
859 | | find_add_match (const char *dir, const char *file) |
| 884 | find_add_match (const char *dir, const char *file, gsize start, gsize end) |
860 | 885 | { |
861 | | insert_file (dir, file); |
| 886 | insert_file (dir, file, start, end); |
862 | 887 | |
863 | 888 | /* Don't scroll */ |
864 | 889 | if (matches == 0) |
… |
… |
search_content (WDialog * h, const char *directory, const char *filename) |
967 | 992 | int line = 1; |
968 | 993 | int pos = 0; |
969 | 994 | int n_read = 0; |
| 995 | off_t off = 0; /* file_fd's offset corresponding to strbuf[0] */ |
970 | 996 | gboolean found = FALSE; |
971 | 997 | gsize found_len; |
| 998 | gsize found_start; |
972 | 999 | char result[BUF_MEDIUM]; |
973 | 1000 | char *strbuf = NULL; /* buffer for fetched string */ |
974 | 1001 | int strbuf_size = 0; |
| 1002 | int i = -1; /* compensate for a newline we'll add when we first enter the loop */ |
975 | 1003 | |
976 | 1004 | if (resuming) |
977 | 1005 | { |
… |
… |
search_content (WDialog * h, const char *directory, const char *filename) |
979 | 1007 | resuming = FALSE; |
980 | 1008 | line = last_line; |
981 | 1009 | pos = last_pos; |
| 1010 | off = last_off; |
| 1011 | i = last_i; |
982 | 1012 | } |
983 | 1013 | |
984 | 1014 | while (!ret_val) |
985 | 1015 | { |
986 | 1016 | char ch = '\0'; |
987 | | int i = 0; |
| 1017 | off += i + 1; /* the previous line, plus a newline character */ |
| 1018 | i = 0; |
988 | 1019 | |
989 | 1020 | /* read to buffer and get line from there */ |
990 | 1021 | while (TRUE) |
… |
… |
search_content (WDialog * h, const char *directory, const char *filename) |
1002 | 1033 | { |
1003 | 1034 | /* skip possible leading zero(s) */ |
1004 | 1035 | if (i == 0) |
| 1036 | { |
| 1037 | off++; |
1005 | 1038 | continue; |
| 1039 | } |
1006 | 1040 | break; |
1007 | 1041 | } |
1008 | 1042 | |
… |
… |
search_content (WDialog * h, const char *directory, const char *filename) |
1045 | 1079 | } |
1046 | 1080 | |
1047 | 1081 | g_snprintf (result, sizeof (result), "%d:%s", line, filename); |
1048 | | find_add_match (directory, result); |
| 1082 | found_start = off + search_content_handle->normal_offset + 1; /* off by one ouch: ticket 3280 */ |
| 1083 | find_add_match (directory, result, found_start, found_start + found_len); |
1049 | 1084 | found = TRUE; |
1050 | 1085 | } |
1051 | 1086 | |
… |
… |
search_content (WDialog * h, const char *directory, const char *filename) |
1073 | 1108 | resuming = TRUE; |
1074 | 1109 | last_line = line; |
1075 | 1110 | last_pos = pos; |
| 1111 | last_off = off; |
| 1112 | last_i = i; |
1076 | 1113 | ret_val = TRUE; |
1077 | 1114 | break; |
1078 | 1115 | default: |
… |
… |
do_search (WDialog * h) |
1301 | 1338 | if (search_ok) |
1302 | 1339 | { |
1303 | 1340 | if (content_pattern == NULL) |
1304 | | find_add_match (directory, dp->d_name); |
| 1341 | find_add_match (directory, dp->d_name, 0, 0); |
1305 | 1342 | else if (search_content (h, directory, dp->d_name)) |
1306 | 1343 | return 1; |
1307 | 1344 | } |
… |
… |
init_find_vars (void) |
1336 | 1373 | /* --------------------------------------------------------------------------------------------- */ |
1337 | 1374 | |
1338 | 1375 | static void |
1339 | | find_do_view_edit (gboolean unparsed_view, gboolean edit, char *dir, char *file) |
| 1376 | find_do_view_edit (gboolean unparsed_view, gboolean edit, char *dir, char *file, off_t search_start, off_t search_end) |
1340 | 1377 | { |
1341 | 1378 | char *fullname = NULL; |
1342 | 1379 | const char *filename = NULL; |
… |
… |
find_do_view_edit (gboolean unparsed_view, gboolean edit, char *dir, char *file) |
1358 | 1395 | if (edit) |
1359 | 1396 | edit_file_at_line (fullname_vpath, use_internal_edit != 0, line); |
1360 | 1397 | else |
1361 | | view_file_at_line (fullname_vpath, unparsed_view, use_internal_view != 0, line); |
| 1398 | view_file_at_line (fullname_vpath, unparsed_view, use_internal_view != 0, line, search_start, search_end); |
1362 | 1399 | vfs_path_free (fullname_vpath); |
1363 | 1400 | g_free (fullname); |
1364 | 1401 | } |
… |
… |
find_do_view_edit (gboolean unparsed_view, gboolean edit, char *dir, char *file) |
1368 | 1405 | static cb_ret_t |
1369 | 1406 | view_edit_currently_selected_file (gboolean unparsed_view, gboolean edit) |
1370 | 1407 | { |
1371 | | char *dir = NULL; |
1372 | 1408 | char *text = NULL; |
| 1409 | find_match_location_t *location; |
1373 | 1410 | |
1374 | | listbox_get_current (find_list, &text, (void **) &dir); |
| 1411 | listbox_get_current (find_list, &text, (void **) &location); |
1375 | 1412 | |
1376 | | if ((text == NULL) || (dir == NULL)) |
| 1413 | if ((text == NULL) || (location == NULL) || (location->dir == NULL)) |
1377 | 1414 | return MSG_NOT_HANDLED; |
1378 | 1415 | |
1379 | | find_do_view_edit (unparsed_view, edit, dir, text); |
| 1416 | find_do_view_edit (unparsed_view, edit, location->dir, text, location->start, location->end); |
1380 | 1417 | return MSG_HANDLED; |
1381 | 1418 | } |
1382 | 1419 | |
… |
… |
do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs, |
1628 | 1665 | { |
1629 | 1666 | int return_value = 0; |
1630 | 1667 | char *dir_tmp = NULL, *file_tmp = NULL; |
| 1668 | gsize start, len; |
1631 | 1669 | |
1632 | 1670 | setup_gui (); |
1633 | 1671 | |
… |
… |
do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs, |
1647 | 1685 | /* Clear variables */ |
1648 | 1686 | init_find_vars (); |
1649 | 1687 | |
1650 | | get_list_info (&file_tmp, &dir_tmp); |
| 1688 | get_list_info (&file_tmp, &dir_tmp, &start, &len); |
1651 | 1689 | |
1652 | 1690 | if (dir_tmp) |
1653 | 1691 | *dirname = g_strdup (dir_tmp); |
… |
… |
do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs, |
1670 | 1708 | { |
1671 | 1709 | const char *lc_filename = NULL; |
1672 | 1710 | WLEntry *le = LENTRY (entry->data); |
| 1711 | find_match_location_t *location = le->data; |
1673 | 1712 | char *p; |
1674 | 1713 | |
1675 | | if ((le->text == NULL) || (le->data == NULL)) |
| 1714 | if ((le->text == NULL) || (location == NULL) || (location->dir == NULL)) |
1676 | 1715 | continue; |
1677 | 1716 | |
1678 | 1717 | if (content_pattern != NULL) |
… |
… |
do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs, |
1680 | 1719 | else |
1681 | 1720 | lc_filename = le->text + 4; |
1682 | 1721 | |
1683 | | name = mc_build_filename (le->data, lc_filename, (char *) NULL); |
| 1722 | name = mc_build_filename (location->dir, lc_filename, (char *) NULL); |
1684 | 1723 | /* skip initial start dir */ |
1685 | 1724 | if (start_dir_len < 0) |
1686 | 1725 | p = name; |
diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c
index adc068e..bf6c26a 100644
a
|
b
|
set_display_type (int num, panel_view_mode_t type) |
1020 | 1020 | else |
1021 | 1021 | file_name = ""; |
1022 | 1022 | |
1023 | | mcview_load ((struct mcview_struct *) new_widget, 0, file_name, 0); |
| 1023 | mcview_load ((struct mcview_struct *) new_widget, 0, file_name, 0, 0, 0); |
1024 | 1024 | break; |
1025 | 1025 | |
1026 | 1026 | default: |
diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c
index fc593b5..2d7d5f8 100644
a
|
b
|
execute_menu_command (WEdit * edit_widget, const char *commands, gboolean show_p |
550 | 550 | mc_chmod (file_name_vpath, S_IRWXU); |
551 | 551 | if (run_view) |
552 | 552 | { |
553 | | mcview_viewer (vfs_path_as_str (file_name_vpath), NULL, 0); |
| 553 | mcview_viewer (vfs_path_as_str (file_name_vpath), NULL, 0, 0, 0); |
554 | 554 | dialog_switch_process_pending (); |
555 | 555 | } |
556 | 556 | else |
diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c
index 20fdbf1..492dcfa 100644
a
|
b
|
mcview_hook (void *v) |
210 | 210 | |
211 | 211 | mcview_done (view); |
212 | 212 | mcview_init (view); |
213 | | mcview_load (view, 0, panel->dir.list[panel->selected].fname, 0); |
| 213 | mcview_load (view, 0, panel->dir.list[panel->selected].fname, 0, 0, 0); |
214 | 214 | mcview_display (view); |
215 | 215 | } |
216 | 216 | |
… |
… |
mcview_load_next_prev (mcview_t * view, int direction) |
369 | 369 | mcview_remove_ext_script (view); |
370 | 370 | mcview_init (view); |
371 | 371 | if (regex_command_for (view, vfile, "View", &ext_script) == 0) |
372 | | mcview_load (view, NULL, vfs_path_as_str (vfile), 0); |
| 372 | mcview_load (view, NULL, vfs_path_as_str (vfile), 0, 0, 0); |
373 | 373 | vfs_path_free (vfile); |
374 | 374 | view->dir = dir; |
375 | 375 | view->dir_idx = dir_idx; |
diff --git a/src/viewer/lib.c b/src/viewer/lib.c
index 2528c10..4d72f60 100644
a
|
b
|
mcview_toggle_magic_mode (mcview_t * view) |
91 | 91 | view->dir_idx = NULL; |
92 | 92 | mcview_done (view); |
93 | 93 | mcview_init (view); |
94 | | mcview_load (view, command, filename, 0); |
| 94 | mcview_load (view, command, filename, 0, 0, 0); |
95 | 95 | view->dir = dir; |
96 | 96 | view->dir_idx = dir_idx; |
97 | 97 | g_free (filename); |
diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c
index a34099b..4dffd11 100644
a
|
b
|
mcview_new (int y, int x, int lines, int cols, gboolean is_panel) |
232 | 232 | /** Real view only */ |
233 | 233 | |
234 | 234 | gboolean |
235 | | mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line) |
| 235 | mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line, off_t search_start, off_t search_end) |
236 | 236 | { |
237 | 237 | gboolean succeeded; |
238 | 238 | mcview_t *lc_mcview; |
… |
… |
mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_lin |
249 | 249 | |
250 | 250 | view_dlg->get_title = mcview_get_title; |
251 | 251 | |
252 | | succeeded = mcview_load (lc_mcview, command, vfs_path_as_str (file_vpath), start_line); |
| 252 | succeeded = mcview_load (lc_mcview, command, vfs_path_as_str (file_vpath), start_line, search_start, search_end); |
253 | 253 | |
254 | 254 | if (succeeded) |
255 | 255 | dlg_run (view_dlg); |
… |
… |
mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_lin |
267 | 267 | /* --------------------------------------------------------------------------------------------- */ |
268 | 268 | |
269 | 269 | gboolean |
270 | | mcview_load (mcview_t * view, const char *command, const char *file, int start_line) |
| 270 | mcview_load (mcview_t * view, const char *command, const char *file, int start_line, off_t search_start, off_t search_end) |
271 | 271 | { |
272 | 272 | gboolean retval = FALSE; |
273 | 273 | vfs_path_t *vpath = NULL; |
… |
… |
mcview_load (mcview_t * view, const char *command, const char *file, int start_l |
409 | 409 | mcview_state_machine_init (&view->dpy_state_top, 0); |
410 | 410 | view->dpy_wrap_dirty = FALSE; |
411 | 411 | view->force_max = -1; |
412 | | view->search_start = 0; |
413 | | view->search_end = 0; |
414 | 412 | view->dpy_text_column = 0; |
415 | 413 | |
416 | 414 | mcview_compute_areas (view); |
… |
… |
mcview_load (mcview_t * view, const char *command, const char *file, int start_l |
441 | 439 | else if (start_line > 0) |
442 | 440 | mcview_moveto (view, start_line - 1, 0); |
443 | 441 | |
| 442 | view->search_start = search_start; |
| 443 | view->search_end = search_end; |
444 | 444 | view->hexedit_lownibble = FALSE; |
445 | 445 | view->hexview_in_text = FALSE; |
446 | 446 | view->change_list = NULL; |
diff --git a/src/viewer/mcviewer.h b/src/viewer/mcviewer.h
index e68642b..89c4073 100644
a
|
b
|
extern mcview_t *mcview_new (int y, int x, int lines, int cols, gboolean is_pane |
43 | 43 | /* Shows {file} or the output of {command} in the internal viewer, |
44 | 44 | * starting in line {start_line}. |
45 | 45 | */ |
46 | | extern gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line); |
| 46 | extern gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line, |
| 47 | off_t search_start, off_t search_end); |
47 | 48 | |
48 | 49 | extern gboolean mcview_load (mcview_t * view, const char *command, const char *file, |
49 | | int start_line); |
| 50 | int start_line, off_t search_start, off_t search_end); |
50 | 51 | |
51 | 52 | /*** inline functions ****************************************************************************/ |
52 | 53 | #endif /* MC__VIEWER_H */ |