mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Merge branch '3026_findfile_all_charsets'
* 3026_findfile_all_charsets: lib/search/search.c: cosmetics. Ticket #3026: Find File: "All charsets" options don't work.
This commit is contained in:
commit
fb7ee43d5b
@ -2,11 +2,12 @@
|
|||||||
Search text engine.
|
Search text engine.
|
||||||
Interface functions
|
Interface functions
|
||||||
|
|
||||||
Copyright (C) 2009, 2011
|
Copyright (C) 2009, 2011, 2013
|
||||||
The Free Software Foundation, Inc.
|
The Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by:
|
Written by:
|
||||||
Slava Zanko <slavazanko@gmail.com>, 2009.
|
Slava Zanko <slavazanko@gmail.com>, 2009
|
||||||
|
Andrew Borodin <aborodin@vmail.ru>, 2013
|
||||||
|
|
||||||
This file is part of the Midnight Commander.
|
This file is part of the Midnight Commander.
|
||||||
|
|
||||||
@ -61,8 +62,8 @@ mc_search__cond_struct_new (mc_search_t * lc_mc_search, const char *str,
|
|||||||
gsize str_len, const char *charset)
|
gsize str_len, const char *charset)
|
||||||
{
|
{
|
||||||
mc_search_cond_t *mc_search_cond;
|
mc_search_cond_t *mc_search_cond;
|
||||||
mc_search_cond = g_malloc0 (sizeof (mc_search_cond_t));
|
|
||||||
|
|
||||||
|
mc_search_cond = g_malloc0 (sizeof (mc_search_cond_t));
|
||||||
mc_search_cond->str = g_string_new_len (str, str_len);
|
mc_search_cond->str = g_string_new_len (str, str_len);
|
||||||
mc_search_cond->charset = g_strdup (charset);
|
mc_search_cond->charset = g_strdup (charset);
|
||||||
|
|
||||||
@ -116,10 +117,11 @@ static void
|
|||||||
mc_search__conditions_free (GPtrArray * array)
|
mc_search__conditions_free (GPtrArray * array)
|
||||||
{
|
{
|
||||||
gsize loop1;
|
gsize loop1;
|
||||||
mc_search_cond_t *lc_mc_search;
|
|
||||||
|
|
||||||
for (loop1 = 0; loop1 < array->len; loop1++)
|
for (loop1 = 0; loop1 < array->len; loop1++)
|
||||||
{
|
{
|
||||||
|
mc_search_cond_t *lc_mc_search;
|
||||||
|
|
||||||
lc_mc_search = (mc_search_cond_t *) g_ptr_array_index (array, loop1);
|
lc_mc_search = (mc_search_cond_t *) g_ptr_array_index (array, loop1);
|
||||||
mc_search__cond_struct_free (lc_mc_search);
|
mc_search__cond_struct_free (lc_mc_search);
|
||||||
}
|
}
|
||||||
@ -134,7 +136,8 @@ mc_search_t *
|
|||||||
mc_search_new (const gchar * original, gsize str_len)
|
mc_search_new (const gchar * original, gsize str_len)
|
||||||
{
|
{
|
||||||
mc_search_t *lc_mc_search;
|
mc_search_t *lc_mc_search;
|
||||||
if (!original)
|
|
||||||
|
if (original == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((gssize) str_len == -1)
|
if ((gssize) str_len == -1)
|
||||||
@ -161,11 +164,11 @@ mc_search_free (mc_search_t * lc_mc_search)
|
|||||||
g_free (lc_mc_search->original);
|
g_free (lc_mc_search->original);
|
||||||
g_free (lc_mc_search->error_str);
|
g_free (lc_mc_search->error_str);
|
||||||
|
|
||||||
if (lc_mc_search->conditions)
|
if (lc_mc_search->conditions != NULL)
|
||||||
mc_search__conditions_free (lc_mc_search->conditions);
|
mc_search__conditions_free (lc_mc_search->conditions);
|
||||||
|
|
||||||
#ifdef SEARCH_TYPE_GLIB
|
#ifdef SEARCH_TYPE_GLIB
|
||||||
if (lc_mc_search->regex_match_info)
|
if (lc_mc_search->regex_match_info != NULL)
|
||||||
g_match_info_free (lc_mc_search->regex_match_info);
|
g_match_info_free (lc_mc_search->regex_match_info);
|
||||||
#else /* SEARCH_TYPE_GLIB */
|
#else /* SEARCH_TYPE_GLIB */
|
||||||
g_free (lc_mc_search->regex_match_info);
|
g_free (lc_mc_search->regex_match_info);
|
||||||
@ -183,27 +186,30 @@ gboolean
|
|||||||
mc_search_prepare (mc_search_t * lc_mc_search)
|
mc_search_prepare (mc_search_t * lc_mc_search)
|
||||||
{
|
{
|
||||||
GPtrArray *ret;
|
GPtrArray *ret;
|
||||||
|
|
||||||
ret = g_ptr_array_new ();
|
ret = g_ptr_array_new ();
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
if (lc_mc_search->is_all_charsets)
|
if (lc_mc_search->is_all_charsets)
|
||||||
{
|
{
|
||||||
gsize loop1, recoded_str_len;
|
gsize loop1, recoded_str_len;
|
||||||
gchar *buffer;
|
gchar *buffer;
|
||||||
|
|
||||||
for (loop1 = 0; loop1 < codepages->len; loop1++)
|
for (loop1 = 0; loop1 < codepages->len; loop1++)
|
||||||
{
|
{
|
||||||
const char *id = ((codepage_desc *) g_ptr_array_index (codepages, loop1))->id;
|
const char *id = ((codepage_desc *) g_ptr_array_index (codepages, loop1))->id;
|
||||||
if (!g_ascii_strcasecmp (id, cp_source))
|
|
||||||
|
if (!g_ascii_strcasecmp (id, cp_display))
|
||||||
{
|
{
|
||||||
g_ptr_array_add (ret,
|
g_ptr_array_add (ret,
|
||||||
mc_search__cond_struct_new (lc_mc_search, lc_mc_search->original,
|
mc_search__cond_struct_new (lc_mc_search, lc_mc_search->original,
|
||||||
lc_mc_search->original_len,
|
lc_mc_search->original_len,
|
||||||
cp_source));
|
cp_display));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer =
|
buffer =
|
||||||
mc_search__recode_str (lc_mc_search->original, lc_mc_search->original_len,
|
mc_search__recode_str (lc_mc_search->original, lc_mc_search->original_len,
|
||||||
cp_source, id, &recoded_str_len);
|
cp_display, id, &recoded_str_len);
|
||||||
|
|
||||||
g_ptr_array_add (ret,
|
g_ptr_array_add (ret,
|
||||||
mc_search__cond_struct_new (lc_mc_search, buffer,
|
mc_search__cond_struct_new (lc_mc_search, buffer,
|
||||||
@ -214,16 +220,15 @@ mc_search_prepare (mc_search_t * lc_mc_search)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_ptr_array_add (ret,
|
g_ptr_array_add (ret,
|
||||||
(gpointer) mc_search__cond_struct_new (lc_mc_search,
|
mc_search__cond_struct_new (lc_mc_search,
|
||||||
lc_mc_search->original,
|
lc_mc_search->original,
|
||||||
lc_mc_search->original_len,
|
lc_mc_search->original_len, cp_display));
|
||||||
cp_source));
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
g_ptr_array_add (ret,
|
g_ptr_array_add (ret,
|
||||||
(gpointer) mc_search__cond_struct_new (lc_mc_search, lc_mc_search->original,
|
mc_search__cond_struct_new (lc_mc_search, lc_mc_search->original,
|
||||||
lc_mc_search->original_len,
|
lc_mc_search->original_len,
|
||||||
str_detect_termencoding ()));
|
str_detect_termencoding ()));
|
||||||
#endif
|
#endif
|
||||||
lc_mc_search->conditions = ret;
|
lc_mc_search->conditions = ret;
|
||||||
|
|
||||||
@ -247,7 +252,7 @@ mc_search_run (mc_search_t * lc_mc_search, const void *user_data,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#ifdef SEARCH_TYPE_GLIB
|
#ifdef SEARCH_TYPE_GLIB
|
||||||
if (lc_mc_search->regex_match_info)
|
if (lc_mc_search->regex_match_info != NULL)
|
||||||
{
|
{
|
||||||
g_match_info_free (lc_mc_search->regex_match_info);
|
g_match_info_free (lc_mc_search->regex_match_info);
|
||||||
lc_mc_search->regex_match_info = NULL;
|
lc_mc_search->regex_match_info = NULL;
|
||||||
@ -407,7 +412,7 @@ mc_search (const gchar * pattern, const gchar * str, mc_search_type_t type)
|
|||||||
int
|
int
|
||||||
mc_search_getstart_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
mc_search_getstart_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
||||||
{
|
{
|
||||||
if (!lc_mc_search)
|
if (lc_mc_search == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if (lc_mc_search->search_type == MC_SEARCH_T_NORMAL)
|
if (lc_mc_search->search_type == MC_SEARCH_T_NORMAL)
|
||||||
return 0;
|
return 0;
|
||||||
@ -415,6 +420,7 @@ mc_search_getstart_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
|||||||
{
|
{
|
||||||
gint start_pos;
|
gint start_pos;
|
||||||
gint end_pos;
|
gint end_pos;
|
||||||
|
|
||||||
g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &start_pos, &end_pos);
|
g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &start_pos, &end_pos);
|
||||||
return (int) start_pos;
|
return (int) start_pos;
|
||||||
}
|
}
|
||||||
@ -428,7 +434,7 @@ mc_search_getstart_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
|||||||
int
|
int
|
||||||
mc_search_getend_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
mc_search_getend_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
||||||
{
|
{
|
||||||
if (!lc_mc_search)
|
if (lc_mc_search == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if (lc_mc_search->search_type == MC_SEARCH_T_NORMAL)
|
if (lc_mc_search->search_type == MC_SEARCH_T_NORMAL)
|
||||||
return 0;
|
return 0;
|
||||||
@ -436,6 +442,7 @@ mc_search_getend_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
|||||||
{
|
{
|
||||||
gint start_pos;
|
gint start_pos;
|
||||||
gint end_pos;
|
gint end_pos;
|
||||||
|
|
||||||
g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &start_pos, &end_pos);
|
g_match_info_fetch_pos (lc_mc_search->regex_match_info, lc_index, &start_pos, &end_pos);
|
||||||
return (int) end_pos;
|
return (int) end_pos;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user