summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config2
-rw-r--r--src/core/commands.c22
-rw-r--r--src/core/commands.h3
-rw-r--r--src/fe-common/irc/fe-channels.c44
-rw-r--r--src/fe-common/irc/fe-irc-commands.c29
-rw-r--r--src/fe-common/irc/fe-query.c45
-rw-r--r--src/fe-common/irc/irc-completion.c2
-rw-r--r--src/irc/core/irc-commands.c28
-rw-r--r--src/irc/core/irc-commands.h4
9 files changed, 150 insertions, 29 deletions
diff --git a/config b/config
index 97caa106..5d0e06a5 100644
--- a/config
+++ b/config
@@ -31,6 +31,8 @@ channels = (
aliases = {
J = "join";
+ WJOIN = "join -window";
+ WQUERY = "query -window";
LEAVE = "part";
BYE = "quit";
EXIT = "quit";
diff --git a/src/core/commands.c b/src/core/commands.c
index 5fbec304..6802713f 100644
--- a/src/core/commands.c
+++ b/src/core/commands.c
@@ -233,6 +233,27 @@ static GSList *optlist_find(GSList *optlist, const char *option)
return NULL;
}
+int command_have_option(const char *cmd, const char *option)
+{
+ COMMAND_REC *rec;
+ char **tmp;
+
+ g_return_val_if_fail(cmd != NULL, FALSE);
+ g_return_val_if_fail(option != NULL, FALSE);
+
+ rec = command_find(cmd);
+ g_return_val_if_fail(rec != NULL, FALSE);
+
+ for (tmp = rec->options; *tmp != NULL; tmp++) {
+ char *name = iscmdtype(**tmp) ? (*tmp)+1 : *tmp;
+
+ if (g_strcasecmp(name, option) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
void command_set_options(const char *cmd, const char *options)
{
COMMAND_REC *rec;
@@ -276,7 +297,6 @@ void command_set_options(const char *cmd, const char *options)
g_strfreev(optlist);
/* linked list -> string[] */
- g_free(rec->options);
str = gslist_to_string(list, " ");
rec->options = g_strsplit(str, " ", -1);
g_free(str);
diff --git a/src/core/commands.h b/src/core/commands.h
index 51bfda57..f5a5c084 100644
--- a/src/core/commands.h
+++ b/src/core/commands.h
@@ -82,6 +82,9 @@ int command_have_sub(const char *command);
((c) == '-' || (c) == '+' || (c) == '@')
void command_set_options(const char *cmd, const char *options);
+/* Returns TRUE if command has specified option. */
+int command_have_option(const char *cmd, const char *option);
+
/* count can have these flags: */
#define PARAM_WITHOUT_FLAGS(a) ((a) & 0x00ffffff)
/* don't check for quotes - "arg1 arg2" is NOT treated as one argument */
diff --git a/src/fe-common/irc/fe-channels.c b/src/fe-common/irc/fe-channels.c
index 64b07fa7..4c1a7011 100644
--- a/src/fe-common/irc/fe-channels.c
+++ b/src/fe-common/irc/fe-channels.c
@@ -108,11 +108,40 @@ static void signal_window_item_changed(WINDOW_REC *window, WI_ITEM_REC *item)
}
}
-static void cmd_wjoin(const char *data, void *server, WI_ITEM_REC *item)
+static void cmd_wjoin_pre(const char *data)
{
- signal_add("channel created", (SIGNAL_FUNC) signal_channel_created_curwin);
- signal_emit("command join", 3, data, server, item);
- signal_remove("channel created", (SIGNAL_FUNC) signal_channel_created_curwin);
+ GHashTable *optlist;
+ char *nick;
+ void *free_arg;
+
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+ "join", &optlist, &nick))
+ return;
+
+ if (g_hash_table_lookup(optlist, "window") != NULL) {
+ signal_add("channel created",
+ (SIGNAL_FUNC) signal_channel_created_curwin);
+ }
+ cmd_params_free(free_arg);
+}
+
+static void cmd_wjoin_post(const char *data)
+{
+ GHashTable *optlist;
+ char *nick;
+ void *free_arg;
+
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+ "join", &optlist, &nick))
+ return;
+
+ if (g_hash_table_lookup(optlist, "window") != NULL) {
+ signal_remove("channel created",
+ (SIGNAL_FUNC) signal_channel_created_curwin);
+ }
+ cmd_params_free(free_arg);
}
static void cmd_channel_list_joined(void)
@@ -265,13 +294,15 @@ void fe_channels_init(void)
signal_add_last("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
- command_bind("wjoin", NULL, (SIGNAL_FUNC) cmd_wjoin);
+ command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_wjoin_pre);
+ command_bind_last("join", NULL, (SIGNAL_FUNC) cmd_wjoin_post);
command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel);
command_bind("channel add", NULL, (SIGNAL_FUNC) cmd_channel_add);
command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove);
command_bind("channel list", NULL, (SIGNAL_FUNC) cmd_channel_list);
command_set_options("channel add", "auto noauto -bots -botcmd");
+ command_set_options("join", "window");
}
void fe_channels_deinit(void)
@@ -282,7 +313,8 @@ void fe_channels_deinit(void)
signal_remove("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
- command_unbind("wjoin", (SIGNAL_FUNC) cmd_wjoin);
+ command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_pre);
+ command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_post);
command_unbind("channel", (SIGNAL_FUNC) cmd_channel);
command_unbind("channel add", (SIGNAL_FUNC) cmd_channel_add);
command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove);
diff --git a/src/fe-common/irc/fe-irc-commands.c b/src/fe-common/irc/fe-irc-commands.c
index d539ac70..260acbba 100644
--- a/src/fe-common/irc/fe-irc-commands.c
+++ b/src/fe-common/irc/fe-irc-commands.c
@@ -63,8 +63,11 @@ static void cmd_unquery(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *it
/* SYNTAX: QUERY <nick> */
static void cmd_query(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
+ GHashTable *optlist;
WINDOW_REC *window;
QUERY_REC *query;
+ char *nick;
+ void *free_arg;
g_return_if_fail(data != NULL);
@@ -74,21 +77,33 @@ static void cmd_query(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item
return;
}
- if (*data != '=' && (server == NULL || !server->connected))
- cmd_return_error(CMDERR_NOT_CONNECTED);
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+ "query", &optlist, &nick))
+ return;
+ if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+ server = irccmd_options_get_server("query", optlist, server);
+ if (server == NULL) {
+ cmd_params_free(free_arg);
+ return;
+ }
+
+ if (*nick != '=' && (server == NULL || !server->connected))
+ cmd_param_error(CMDERR_NOT_CONNECTED);
- query = query_find(server, data);
- if (query != NULL) {
+ query = query_find(server, nick);
+ if (query == NULL)
+ query_create(server, nick, FALSE);
+ else {
/* query already existed - change to query window */
window = window_item_window((WI_ITEM_REC *) query);
g_return_if_fail(window != NULL);
window_set_active(window);
window_item_set_active(window, (WI_ITEM_REC *) query);
- return;
}
- query_create(server, data, FALSE);
+ cmd_params_free(free_arg);
}
static void cmd_msg(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
@@ -109,7 +124,7 @@ static void cmd_msg(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
"msg", &optlist, &target, &msg))
return;
if (*target == '\0' || *msg == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- server = irccmd_options_get_server(optlist, server);
+ server = irccmd_options_get_server("msg", optlist, server);
if (*target == '=')
{
diff --git a/src/fe-common/irc/fe-query.c b/src/fe-common/irc/fe-query.c
index ee1505bd..6fe9bf64 100644
--- a/src/fe-common/irc/fe-query.c
+++ b/src/fe-common/irc/fe-query.c
@@ -129,11 +129,40 @@ static void cmd_window_server(const char *data)
}
}
-static void cmd_wquery(const char *data, void *server, WI_ITEM_REC *item)
+static void cmd_wquery_pre(const char *data)
{
- signal_add("query created", (SIGNAL_FUNC) signal_query_created_curwin);
- signal_emit("command query", 3, data, server, item);
- signal_remove("query created", (SIGNAL_FUNC) signal_query_created_curwin);
+ GHashTable *optlist;
+ char *nick;
+ void *free_arg;
+
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+ "query", &optlist, &nick))
+ return;
+
+ if (g_hash_table_lookup(optlist, "window") != NULL) {
+ signal_add("query created",
+ (SIGNAL_FUNC) signal_query_created_curwin);
+ }
+ cmd_params_free(free_arg);
+}
+
+static void cmd_wquery_post(const char *data)
+{
+ GHashTable *optlist;
+ char *nick;
+ void *free_arg;
+
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+ "query", &optlist, &nick))
+ return;
+
+ if (g_hash_table_lookup(optlist, "window") != NULL) {
+ signal_remove("query created",
+ (SIGNAL_FUNC) signal_query_created_curwin);
+ }
+ cmd_params_free(free_arg);
}
static int window_has_query(WINDOW_REC *window)
@@ -210,8 +239,11 @@ void fe_query_init(void)
signal_add("window changed", (SIGNAL_FUNC) sig_window_changed);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
- command_bind("wquery", NULL, (SIGNAL_FUNC) cmd_wquery);
+ command_bind_first("query", NULL, (SIGNAL_FUNC) cmd_wquery_pre);
+ command_bind_last("query", NULL, (SIGNAL_FUNC) cmd_wquery_post);
command_bind("window server", NULL, (SIGNAL_FUNC) cmd_window_server);
+
+ command_set_options("query", "window");
}
void fe_query_deinit(void)
@@ -225,6 +257,7 @@ void fe_query_deinit(void)
signal_remove("window changed", (SIGNAL_FUNC) sig_window_changed);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
- command_unbind("wquery", (SIGNAL_FUNC) cmd_wquery);
+ command_unbind("query", (SIGNAL_FUNC) cmd_wquery_pre);
+ command_unbind("query", (SIGNAL_FUNC) cmd_wquery_post);
command_unbind("window server", (SIGNAL_FUNC) cmd_window_server);
}
diff --git a/src/fe-common/irc/irc-completion.c b/src/fe-common/irc/irc-completion.c
index 5de5294d..91e7fecf 100644
--- a/src/fe-common/irc/irc-completion.c
+++ b/src/fe-common/irc/irc-completion.c
@@ -259,7 +259,7 @@ static void cmd_msg(const char *data, IRC_SERVER_REC *server)
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"msg", &optlist, &target, &msg))
return;
- server = irccmd_options_get_server(optlist, server);
+ server = irccmd_options_get_server("msg", optlist, server);
if (*target != '\0' && *msg != '\0') {
if (!ischannel(*target) && *target != '=' && server != NULL)
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c
index 323d922b..b067dda9 100644
--- a/src/irc/core/irc-commands.c
+++ b/src/irc/core/irc-commands.c
@@ -47,19 +47,33 @@ static int knockout_tag;
/* `optlist' should contain only one key - the server tag.
returns NULL if there was unknown -option */
-IRC_SERVER_REC *irccmd_options_get_server(GHashTable *optlist, IRC_SERVER_REC *defserver)
+IRC_SERVER_REC *irccmd_options_get_server(const char *cmd,
+ GHashTable *optlist,
+ IRC_SERVER_REC *defserver)
{
SERVER_REC *server;
- GSList *list;
+ GSList *list, *tmp, *next;
- /* -<server tag> */
+ /* get all the options, then remove the known ones. there should
+ be only one left - the server tag. */
list = hashtable_get_keys(optlist);
- if (list == NULL) return defserver;
+ for (tmp = list; tmp != NULL; tmp = next) {
+ char *option = tmp->data;
+ next = tmp->next;
+
+ if (command_have_option(cmd, option))
+ list = g_slist_remove(list, option);
+ }
+
+ if (list == NULL)
+ return defserver;
server = server_find_tag(list->data);
if (server == NULL || list->next != NULL) {
/* unknown option (not server tag) */
- signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN), list->data);
+ signal_emit("error command", 2,
+ GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN),
+ server == NULL ? list->data : list->next->data);
server = NULL;
}
@@ -244,7 +258,7 @@ static void cmd_msg(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
return;
if (*target == '\0' || *msg == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- server = irccmd_options_get_server(optlist, server);
+ server = irccmd_options_get_server("msg", optlist, server);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_param_error(CMDERR_NOT_CONNECTED);
@@ -349,7 +363,7 @@ static void cmd_join(const char *data, IRC_SERVER_REC *server)
channels_join(server, server->last_invite, FALSE);
} else {
/* -<server tag> */
- server = irccmd_options_get_server(optlist, server);
+ server = irccmd_options_get_server("join", optlist, server);
if (server != NULL) channels_join(server, channels, FALSE);
}
diff --git a/src/irc/core/irc-commands.h b/src/irc/core/irc-commands.h
index 6d4535a0..900a7765 100644
--- a/src/irc/core/irc-commands.h
+++ b/src/irc/core/irc-commands.h
@@ -3,6 +3,8 @@
/* `optlist' should contain only one key - the server tag.
returns NULL if there was unknown -option */
-IRC_SERVER_REC *irccmd_options_get_server(GHashTable *optlist, IRC_SERVER_REC *defserver);
+IRC_SERVER_REC *irccmd_options_get_server(const char *cmd,
+ GHashTable *optlist,
+ IRC_SERVER_REC *defserver);
#endif