1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Automatic command and option completion didn't check ambiguous commands

right. For example /VER didn't work because there was /VERSION command
too..


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@411 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-07-02 11:30:19 +00:00 committed by cras
parent 6c69f384bd
commit c15f655bca

View File

@ -112,10 +112,11 @@ static const char *command_expand(char *cmd)
{
GSList *tmp;
const char *match;
int len;
int len, multiple;
g_return_val_if_fail(cmd != NULL, NULL);
multiple = FALSE;
match = NULL;
len = strlen(cmd);
for (tmp = commands; tmp != NULL; tmp = tmp->next) {
@ -123,22 +124,28 @@ static const char *command_expand(char *cmd)
if (g_strncasecmp(rec->cmd, cmd, len) == 0 &&
strchr(rec->cmd+len, ' ') == NULL) {
if (match != NULL) {
/* multiple matches */
signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_AMBIGUOUS), cmd);
return NULL;
}
if (rec->cmd[len] == '\0') {
/* full match */
return rec->cmd;
}
if (match != NULL) {
/* multiple matches, we still need to check
if there's some command left that is a
full match.. */
multiple = TRUE;
}
/* check that this is the only match */
match = rec->cmd;
}
}
if (multiple) {
signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_AMBIGUOUS), cmd);
return NULL;
}
return match != NULL ? match : cmd;
}
@ -297,7 +304,7 @@ static char *cmd_get_quoted_param(char **data)
static int option_find(char **array, const char *option)
{
char **tmp;
int index, found, len;
int index, found, len, multiple;
g_return_val_if_fail(array != NULL, -1);
g_return_val_if_fail(option != NULL, -1);
@ -305,7 +312,7 @@ static int option_find(char **array, const char *option)
len = strlen(option);
g_return_val_if_fail(len > 0, -1);
found = -1; index = 0;
found = -1; index = 0; multiple = FALSE;
for (tmp = array; *tmp != NULL; tmp++, index++) {
const char *text = *tmp + iscmdtype(**tmp);
@ -316,8 +323,9 @@ static int option_find(char **array, const char *option)
}
if (found != -1) {
/* multiple matches - abort */
return -2;
/* multiple matches - we still need to check
if there's a full match left.. */
multiple = TRUE;
}
/* partial match, check that it's the only one */
@ -325,6 +333,9 @@ static int option_find(char **array, const char *option)
}
}
if (multiple)
return -2;
return found;
}