mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -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:
parent
6c69f384bd
commit
c15f655bca
@ -112,10 +112,11 @@ static const char *command_expand(char *cmd)
|
|||||||
{
|
{
|
||||||
GSList *tmp;
|
GSList *tmp;
|
||||||
const char *match;
|
const char *match;
|
||||||
int len;
|
int len, multiple;
|
||||||
|
|
||||||
g_return_val_if_fail(cmd != NULL, NULL);
|
g_return_val_if_fail(cmd != NULL, NULL);
|
||||||
|
|
||||||
|
multiple = FALSE;
|
||||||
match = NULL;
|
match = NULL;
|
||||||
len = strlen(cmd);
|
len = strlen(cmd);
|
||||||
for (tmp = commands; tmp != NULL; tmp = tmp->next) {
|
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 &&
|
if (g_strncasecmp(rec->cmd, cmd, len) == 0 &&
|
||||||
strchr(rec->cmd+len, ' ') == NULL) {
|
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') {
|
if (rec->cmd[len] == '\0') {
|
||||||
/* full match */
|
/* full match */
|
||||||
return rec->cmd;
|
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 */
|
/* check that this is the only match */
|
||||||
match = rec->cmd;
|
match = rec->cmd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (multiple) {
|
||||||
|
signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_AMBIGUOUS), cmd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return match != NULL ? match : cmd;
|
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)
|
static int option_find(char **array, const char *option)
|
||||||
{
|
{
|
||||||
char **tmp;
|
char **tmp;
|
||||||
int index, found, len;
|
int index, found, len, multiple;
|
||||||
|
|
||||||
g_return_val_if_fail(array != NULL, -1);
|
g_return_val_if_fail(array != NULL, -1);
|
||||||
g_return_val_if_fail(option != 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);
|
len = strlen(option);
|
||||||
g_return_val_if_fail(len > 0, -1);
|
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++) {
|
for (tmp = array; *tmp != NULL; tmp++, index++) {
|
||||||
const char *text = *tmp + iscmdtype(**tmp);
|
const char *text = *tmp + iscmdtype(**tmp);
|
||||||
|
|
||||||
@ -316,8 +323,9 @@ static int option_find(char **array, const char *option)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (found != -1) {
|
if (found != -1) {
|
||||||
/* multiple matches - abort */
|
/* multiple matches - we still need to check
|
||||||
return -2;
|
if there's a full match left.. */
|
||||||
|
multiple = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* partial match, check that it's the only one */
|
/* 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;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user