From 7103fc87b804624379a4dff884d671a73c1af47c Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 21 Feb 2001 18:41:45 +0000 Subject: /FOREACH server|channel|query|window git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1276 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/chat-commands.c | 49 ++++++++++++++++++++++++++++++++++++ src/fe-common/core/window-commands.c | 19 ++++++++++++++ 2 files changed, 68 insertions(+) (limited to 'src') diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c index 5e0be456..94d65e0e 100644 --- a/src/core/chat-commands.c +++ b/src/core/chat-commands.c @@ -29,6 +29,8 @@ #include "servers.h" #include "servers-setup.h" #include "servers-reconnect.h" +#include "channels.h" +#include "queries.h" #include "window-item-def.h" static SERVER_CONNECT_REC *get_server_connect(const char *data, int *plus_addr) @@ -316,6 +318,45 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) cmd_params_free(free_arg); } +static void cmd_foreach(const char *data, SERVER_REC *server, + WI_ITEM_REC *item) +{ + command_runsub("foreach", data, server, item); +} + +/* SYNTAX: FOREACH SERVER */ +static void cmd_foreach_server(const char *data, SERVER_REC *server) +{ + GSList *tmp; + + for (tmp = servers; tmp != NULL; tmp = tmp->next) + signal_emit("send command", 3, data, tmp->data, NULL); +} + +/* SYNTAX: FOREACH CHANNEL */ +static void cmd_foreach_channel(const char *data) +{ + GSList *tmp; + + for (tmp = channels; tmp != NULL; tmp = tmp->next) { + CHANNEL_REC *rec = tmp->data; + + signal_emit("send command", 3, data, rec->server, rec); + } +} + +/* SYNTAX: FOREACH QUERY */ +static void cmd_foreach_query(const char *data) +{ + GSList *tmp; + + for (tmp = queries; tmp != NULL; tmp = tmp->next) { + QUERY_REC *rec = tmp->data; + + signal_emit("send command", 3, data, rec->server, rec); + } +} + void chat_commands_init(void) { command_bind("server", NULL, (SIGNAL_FUNC) cmd_server); @@ -324,6 +365,10 @@ void chat_commands_init(void) command_bind("quit", NULL, (SIGNAL_FUNC) cmd_quit); command_bind("join", NULL, (SIGNAL_FUNC) cmd_join); command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg); + command_bind("foreach", NULL, (SIGNAL_FUNC) cmd_foreach); + command_bind("foreach server", NULL, (SIGNAL_FUNC) cmd_foreach_server); + command_bind("foreach channel", NULL, (SIGNAL_FUNC) cmd_foreach_channel); + command_bind("foreach query", NULL, (SIGNAL_FUNC) cmd_foreach_query); command_set_options("connect", "4 6 +host"); command_set_options("join", "invite"); @@ -337,4 +382,8 @@ void chat_commands_deinit(void) command_unbind("quit", (SIGNAL_FUNC) cmd_quit); command_unbind("join", (SIGNAL_FUNC) cmd_join); command_unbind("msg", (SIGNAL_FUNC) cmd_msg); + command_unbind("foreach", (SIGNAL_FUNC) cmd_foreach); + command_unbind("foreach server", (SIGNAL_FUNC) cmd_foreach_server); + command_unbind("foreach channel", (SIGNAL_FUNC) cmd_foreach_channel); + command_unbind("foreach query", (SIGNAL_FUNC) cmd_foreach_query); } diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index e2e43039..049d74e1 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -454,6 +454,23 @@ static void cmd_savewindows(void) windows_save(); } +/* SYNTAX: FOREACH WINDOW */ +static void cmd_foreach_window(const char *data) +{ + WINDOW_REC *old; + GSList *tmp; + + old = active_win; + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + WINDOW_REC *rec = tmp->data; + + active_win = rec; + signal_emit("send command", 3, data, rec->active_server, + rec->active); + } + active_win = old; +} + void window_commands_init(void) { command_bind("window", NULL, (SIGNAL_FUNC) cmd_window); @@ -480,6 +497,7 @@ void window_commands_init(void) command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list); command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme); command_bind("savewindows", NULL, (SIGNAL_FUNC) cmd_savewindows); + command_bind("foreach window", NULL, (SIGNAL_FUNC) cmd_foreach_window); command_set_options("window number", "sticky"); command_set_options("window server", "sticky unsticky"); @@ -511,4 +529,5 @@ void window_commands_deinit(void) command_unbind("window list", (SIGNAL_FUNC) cmd_window_list); command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme); command_unbind("savewindows", (SIGNAL_FUNC) cmd_savewindows); + command_unbind("foreach window", (SIGNAL_FUNC) cmd_foreach_window); } -- cgit v1.2.3