mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
Moved is_base_command() from command completion to command_have_sub()
in core/commands. /HELP <command with subcommands> works now right. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@437 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
abb46a0313
commit
8bea491a57
@ -52,6 +52,25 @@ COMMAND_REC *command_find(const char *cmd)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int command_have_sub(const char *command)
|
||||||
|
{
|
||||||
|
GSList *tmp;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
g_return_val_if_fail(command != NULL, FALSE);
|
||||||
|
|
||||||
|
/* find "command "s */
|
||||||
|
len = strlen(command);
|
||||||
|
for (tmp = commands; tmp != NULL; tmp = tmp->next) {
|
||||||
|
COMMAND_REC *rec = tmp->data;
|
||||||
|
|
||||||
|
if (g_strncasecmp(rec->cmd, command, len) == 0 && rec->cmd[len] == ' ')
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void command_bind_to(int pos, const char *cmd, const char *category, SIGNAL_FUNC func)
|
void command_bind_to(int pos, const char *cmd, const char *category, SIGNAL_FUNC func)
|
||||||
{
|
{
|
||||||
COMMAND_REC *rec;
|
COMMAND_REC *rec;
|
||||||
|
@ -52,6 +52,7 @@ void command_unbind(const char *cmd, SIGNAL_FUNC func);
|
|||||||
void command_runsub(const char *cmd, const char *data, void *server, void *item);
|
void command_runsub(const char *cmd, const char *data, void *server, void *item);
|
||||||
|
|
||||||
COMMAND_REC *command_find(const char *cmd);
|
COMMAND_REC *command_find(const char *cmd);
|
||||||
|
int command_have_sub(const char *command);
|
||||||
|
|
||||||
/* Specify options that command can accept. `options' contains list of
|
/* Specify options that command can accept. `options' contains list of
|
||||||
options separated with space, each option can contain a special
|
options separated with space, each option can contain a special
|
||||||
|
@ -265,25 +265,6 @@ GList *filename_complete(const char *path)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_base_command(const char *command)
|
|
||||||
{
|
|
||||||
GSList *tmp;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
g_return_val_if_fail(command != NULL, FALSE);
|
|
||||||
|
|
||||||
/* find "command "s */
|
|
||||||
len = strlen(command);
|
|
||||||
for (tmp = commands; tmp != NULL; tmp = tmp->next) {
|
|
||||||
COMMAND_REC *rec = tmp->data;
|
|
||||||
|
|
||||||
if (g_strncasecmp(rec->cmd, command, len) == 0 && rec->cmd[len] == ' ')
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GList *completion_get_settings(const char *key)
|
static GList *completion_get_settings(const char *key)
|
||||||
{
|
{
|
||||||
GList *complist;
|
GList *complist;
|
||||||
@ -509,7 +490,7 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
|
|||||||
line = linestart[1] == *cmdchars ? g_strdup(linestart+2) :
|
line = linestart[1] == *cmdchars ? g_strdup(linestart+2) :
|
||||||
expand_aliases(linestart+1);
|
expand_aliases(linestart+1);
|
||||||
|
|
||||||
if (is_base_command(line)) {
|
if (command_have_sub(line)) {
|
||||||
/* complete subcommand */
|
/* complete subcommand */
|
||||||
cmd = g_strconcat(line, " ", word, NULL);
|
cmd = g_strconcat(line, " ", word, NULL);
|
||||||
*list = completion_get_subcommands(cmd);
|
*list = completion_get_subcommands(cmd);
|
||||||
@ -600,7 +581,7 @@ static void sig_complete_command(GList **list, WINDOW_REC *window,
|
|||||||
if (*line == '\0') {
|
if (*line == '\0') {
|
||||||
/* complete base command */
|
/* complete base command */
|
||||||
*list = completion_get_commands(word, '\0');
|
*list = completion_get_commands(word, '\0');
|
||||||
} else if (is_base_command(line)) {
|
} else if (command_have_sub(line)) {
|
||||||
/* complete subcommand */
|
/* complete subcommand */
|
||||||
cmd = g_strconcat(line, " ", word, NULL);
|
cmd = g_strconcat(line, " ", word, NULL);
|
||||||
*list = completion_get_subcommands(cmd);
|
*list = completion_get_subcommands(cmd);
|
||||||
|
@ -107,7 +107,7 @@ static void help_category(GSList *cmdlist, gint items, gint max)
|
|||||||
g_free(cmdbuf);
|
g_free(cmdbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int show_help(COMMAND_REC *cmd)
|
static int show_help_rec(COMMAND_REC *cmd)
|
||||||
{
|
{
|
||||||
char tmpbuf[1024], *str, *path;
|
char tmpbuf[1024], *str, *path;
|
||||||
LINEBUF_REC *buffer = NULL;
|
LINEBUF_REC *buffer = NULL;
|
||||||
@ -139,12 +139,12 @@ static int show_help(COMMAND_REC *cmd)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_help(gchar *data)
|
static void show_help(const char *data)
|
||||||
{
|
{
|
||||||
COMMAND_REC *rec, *last, *helpitem;
|
COMMAND_REC *rec, *last, *helpitem;
|
||||||
GSList *tmp, *cmdlist;
|
GSList *tmp, *cmdlist;
|
||||||
gint len, max, items, findlen;
|
gint len, max, items, findlen;
|
||||||
gboolean header;
|
gboolean header, found;
|
||||||
|
|
||||||
g_return_if_fail(data != NULL);
|
g_return_if_fail(data != NULL);
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ static void cmd_help(gchar *data)
|
|||||||
|
|
||||||
/* print command, sort by category */
|
/* print command, sort by category */
|
||||||
cmdlist = NULL; last = NULL; header = FALSE; helpitem = NULL;
|
cmdlist = NULL; last = NULL; header = FALSE; helpitem = NULL;
|
||||||
max = items = 0; findlen = strlen(data);
|
max = items = 0; findlen = strlen(data); found = FALSE;
|
||||||
for (tmp = commands; tmp != NULL; last = rec, tmp = tmp->next)
|
for (tmp = commands; tmp != NULL; last = rec, tmp = tmp->next)
|
||||||
{
|
{
|
||||||
rec = tmp->data;
|
rec = tmp->data;
|
||||||
@ -198,13 +198,22 @@ static void cmd_help(gchar *data)
|
|||||||
if (max < len) max = len;
|
if (max < len) max = len;
|
||||||
items++;
|
items++;
|
||||||
cmdlist = g_slist_append(cmdlist, rec);
|
cmdlist = g_slist_append(cmdlist, rec);
|
||||||
|
found = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((helpitem == NULL && items == 0) || (helpitem != NULL && !show_help(helpitem)))
|
if (!found || (helpitem != NULL && !show_help_rec(helpitem)))
|
||||||
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "No help for %s", data);
|
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "No help for %s", data);
|
||||||
|
|
||||||
|
if (data[strlen(data)-1] != ' ' && command_have_sub(data)) {
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
|
cmd = g_strconcat(data, " ", NULL);
|
||||||
|
show_help(cmd);
|
||||||
|
g_free(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
if (items != 0)
|
if (items != 0)
|
||||||
{
|
{
|
||||||
/* display the last category */
|
/* display the last category */
|
||||||
@ -224,6 +233,18 @@ static void cmd_help(gchar *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cmd_help(const char *data)
|
||||||
|
{
|
||||||
|
char *cmd, *ptr;
|
||||||
|
|
||||||
|
cmd = g_strdup(data);
|
||||||
|
ptr = cmd+strlen(cmd);
|
||||||
|
while (ptr[-1] == ' ') ptr--; *ptr = '\0';
|
||||||
|
|
||||||
|
show_help(cmd);
|
||||||
|
g_free(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
static void cmd_echo(const char *data, void *server, WI_ITEM_REC *item)
|
static void cmd_echo(const char *data, void *server, WI_ITEM_REC *item)
|
||||||
{
|
{
|
||||||
g_return_if_fail(data != NULL);
|
g_return_if_fail(data != NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user