diff options
-rw-r--r-- | src/core/commands.c | 19 | ||||
-rw-r--r-- | src/core/commands.h | 1 | ||||
-rw-r--r-- | src/fe-common/core/completion.c | 23 | ||||
-rw-r--r-- | src/fe-common/core/fe-core-commands.c | 31 |
4 files changed, 48 insertions, 26 deletions
diff --git a/src/core/commands.c b/src/core/commands.c index 12131d10..fbfc7c37 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -52,6 +52,25 @@ COMMAND_REC *command_find(const char *cmd) 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) { COMMAND_REC *rec; diff --git a/src/core/commands.h b/src/core/commands.h index 29ddbfb4..3201c5ab 100644 --- a/src/core/commands.h +++ b/src/core/commands.h @@ -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); COMMAND_REC *command_find(const char *cmd); +int command_have_sub(const char *command); /* Specify options that command can accept. `options' contains list of options separated with space, each option can contain a special diff --git a/src/fe-common/core/completion.c b/src/fe-common/core/completion.c index 4a62d4f6..aa1859c7 100644 --- a/src/fe-common/core/completion.c +++ b/src/fe-common/core/completion.c @@ -265,25 +265,6 @@ GList *filename_complete(const char *path) 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) { GList *complist; @@ -509,7 +490,7 @@ static void sig_complete_word(GList **list, WINDOW_REC *window, line = linestart[1] == *cmdchars ? g_strdup(linestart+2) : expand_aliases(linestart+1); - if (is_base_command(line)) { + if (command_have_sub(line)) { /* complete subcommand */ cmd = g_strconcat(line, " ", word, NULL); *list = completion_get_subcommands(cmd); @@ -600,7 +581,7 @@ static void sig_complete_command(GList **list, WINDOW_REC *window, if (*line == '\0') { /* complete base command */ *list = completion_get_commands(word, '\0'); - } else if (is_base_command(line)) { + } else if (command_have_sub(line)) { /* complete subcommand */ cmd = g_strconcat(line, " ", word, NULL); *list = completion_get_subcommands(cmd); diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 251ecc3b..d2dada6c 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -107,7 +107,7 @@ static void help_category(GSList *cmdlist, gint items, gint max) g_free(cmdbuf); } -static int show_help(COMMAND_REC *cmd) +static int show_help_rec(COMMAND_REC *cmd) { char tmpbuf[1024], *str, *path; LINEBUF_REC *buffer = NULL; @@ -139,12 +139,12 @@ static int show_help(COMMAND_REC *cmd) return TRUE; } -static void cmd_help(gchar *data) +static void show_help(const char *data) { COMMAND_REC *rec, *last, *helpitem; GSList *tmp, *cmdlist; gint len, max, items, findlen; - gboolean header; + gboolean header, found; g_return_if_fail(data != NULL); @@ -153,7 +153,7 @@ static void cmd_help(gchar *data) /* print command, sort by category */ 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) { rec = tmp->data; @@ -198,13 +198,22 @@ static void cmd_help(gchar *data) if (max < len) max = len; items++; 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); + 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) { /* 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) { g_return_if_fail(data != NULL); |