vector matchvec;
struct cmd_element *cmd_element;
int index;
+ int ret;
+ enum match_type match;
+ char *command;
static struct desc desc_cr = { "<cr>", "" };
/* Set index. */
matchvec = vector_init (INIT_MATCHVEC_SIZE);
/* Filter commands. */
+ /* Only words precedes current word will be checked in this loop. */
for (i = 0; i < index; i++)
{
- enum match_type match;
- char *command;
- int ret;
-
command = vector_slot (vline, i);
-
match = cmd_filter_by_completion (command, cmd_vector, i);
if (match == vararg_match)
}
vector_set (matchvec, &desc_cr);
-
vector_free (cmd_vector);
return matchvec;
/* Prepare match vector */
/* matchvec = vector_init (INIT_MATCHVEC_SIZE); */
+ /* Make sure that cmd_vector is filtered based on current word */
+ command = vector_slot (vline, index);
+ if (command)
+ match = cmd_filter_by_completion (command, cmd_vector, index);
+
/* Make description vector. */
for (i = 0; i < vector_max (cmd_vector); i++)
if ((cmd_element = vector_slot (cmd_vector, i)) != NULL)
char *string = NULL;
vector strvec = cmd_element->strvec;
- if (index > vector_max (strvec))
+ /* if command is NULL, index may be equal to vector_max */
+ if (command && index >= vector_max (strvec))
vector_slot (cmd_vector, i) = NULL;
else
{
- /* Check is command is completed. */
- if (index == vector_max (strvec))
+ /* Check if command is completed. */
+ if (command == NULL && index == vector_max (strvec))
{
string = "<cr>";
if (! desc_unique_string (matchvec, string))
for (j = 0; j < vector_max (descvec); j++)
{
desc = vector_slot (descvec, j);
- string = cmd_entry_function_desc (vector_slot (vline, index), desc->cmd);
+ string = cmd_entry_function_desc (command, desc->cmd);
if (string)
{
/* Uniqueness check */