mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
src/editor/spell.c: refactoring: use GPtrArray instead of GArray for string arrays.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
583adea34e
commit
2e78166c23
@ -360,7 +360,7 @@ aspell_clean (void)
|
||||
*/
|
||||
|
||||
unsigned int
|
||||
aspell_get_lang_list (GArray * lang_list)
|
||||
aspell_get_lang_list (GPtrArray * lang_list)
|
||||
{
|
||||
AspellDictInfoList *dlist;
|
||||
AspellDictInfoEnumeration *elem;
|
||||
@ -375,16 +375,11 @@ aspell_get_lang_list (GArray * lang_list)
|
||||
elem = mc_aspell_dict_info_list_elements (dlist);
|
||||
|
||||
while ((entry = mc_aspell_dict_info_enumeration_next (elem)) != NULL)
|
||||
{
|
||||
if (entry->name != NULL)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
tmp = g_strdup (entry->name);
|
||||
g_array_append_val (lang_list, tmp);
|
||||
g_ptr_array_add (lang_list, g_strdup (entry->name));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
mc_delete_aspell_dict_info_enumeration (elem);
|
||||
|
||||
@ -399,21 +394,10 @@ aspell_get_lang_list (GArray * lang_list)
|
||||
*/
|
||||
|
||||
void
|
||||
aspell_array_clean (GArray * array)
|
||||
aspell_array_clean (GPtrArray * array)
|
||||
{
|
||||
if (array != NULL)
|
||||
{
|
||||
guint i = 0;
|
||||
|
||||
for (i = 0; i < array->len; ++i)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
tmp = g_array_index (array, char *, i);
|
||||
g_free (tmp);
|
||||
}
|
||||
g_array_free (array, TRUE);
|
||||
}
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -510,7 +494,7 @@ aspell_check (const char *word, const int word_size)
|
||||
*/
|
||||
|
||||
unsigned int
|
||||
aspell_suggest (GArray * suggest, const char *word, const int word_size)
|
||||
aspell_suggest (GPtrArray * suggest, const char *word, const int word_size)
|
||||
{
|
||||
unsigned int size = 0;
|
||||
|
||||
@ -531,9 +515,9 @@ aspell_suggest (GArray * suggest, const char *word, const int word_size)
|
||||
{
|
||||
const char *cur_sugg_word;
|
||||
|
||||
cur_sugg_word = g_strdup (mc_aspell_string_enumeration_next (elements));
|
||||
cur_sugg_word = mc_aspell_string_enumeration_next (elements);
|
||||
if (cur_sugg_word != NULL)
|
||||
g_array_append_val (suggest, cur_sugg_word);
|
||||
g_ptr_array_add (suggest, g_strdup (cur_sugg_word));
|
||||
}
|
||||
|
||||
mc_delete_aspell_string_enumeration (elements);
|
||||
@ -603,11 +587,11 @@ edit_suggest_current_word (WEdit * edit)
|
||||
{
|
||||
if (!aspell_check (match_word->str, (int) word_len))
|
||||
{
|
||||
GArray *suggest;
|
||||
GPtrArray *suggest;
|
||||
unsigned int res;
|
||||
guint i;
|
||||
|
||||
suggest = g_array_new (TRUE, FALSE, sizeof (char *));
|
||||
suggest = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
res = aspell_suggest (suggest, match_word->str, (int) word_len);
|
||||
if (res != 0)
|
||||
@ -651,14 +635,7 @@ edit_suggest_current_word (WEdit * edit)
|
||||
aspell_add_to_dict (match_word->str, (int) word_len);
|
||||
}
|
||||
|
||||
for (i = 0; i < suggest->len; i++)
|
||||
{
|
||||
char *cur_sugg_word;
|
||||
|
||||
cur_sugg_word = g_array_index (suggest, char *, i);
|
||||
g_free (cur_sugg_word);
|
||||
}
|
||||
g_array_free (suggest, TRUE);
|
||||
g_ptr_array_free (suggest, TRUE);
|
||||
edit->found_start = 0;
|
||||
edit->found_len = 0;
|
||||
}
|
||||
@ -706,9 +683,9 @@ edit_spellcheck_file (WEdit * edit)
|
||||
void
|
||||
edit_set_spell_lang (void)
|
||||
{
|
||||
GArray *lang_list;
|
||||
GPtrArray *lang_list;
|
||||
|
||||
lang_list = g_array_new (TRUE, FALSE, sizeof (char *));
|
||||
lang_list = g_ptr_array_new_with_free_func (g_free);
|
||||
if (aspell_get_lang_list (lang_list) != 0)
|
||||
{
|
||||
char *lang;
|
||||
@ -735,7 +712,8 @@ edit_set_spell_lang (void)
|
||||
*/
|
||||
|
||||
int
|
||||
spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word, GArray * suggest)
|
||||
spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word,
|
||||
const GPtrArray * suggest)
|
||||
{
|
||||
|
||||
int sug_dlg_h = 14; /* dialog height */
|
||||
@ -796,8 +774,8 @@ spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word
|
||||
|
||||
sug_list = listbox_new (5, 2, sug_dlg_h - 7, 24, FALSE, NULL);
|
||||
for (i = 0; i < suggest->len; i++)
|
||||
listbox_add_item (sug_list, LISTBOX_APPEND_AT_END, 0, g_array_index (suggest, char *, i),
|
||||
NULL, FALSE);
|
||||
listbox_add_item (sug_list, LISTBOX_APPEND_AT_END, 0, g_ptr_array_index (suggest, i), NULL,
|
||||
FALSE);
|
||||
group_add_widget (g, sug_list);
|
||||
|
||||
group_add_widget (g, add_btn);
|
||||
@ -832,7 +810,7 @@ spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word
|
||||
*/
|
||||
|
||||
char *
|
||||
spell_dialog_lang_list_show (GArray * languages)
|
||||
spell_dialog_lang_list_show (const GPtrArray * languages)
|
||||
{
|
||||
|
||||
int lang_dlg_h = 12; /* dialog height */
|
||||
@ -847,14 +825,13 @@ spell_dialog_lang_list_show (GArray * languages)
|
||||
_("Select language"), "[ASpell]");
|
||||
|
||||
for (i = 0; i < languages->len; i++)
|
||||
LISTBOX_APPEND_TEXT (lang_list, 0, g_array_index (languages, char *, i), NULL, FALSE);
|
||||
LISTBOX_APPEND_TEXT (lang_list, 0, g_ptr_array_index (languages, i), NULL, FALSE);
|
||||
|
||||
res = listbox_run (lang_list);
|
||||
if (res >= 0)
|
||||
selected_lang = g_strdup (g_array_index (languages, char *, (unsigned int) res));
|
||||
selected_lang = g_strdup (g_ptr_array_index (languages, (unsigned int) res));
|
||||
|
||||
return selected_lang;
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -16,9 +16,9 @@
|
||||
void aspell_init (void);
|
||||
void aspell_clean (void);
|
||||
gboolean aspell_check (const char *word, const int word_size);
|
||||
unsigned int aspell_suggest (GArray * suggest, const char *word, const int word_size);
|
||||
void aspell_array_clean (GArray * array);
|
||||
unsigned int aspell_get_lang_list (GArray * lang_list);
|
||||
unsigned int aspell_suggest (GPtrArray * suggest, const char *word, const int word_size);
|
||||
void aspell_array_clean (GPtrArray * array);
|
||||
unsigned int aspell_get_lang_list (GPtrArray * lang_list);
|
||||
const char *aspell_get_lang (void);
|
||||
gboolean aspell_set_lang (const char *lang);
|
||||
gboolean aspell_add_to_dict (const char *word, const int word_size);
|
||||
@ -28,8 +28,8 @@ void edit_spellcheck_file (WEdit * edit);
|
||||
void edit_set_spell_lang (void);
|
||||
|
||||
int spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word,
|
||||
GArray * suggest);
|
||||
char *spell_dialog_lang_list_show (GArray * languages);
|
||||
const GPtrArray * suggest);
|
||||
char *spell_dialog_lang_list_show (const GPtrArray * languages);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user