mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
When using a /command that has only subcommands, print the list of the
subcommands instead of just "unknown command" text. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1093 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
6a7c1d212a
commit
e46e2b5e09
@ -282,9 +282,8 @@ void command_runsub(const char *cmd, const char *data,
|
|||||||
g_return_if_fail(data != NULL);
|
g_return_if_fail(data != NULL);
|
||||||
|
|
||||||
if (*data == '\0') {
|
if (*data == '\0') {
|
||||||
/* no subcommand given - unknown command? */
|
/* no subcommand given - list the subcommands */
|
||||||
signal_emit("error command", 2,
|
signal_emit("list subcommands", 2, cmd);
|
||||||
GINT_TO_POINTER(CMDERR_UNKNOWN), cmd);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,8 +289,10 @@ static void cmd_version(char *data)
|
|||||||
{
|
{
|
||||||
g_return_if_fail(data != NULL);
|
g_return_if_fail(data != NULL);
|
||||||
|
|
||||||
if (*data == '\0')
|
if (*data == '\0') {
|
||||||
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Client: "PACKAGE" " IRSSI_VERSION);
|
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||||
|
"Client: "PACKAGE" " IRSSI_VERSION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SYNTAX: CAT <file> */
|
/* SYNTAX: CAT <file> */
|
||||||
@ -314,7 +316,8 @@ static void cmd_cat(const char *data)
|
|||||||
|
|
||||||
if (f == -1) {
|
if (f == -1) {
|
||||||
/* file not found */
|
/* file not found */
|
||||||
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s", g_strerror(errno));
|
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
|
||||||
|
"%s", g_strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +326,8 @@ static void cmd_cat(const char *data)
|
|||||||
recvlen = read(f, tmpbuf, sizeof(tmpbuf));
|
recvlen = read(f, tmpbuf, sizeof(tmpbuf));
|
||||||
|
|
||||||
ret = line_split(tmpbuf, recvlen, &str, &buffer);
|
ret = line_split(tmpbuf, recvlen, &str, &buffer);
|
||||||
if (ret > 0) printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", str);
|
if (ret > 0)
|
||||||
|
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", str);
|
||||||
} while (ret > 0);
|
} while (ret > 0);
|
||||||
line_split_free(buffer);
|
line_split_free(buffer);
|
||||||
|
|
||||||
@ -357,7 +361,8 @@ static void event_command(const char *data)
|
|||||||
|
|
||||||
/* /^command hides the output of the command */
|
/* /^command hides the output of the command */
|
||||||
cmdchar = strchr(settings_get_str("cmdchars"), *data);
|
cmdchar = strchr(settings_get_str("cmdchars"), *data);
|
||||||
if (cmdchar != NULL && (data[1] == '^' || (data[1] == *cmdchar && data[2] == '^'))) {
|
if (cmdchar != NULL && (data[1] == '^' ||
|
||||||
|
(data[1] == *cmdchar && data[2] == '^'))) {
|
||||||
hide_output = TRUE;
|
hide_output = TRUE;
|
||||||
signal_add_first("print starting", (SIGNAL_FUNC) sig_stop);
|
signal_add_first("print starting", (SIGNAL_FUNC) sig_stop);
|
||||||
signal_add_first("print format", (SIGNAL_FUNC) sig_stop);
|
signal_add_first("print format", (SIGNAL_FUNC) sig_stop);
|
||||||
@ -377,7 +382,8 @@ static void event_command_last(const char *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_default_command(const char *data, void *server, WI_ITEM_REC *item)
|
static void event_default_command(const char *data, void *server,
|
||||||
|
WI_ITEM_REC *item)
|
||||||
{
|
{
|
||||||
const char *cmdchars, *ptr;
|
const char *cmdchars, *ptr;
|
||||||
char *cmd, *p;
|
char *cmd, *p;
|
||||||
@ -416,7 +422,7 @@ static void event_default_command(const char *data, void *server, WI_ITEM_REC *i
|
|||||||
g_free(cmd);
|
g_free(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_cmderror(gpointer errorp, const char *arg)
|
static void event_cmderror(void *errorp, const char *arg)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
@ -430,6 +436,33 @@ static void event_cmderror(gpointer errorp, const char *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void event_list_subcommands(const char *command)
|
||||||
|
{
|
||||||
|
GSList *tmp;
|
||||||
|
GString *str;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
str = g_string_new(NULL);
|
||||||
|
|
||||||
|
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] == ' ' &&
|
||||||
|
strchr(rec->cmd+len+1, ' ') == NULL) {
|
||||||
|
g_string_sprintfa(str, "%s ", rec->cmd+len+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str->len != 0) {
|
||||||
|
g_string_truncate(str, str->len-1);
|
||||||
|
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s", str->str);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_string_free(str, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
void fe_core_commands_init(void)
|
void fe_core_commands_init(void)
|
||||||
{
|
{
|
||||||
hide_output = FALSE;
|
hide_output = FALSE;
|
||||||
@ -447,6 +480,7 @@ void fe_core_commands_init(void)
|
|||||||
signal_add_last("send command", (SIGNAL_FUNC) event_command_last);
|
signal_add_last("send command", (SIGNAL_FUNC) event_command_last);
|
||||||
signal_add("default command", (SIGNAL_FUNC) event_default_command);
|
signal_add("default command", (SIGNAL_FUNC) event_default_command);
|
||||||
signal_add("error command", (SIGNAL_FUNC) event_cmderror);
|
signal_add("error command", (SIGNAL_FUNC) event_cmderror);
|
||||||
|
signal_add("list subcommands", (SIGNAL_FUNC) event_list_subcommands);
|
||||||
|
|
||||||
command_set_options("echo", "current +level +window");
|
command_set_options("echo", "current +level +window");
|
||||||
}
|
}
|
||||||
@ -463,4 +497,5 @@ void fe_core_commands_deinit(void)
|
|||||||
signal_remove("send command", (SIGNAL_FUNC) event_command_last);
|
signal_remove("send command", (SIGNAL_FUNC) event_command_last);
|
||||||
signal_remove("default command", (SIGNAL_FUNC) event_default_command);
|
signal_remove("default command", (SIGNAL_FUNC) event_default_command);
|
||||||
signal_remove("error command", (SIGNAL_FUNC) event_cmderror);
|
signal_remove("error command", (SIGNAL_FUNC) event_cmderror);
|
||||||
|
signal_remove("list subcommands", (SIGNAL_FUNC) event_list_subcommands);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user