Refactoring: use GString instead of "struct selection".
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
18cc9ac0dd
Коммит
2254b24008
@ -1203,7 +1203,7 @@ edit_collect_completions_get_current_word (WEdit * edit, mc_search_t * srch, off
|
|||||||
|
|
||||||
static gsize
|
static gsize
|
||||||
edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
|
edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
|
||||||
char *match_expr, struct selection *compl, gsize * num)
|
char *match_expr, GString ** compl, gsize * num)
|
||||||
{
|
{
|
||||||
gsize len = 0;
|
gsize len = 0;
|
||||||
gsize max_len = 0;
|
gsize max_len = 0;
|
||||||
@ -1267,14 +1267,12 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
|
|||||||
for (i = 0; i < *num; i++)
|
for (i = 0; i < *num; i++)
|
||||||
{
|
{
|
||||||
if (strncmp
|
if (strncmp
|
||||||
((char *) &compl[i].text[word_len],
|
((char *) &compl[i]->str[word_len],
|
||||||
(char *) &temp->str[word_len], max (len, compl[i].len) - word_len) == 0)
|
(char *) &temp->str[word_len], max (len, compl[i]->len) - word_len) == 0)
|
||||||
{
|
{
|
||||||
struct selection this = compl[i];
|
GString *this = compl[i];
|
||||||
for (++i; i < *num; i++)
|
for (++i; i < *num; i++)
|
||||||
{
|
|
||||||
compl[i - 1] = compl[i];
|
compl[i - 1] = compl[i];
|
||||||
}
|
|
||||||
compl[*num - 1] = this;
|
compl[*num - 1] = this;
|
||||||
skip = 1;
|
skip = 1;
|
||||||
break; /* skip it, already added */
|
break; /* skip it, already added */
|
||||||
@ -1285,11 +1283,9 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
|
|||||||
|
|
||||||
if (*num == MAX_WORD_COMPLETIONS)
|
if (*num == MAX_WORD_COMPLETIONS)
|
||||||
{
|
{
|
||||||
g_free (compl[0].text);
|
g_string_free (compl[0], TRUE);
|
||||||
for (i = 1; i < *num; i++)
|
for (i = 1; i < *num; i++)
|
||||||
{
|
|
||||||
compl[i - 1] = compl[i];
|
compl[i - 1] = compl[i];
|
||||||
}
|
|
||||||
(*num)--;
|
(*num)--;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
@ -1303,9 +1299,7 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
|
|||||||
g_string_free (recoded, TRUE);
|
g_string_free (recoded, TRUE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
compl[*num].text = g_strndup (temp->str, temp->len);
|
compl[(*num)++] = g_string_new_len (temp->str, temp->len);
|
||||||
compl[*num].len = temp->len;
|
|
||||||
(*num)++;
|
|
||||||
start += len;
|
start += len;
|
||||||
|
|
||||||
/* note the maximal length needed for the completion dialog */
|
/* note the maximal length needed for the completion dialog */
|
||||||
@ -3274,7 +3268,7 @@ edit_complete_word_cmd (WEdit * edit)
|
|||||||
off_t word_start = 0;
|
off_t word_start = 0;
|
||||||
unsigned char *bufpos;
|
unsigned char *bufpos;
|
||||||
char *match_expr;
|
char *match_expr;
|
||||||
struct selection compl[MAX_WORD_COMPLETIONS]; /* completions */
|
GString *compl[MAX_WORD_COMPLETIONS]; /* completions */
|
||||||
|
|
||||||
/* search start of word to be completed */
|
/* search start of word to be completed */
|
||||||
if (!edit_find_word_start (edit, &word_start, &word_len))
|
if (!edit_find_word_start (edit, &word_start, &word_len))
|
||||||
@ -3292,16 +3286,16 @@ edit_complete_word_cmd (WEdit * edit)
|
|||||||
/* collect the possible completions */
|
/* collect the possible completions */
|
||||||
/* start search from begin to end of file */
|
/* start search from begin to end of file */
|
||||||
max_len =
|
max_len =
|
||||||
edit_collect_completions (edit, word_start, word_len, match_expr,
|
edit_collect_completions (edit, word_start, word_len, match_expr, (GString **) &compl,
|
||||||
(struct selection *) &compl, &num_compl);
|
&num_compl);
|
||||||
|
|
||||||
if (num_compl > 0)
|
if (num_compl > 0)
|
||||||
{
|
{
|
||||||
/* insert completed word if there is only one match */
|
/* insert completed word if there is only one match */
|
||||||
if (num_compl == 1)
|
if (num_compl == 1)
|
||||||
{
|
{
|
||||||
for (i = word_len; i < compl[0].len; i++)
|
for (i = word_len; i < compl[0]->len; i++)
|
||||||
edit_insert (edit, *(compl[0].text + i));
|
edit_insert (edit, *(compl[0]->str + i));
|
||||||
}
|
}
|
||||||
/* more than one possible completion => ask the user */
|
/* more than one possible completion => ask the user */
|
||||||
else
|
else
|
||||||
@ -3312,15 +3306,14 @@ edit_complete_word_cmd (WEdit * edit)
|
|||||||
/*tty_beep (); */
|
/*tty_beep (); */
|
||||||
|
|
||||||
/* let the user select the preferred completion */
|
/* let the user select the preferred completion */
|
||||||
editcmd_dialog_completion_show (edit, max_len, word_len,
|
editcmd_dialog_completion_show (edit, max_len, word_len, (GString **) &compl, num_compl);
|
||||||
(struct selection *) &compl, num_compl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (match_expr);
|
g_free (match_expr);
|
||||||
/* release memory before return */
|
/* release memory before return */
|
||||||
for (i = 0; i < num_compl; i++)
|
for (i = 0; i < num_compl; i++)
|
||||||
g_free (compl[i].text);
|
g_string_free (compl[i], TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -338,7 +338,7 @@ editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean c
|
|||||||
|
|
||||||
void
|
void
|
||||||
editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
|
editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
|
||||||
struct selection *compl, int num_compl)
|
GString ** compl, int num_compl)
|
||||||
{
|
{
|
||||||
|
|
||||||
int start_x, start_y, offset, i;
|
int start_x, start_y, offset, i;
|
||||||
@ -382,7 +382,7 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
|
|||||||
|
|
||||||
/* fill the listbox with the completions */
|
/* fill the listbox with the completions */
|
||||||
for (i = num_compl - 1; i >= 0; i--) /* reverse order */
|
for (i = num_compl - 1; i >= 0; i--) /* reverse order */
|
||||||
listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL);
|
listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i]->str, NULL);
|
||||||
|
|
||||||
/* pop up the dialog and apply the choosen completion */
|
/* pop up the dialog and apply the choosen completion */
|
||||||
if (run_dlg (compl_dlg) == B_ENTER)
|
if (run_dlg (compl_dlg) == B_ENTER)
|
||||||
|
@ -15,12 +15,6 @@ struct etags_hash_struct;
|
|||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
struct selection
|
|
||||||
{
|
|
||||||
gchar *text;
|
|
||||||
gsize len;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*** global variables defined in .c file *********************************************************/
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
/*** declarations of public functions ************************************************************/
|
/*** declarations of public functions ************************************************************/
|
||||||
@ -31,7 +25,7 @@ gboolean editcmd_dialog_search_show (WEdit * edit);
|
|||||||
|
|
||||||
int editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean cancel);
|
int editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean cancel);
|
||||||
|
|
||||||
void editcmd_dialog_completion_show (WEdit *, int, int, struct selection *, int);
|
void editcmd_dialog_completion_show (WEdit *, int, int, GString **, int);
|
||||||
|
|
||||||
void editcmd_dialog_select_definition_show (WEdit *, char *, int, int, struct etags_hash_struct *,
|
void editcmd_dialog_select_definition_show (WEdit *, char *, int, int, struct etags_hash_struct *,
|
||||||
int);
|
int);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user