mirror of https://github.com/MidnightCommander/mc
* editcmd.c (edit_set_search_parameters): Use g_malloc().
(edit_complete_word_cmd): Use g_free().
This commit is contained in:
parent
b628d515c0
commit
29f1543919
|
@ -1,3 +1,8 @@
|
|||
2002-11-30 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* editcmd.c (edit_set_search_parameters): Use g_malloc().
|
||||
(edit_complete_word_cmd): Use g_free().
|
||||
|
||||
2002-11-29 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* edit.h: Don't define HAVE_SYNTAXH.
|
||||
|
|
|
@ -2481,8 +2481,10 @@ static void edit_set_search_parameters (int rs, int rb, int rr, int rw, int rc)
|
|||
#define MAX_WORD_COMPLETIONS 100 /* in listbox */
|
||||
|
||||
/* collect the possible completions */
|
||||
static int edit_collect_completions (WEdit *edit, long start,
|
||||
int word_len, char *match_expr, struct selection *compl, int *num)
|
||||
static int
|
||||
edit_collect_completions (WEdit *edit, long start, int word_len,
|
||||
char *match_expr, struct selection *compl,
|
||||
int *num)
|
||||
{
|
||||
int len, max_len = 0, i, skip;
|
||||
char *bufpos;
|
||||
|
@ -2490,8 +2492,10 @@ static int edit_collect_completions (WEdit *edit, long start,
|
|||
/* collect max MAX_WORD_COMPLETIONS completions */
|
||||
while (*num < MAX_WORD_COMPLETIONS) {
|
||||
/* get next match */
|
||||
start = edit_find (start - 1, (unsigned char *) match_expr, &len,
|
||||
edit->last_byte, (int (*)(void *, long)) edit_get_byte,
|
||||
start =
|
||||
edit_find (start - 1, (unsigned char *) match_expr, &len,
|
||||
edit->last_byte,
|
||||
(int (*)(void *, long)) edit_get_byte,
|
||||
(void *) edit, 0);
|
||||
|
||||
/* not matched */
|
||||
|
@ -2499,10 +2503,13 @@ static int edit_collect_completions (WEdit *edit, long start,
|
|||
break;
|
||||
|
||||
/* add matched completion if not yet added */
|
||||
bufpos = &edit->buffers1[start >> S_EDIT_BUF_SIZE][start & M_EDIT_BUF_SIZE];
|
||||
bufpos =
|
||||
&edit->
|
||||
buffers1[start >> S_EDIT_BUF_SIZE][start & M_EDIT_BUF_SIZE];
|
||||
skip = 0;
|
||||
for (i = 0; i < *num; i++) {
|
||||
if (strncmp (&compl[i].text[word_len], &bufpos[word_len],
|
||||
if (strncmp
|
||||
(&compl[i].text[word_len], &bufpos[word_len],
|
||||
max (len, compl[i].len) - word_len) == 0) {
|
||||
skip = 1;
|
||||
break; /* skip it, already added */
|
||||
|
@ -2511,7 +2518,7 @@ static int edit_collect_completions (WEdit *edit, long start,
|
|||
if (skip)
|
||||
continue;
|
||||
|
||||
compl[*num].text = CMalloc (len + 1);
|
||||
compl[*num].text = g_malloc (len + 1);
|
||||
compl[*num].len = len;
|
||||
for (i = 0; i < len; i++)
|
||||
compl[*num].text[i] = *(bufpos + i);
|
||||
|
@ -2526,7 +2533,8 @@ static int edit_collect_completions (WEdit *edit, long start,
|
|||
}
|
||||
|
||||
|
||||
static int compllist_callback (void *data)
|
||||
static int
|
||||
compllist_callback (void *data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -2565,12 +2573,14 @@ edit_completion_dialog (WEdit *edit, int max_len, int word_len,
|
|||
start_y -= (offset + 1);
|
||||
|
||||
/* create the dialog */
|
||||
compl_dlg = create_dlg (start_y, start_x, compl_dlg_h, compl_dlg_w,
|
||||
compl_dlg =
|
||||
create_dlg (start_y, start_x, compl_dlg_h, compl_dlg_w,
|
||||
dialog_colors, NULL, "[Completion]", NULL,
|
||||
DLG_COMPACT);
|
||||
|
||||
/* create the listbox */
|
||||
compl_list = listbox_new (1, 1, compl_dlg_w - 2, compl_dlg_h - 2, 0,
|
||||
compl_list =
|
||||
listbox_new (1, 1, compl_dlg_w - 2, compl_dlg_h - 2, 0,
|
||||
compllist_callback, NULL);
|
||||
|
||||
/* add the dialog */
|
||||
|
@ -2596,9 +2606,12 @@ edit_completion_dialog (WEdit *edit, int max_len, int word_len,
|
|||
}
|
||||
|
||||
|
||||
/* complete current word using regular expression search */
|
||||
/* backwards beginning at current cursor position */
|
||||
void edit_complete_word_cmd (WEdit *edit)
|
||||
/*
|
||||
* Complete current word using regular expression search
|
||||
* backwards beginning at the current cursor position.
|
||||
*/
|
||||
void
|
||||
edit_complete_word_cmd (WEdit *edit)
|
||||
{
|
||||
int word_len = 0, i, num_compl = 0, max_len;
|
||||
long word_start = 0;
|
||||
|
@ -2629,8 +2642,9 @@ void edit_complete_word_cmd (WEdit *edit)
|
|||
|
||||
/* collect the possible completions */
|
||||
/* start search from curs1 down to begin of file */
|
||||
max_len = edit_collect_completions (edit, word_start, word_len,
|
||||
match_expr, (struct selection *) &compl, &num_compl);
|
||||
max_len =
|
||||
edit_collect_completions (edit, word_start, word_len, match_expr,
|
||||
(struct selection *) &compl, &num_compl);
|
||||
|
||||
if (num_compl > 0) {
|
||||
/* insert completed word if there is only one match */
|
||||
|
@ -2647,13 +2661,14 @@ void edit_complete_word_cmd (WEdit *edit)
|
|||
|
||||
/* let the user select the preferred completion */
|
||||
edit_completion_dialog (edit, max_len, word_len,
|
||||
(struct selection *) &compl, num_compl);
|
||||
(struct selection *) &compl,
|
||||
num_compl);
|
||||
}
|
||||
}
|
||||
|
||||
/* release memory before return */
|
||||
for (i = 0; i < num_compl; i++)
|
||||
free (compl[i].text);
|
||||
g_free (compl[i].text);
|
||||
|
||||
/* restore search parameters */
|
||||
edit_set_search_parameters (old_rs, old_rb, old_rr, old_rw, old_rc);
|
||||
|
|
Loading…
Reference in New Issue