mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Don't mix mc_search_cb_ret_t and int as result of search callback.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
2a5a5b4753
commit
bbf534e7d7
@ -13,7 +13,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
typedef int (*mc_search_fn) (const void *user_data, gsize char_offset);
|
||||
typedef int (*mc_search_fn) (const void *user_data, gsize char_offset, int *current_char);
|
||||
typedef int (*mc_update_fn) (const void *user_data, gsize char_offset);
|
||||
|
||||
#define MC_SEARCH__NUM_REPLACE_ARGS 64
|
||||
|
||||
@ -77,12 +78,11 @@ typedef struct mc_search_struct
|
||||
mc_search_fn search_fn;
|
||||
|
||||
/* function, used for updatin current search status. NULL if not used */
|
||||
mc_search_fn update_fn;
|
||||
mc_update_fn update_fn;
|
||||
|
||||
/* type of search */
|
||||
mc_search_type_t search_type;
|
||||
|
||||
|
||||
/* public output data */
|
||||
|
||||
/* some data for normal */
|
||||
|
@ -47,7 +47,7 @@ gchar *mc_search__recode_str (const char *, gsize, const char *, const char *, g
|
||||
|
||||
gchar *mc_search__get_one_symbol (const char *, const char *, gsize, gboolean *);
|
||||
|
||||
int mc_search__get_char (mc_search_t *, const void *, gsize);
|
||||
mc_search_cbret_t mc_search__get_char (mc_search_t *, const void *, gsize, int *);
|
||||
|
||||
GString *mc_search__tolower_case_str (const char *, const char *, gsize);
|
||||
|
||||
|
@ -137,15 +137,18 @@ mc_search__get_one_symbol (const char *charset, const char *str, gsize str_len,
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
mc_search__get_char (mc_search_t * lc_mc_search, const void *user_data, gsize current_pos)
|
||||
mc_search_cbret_t
|
||||
mc_search__get_char (mc_search_t * lc_mc_search, const void *user_data, gsize current_pos,
|
||||
int *current_char)
|
||||
{
|
||||
char *data;
|
||||
if (lc_mc_search->search_fn)
|
||||
return (lc_mc_search->search_fn) (user_data, current_pos);
|
||||
unsigned char *data;
|
||||
|
||||
data = (char *) user_data;
|
||||
return (int) (unsigned char) data[current_pos];
|
||||
if (lc_mc_search->search_fn != NULL)
|
||||
return lc_mc_search->search_fn (user_data, current_pos, current_char);
|
||||
|
||||
data = (unsigned char *) user_data;
|
||||
*current_char = (int) data[current_pos];
|
||||
return (*current_char == 0) ? MC_SEARCH_CB_ABORT : MC_SEARCH_CB_OK;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -792,8 +792,8 @@ gboolean
|
||||
mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
|
||||
gsize start_search, gsize end_search, gsize * found_len)
|
||||
{
|
||||
mc_search_cbret_t ret = MC_SEARCH_CB_ABORT;
|
||||
gsize current_pos, virtual_pos;
|
||||
int current_chr = 0;
|
||||
gint start_pos;
|
||||
gint end_pos;
|
||||
|
||||
@ -808,18 +808,20 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
|
||||
g_string_set_size (lc_mc_search->regex_buffer, 0);
|
||||
lc_mc_search->start_buffer = current_pos;
|
||||
|
||||
while (1)
|
||||
while (TRUE)
|
||||
{
|
||||
current_chr = mc_search__get_char (lc_mc_search, user_data, current_pos);
|
||||
if (current_chr == MC_SEARCH_CB_ABORT)
|
||||
int current_chr = '\n'; /* stop search symbol */
|
||||
|
||||
ret = mc_search__get_char (lc_mc_search, user_data, current_pos, ¤t_chr);
|
||||
if (ret == MC_SEARCH_CB_ABORT)
|
||||
break;
|
||||
|
||||
if (current_chr == MC_SEARCH_CB_INVALID)
|
||||
if (ret == MC_SEARCH_CB_INVALID)
|
||||
continue;
|
||||
|
||||
current_pos++;
|
||||
|
||||
if (current_chr == MC_SEARCH_CB_SKIP)
|
||||
if (ret == MC_SEARCH_CB_SKIP)
|
||||
continue;
|
||||
|
||||
virtual_pos++;
|
||||
@ -829,18 +831,15 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
|
||||
if ((char) current_chr == '\n' || virtual_pos > end_search)
|
||||
break;
|
||||
}
|
||||
|
||||
switch (mc_search__regex_found_cond (lc_mc_search, lc_mc_search->regex_buffer))
|
||||
{
|
||||
case COND__FOUND_OK:
|
||||
#ifdef SEARCH_TYPE_GLIB
|
||||
if (lc_mc_search->whole_words)
|
||||
{
|
||||
g_match_info_fetch_pos (lc_mc_search->regex_match_info, 2, &start_pos, &end_pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_match_info_fetch_pos (lc_mc_search->regex_match_info, 0, &start_pos, &end_pos);
|
||||
}
|
||||
#else /* SEARCH_TYPE_GLIB */
|
||||
if (lc_mc_search->whole_words)
|
||||
{
|
||||
@ -853,7 +852,7 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
|
||||
end_pos = lc_mc_search->iovector[1];
|
||||
}
|
||||
#endif /* SEARCH_TYPE_GLIB */
|
||||
if (found_len)
|
||||
if (found_len != NULL)
|
||||
*found_len = end_pos - start_pos;
|
||||
lc_mc_search->normal_offset = lc_mc_search->start_buffer + start_pos;
|
||||
return TRUE;
|
||||
@ -864,18 +863,20 @@ mc_search__run_regex (mc_search_t * lc_mc_search, const void *user_data,
|
||||
lc_mc_search->regex_buffer = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((lc_mc_search->update_fn != NULL) &&
|
||||
((lc_mc_search->update_fn) (user_data, current_pos) == MC_SEARCH_CB_ABORT))
|
||||
current_chr = MC_SEARCH_CB_ABORT;
|
||||
ret = MC_SEARCH_CB_ABORT;
|
||||
|
||||
if (current_chr == MC_SEARCH_CB_ABORT)
|
||||
if (ret == MC_SEARCH_CB_ABORT)
|
||||
break;
|
||||
}
|
||||
|
||||
g_string_free (lc_mc_search->regex_buffer, TRUE);
|
||||
lc_mc_search->regex_buffer = NULL;
|
||||
lc_mc_search->error = MC_SEARCH_E_NOTFOUND;
|
||||
|
||||
if (current_chr != MC_SEARCH_CB_ABORT)
|
||||
if (ret != MC_SEARCH_CB_ABORT)
|
||||
lc_mc_search->error_str = g_strdup (_(STR_E_NOTFOUND));
|
||||
else
|
||||
lc_mc_search->error_str = NULL;
|
||||
|
@ -239,7 +239,8 @@ void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
|
||||
void edit_push_markers (WEdit * edit);
|
||||
void edit_replace_cmd (WEdit * edit, int again);
|
||||
void edit_search_cmd (WEdit * edit, gboolean again);
|
||||
int edit_search_cmd_callback (const void *user_data, gsize char_offset);
|
||||
mc_search_cbret_t edit_search_cmd_callback (const void *user_data, gsize char_offset,
|
||||
int *current_char);
|
||||
void edit_complete_word_cmd (WEdit * edit);
|
||||
void edit_get_match_keyword_cmd (WEdit * edit);
|
||||
int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
|
||||
|
@ -2687,10 +2687,11 @@ edit_replace_cmd (WEdit * edit, int again)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
edit_search_cmd_callback (const void *user_data, gsize char_offset)
|
||||
mc_search_cbret_t
|
||||
edit_search_cmd_callback (const void *user_data, gsize char_offset, int *current_char)
|
||||
{
|
||||
return edit_get_byte ((WEdit *) user_data, (long) char_offset);
|
||||
*current_char = edit_get_byte ((WEdit *) user_data, (long) char_offset);
|
||||
return MC_SEARCH_CB_OK;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -321,7 +321,8 @@ int mcview_nroff_seq_prev (mcview_nroff_t *);
|
||||
void mcview_display_text (mcview_t *);
|
||||
|
||||
/* search.c: */
|
||||
int mcview_search_cmd_callback (const void *user_data, gsize char_offset);
|
||||
mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
|
||||
int *current_char);
|
||||
int mcview_search_update_cmd_callback (const void *, gsize);
|
||||
void mcview_do_search (mcview_t * view);
|
||||
|
||||
|
@ -158,19 +158,16 @@ mcview_search_show_result (mcview_t * view, Dlg_head ** d, size_t match_len)
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
mcview_search_cmd_callback (const void *user_data, gsize char_offset)
|
||||
mc_search_cbret_t
|
||||
mcview_search_cmd_callback (const void *user_data, gsize char_offset, int *current_char)
|
||||
{
|
||||
int lc_byte;
|
||||
mcview_t *view = (mcview_t *) user_data;
|
||||
|
||||
/* view_read_continue (view, &view->search_onechar_info); *//* AB:FIXME */
|
||||
if (!view->text_nroff_mode)
|
||||
{
|
||||
if (!mcview_get_byte (view, char_offset, &lc_byte))
|
||||
return MC_SEARCH_CB_OK;
|
||||
|
||||
return lc_byte;
|
||||
mcview_get_byte (view, char_offset, current_char);
|
||||
return MC_SEARCH_CB_OK;
|
||||
}
|
||||
|
||||
if (view->search_numNeedSkipChar != 0)
|
||||
@ -208,10 +205,10 @@ mcview_search_cmd_callback (const void *user_data, gsize char_offset)
|
||||
return MC_SEARCH_CB_INVALID;
|
||||
}
|
||||
|
||||
lc_byte = search_cb_char_buffer[search_cb_char_curr_index];
|
||||
*current_char = search_cb_char_buffer[search_cb_char_curr_index];
|
||||
search_cb_char_curr_index++;
|
||||
return (lc_byte != -1) ? (unsigned char) lc_byte : MC_SEARCH_CB_INVALID;
|
||||
|
||||
return (*current_char != -1) ? MC_SEARCH_CB_OK : MC_SEARCH_CB_INVALID;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user