1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -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:
Timo Sirainen 2000-07-09 00:03:46 +00:00 committed by cras
parent abb46a0313
commit 8bea491a57
4 changed files with 48 additions and 26 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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);