mcviewer: refactoring of search.

(mcview_search_init): new function: initialization of search handler.
(mcview_search_deinit): new function: deinitialization of search handler.
(mcview_dialog_search): use mcview_search_init() and mcview_search_deinit().
(mcview_continue_search_cmd): use mcview_search_init().
(mcview_dialog_search): use mcview_search_deinit().
(mcview_search_options) move definition from dialogs.c to search.c.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-05-22 11:53:42 +03:00
parent 37b86b2781
commit 65ca3da3b2
5 changed files with 56 additions and 52 deletions

View File

@ -147,32 +147,14 @@ mcview_continue_search_cmd (WView * view)
history = g_list_first (history);
g_list_free_full (history, g_free);
#ifdef HAVE_CHARSET
view->search = mc_search_new (view->last_search_string, cp_source);
#else
view->search = mc_search_new (view->last_search_string, NULL);
#endif
view->search_nroff_seq = mcview_nroff_seq_new (view);
if (view->search == NULL)
if (!mcview_search_init (view))
{
/* if not... then ask for an expression */
MC_PTR_FREE (view->last_search_string);
mcview_search (view, TRUE);
}
else
{
view->search->search_type = mcview_search_options.type;
#ifdef HAVE_CHARSET
view->search->is_all_charsets = mcview_search_options.all_codepages;
#endif
view->search->is_case_sensitive = mcview_search_options.case_sens;
view->search->whole_words = mcview_search_options.whole_words;
view->search->search_fn = mcview_search_cmd_callback;
view->search->update_fn = mcview_search_update_cmd_callback;
mcview_search (view, FALSE);
}
}
else
{

View File

@ -52,14 +52,6 @@
/*** global variables ****************************************************************************/
mcview_search_options_t mcview_search_options = {
.type = MC_SEARCH_T_NORMAL,
.case_sens = FALSE,
.backwards = FALSE,
.whole_words = FALSE,
.all_codepages = FALSE
};
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
@ -133,30 +125,10 @@ mcview_dialog_search (WView * view)
}
#endif
g_free (view->last_search_string);
mcview_search_deinit (view);
view->last_search_string = exp;
mcview_nroff_seq_free (&view->search_nroff_seq);
mc_search_free (view->search);
#ifdef HAVE_CHARSET
view->search = mc_search_new (view->last_search_string, cp_source);
#else
view->search = mc_search_new (view->last_search_string, NULL);
#endif
view->search_nroff_seq = mcview_nroff_seq_new (view);
if (view->search != NULL)
{
view->search->search_type = mcview_search_options.type;
#ifdef HAVE_CHARSET
view->search->is_all_charsets = mcview_search_options.all_codepages;
#endif
view->search->is_case_sensitive = mcview_search_options.case_sens;
view->search->whole_words = mcview_search_options.whole_words;
view->search->search_fn = mcview_search_cmd_callback;
view->search->update_fn = mcview_search_update_cmd_callback;
}
return (view->search != NULL);
return mcview_search_init (view);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -342,6 +342,8 @@ int mcview_nroff_seq_next (mcview_nroff_t * nroff);
int mcview_nroff_seq_prev (mcview_nroff_t * nroff);
/* search.c: */
gboolean mcview_search_init (WView * view);
void mcview_search_deinit (WView * view);
mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
int *current_char);
mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset);

View File

@ -238,10 +238,9 @@ mcview_done (WView * view)
view->converter = str_cnv_from_term;
}
mc_search_free (view->search);
mcview_search_deinit (view);
view->search = NULL;
MC_PTR_FREE (view->last_search_string);
mcview_nroff_seq_free (&view->search_nroff_seq);
view->last_search_string = NULL;
mcview_hexedit_free_change_list (view);
if (mc_global.mc_run_mode == MC_RUN_VIEWER && view->dir != NULL)

View File

@ -37,6 +37,9 @@
#include "lib/global.h"
#include "lib/strutil.h"
#ifdef HAVE_CHARSET
#include "lib/charsets.h" /* cp_source */
#endif
#include "lib/widget.h"
#include "src/setup.h"
@ -45,6 +48,14 @@
/*** global variables ****************************************************************************/
mcview_search_options_t mcview_search_options = {
.type = MC_SEARCH_T_NORMAL,
.case_sens = FALSE,
.backwards = FALSE,
.whole_words = FALSE,
.all_codepages = FALSE
};
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
@ -198,6 +209,44 @@ mcview_search_show_result (WView * view, size_t match_len)
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
gboolean
mcview_search_init (WView * view)
{
#ifdef HAVE_CHARSET
view->search = mc_search_new (view->last_search_string, cp_source);
#else
view->search = mc_search_new (view->last_search_string, NULL);
#endif
view->search_nroff_seq = mcview_nroff_seq_new (view);
if (view->search == NULL)
return FALSE;
view->search->search_type = mcview_search_options.type;
#ifdef HAVE_CHARSET
view->search->is_all_charsets = mcview_search_options.all_codepages;
#endif
view->search->is_case_sensitive = mcview_search_options.case_sens;
view->search->whole_words = mcview_search_options.whole_words;
view->search->search_fn = mcview_search_cmd_callback;
view->search->update_fn = mcview_search_update_cmd_callback;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
void
mcview_search_deinit (WView * view)
{
mc_search_free (view->search);
g_free (view->last_search_string);
mcview_nroff_seq_free (&view->search_nroff_seq);
}
/* --------------------------------------------------------------------------------------------- */
mc_search_cbret_t
mcview_search_cmd_callback (const void *user_data, gsize char_offset, int *current_char)
{