summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2018-04-01 08:38:15 +0200
committerSébastien Helleu <flashcode@flashtux.org>2018-04-01 08:38:15 +0200
commit5314aa394a1dd3f8df4093891cb8f695dec5f3ef (patch)
tree82a9a3150b5766558985afa98c95c95e90d92f04 /src/plugins/irc
parentfc2395ca4f05ae0cf8072114f56eb92c89de3fc6 (diff)
downloadweechat-5314aa394a1dd3f8df4093891cb8f695dec5f3ef.zip
irc: add option "-server" in command /list (closes #1165)
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-command.c142
1 files changed, 71 insertions, 71 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index 8ab70a349..e879242d5 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -30,6 +30,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
+#include <regex.h>
#include "../weechat-plugin.h"
#include "irc.h"
@@ -2918,98 +2919,95 @@ IRC_COMMAND_CALLBACK(links)
IRC_COMMAND_CALLBACK(list)
{
char buf[512], *ptr_channel_name, *ptr_server_name, *ptr_regex;
+ regex_t *new_regexp;
int i, ret;
IRC_BUFFER_GET_SERVER(buffer);
- IRC_COMMAND_CHECK_SERVER("list", 1);
/* make C compiler happy */
(void) pointer;
(void) data;
- if (ptr_server->cmd_list_regexp)
+ ptr_channel_name = NULL;
+ ptr_server_name = NULL;
+ ptr_regex = NULL;
+ new_regexp = NULL;
+
+ for (i = 1; i < argc; i++)
{
- regfree (ptr_server->cmd_list_regexp);
- free (ptr_server->cmd_list_regexp);
- ptr_server->cmd_list_regexp = NULL;
+ if (weechat_strcasecmp (argv[i], "-server") == 0)
+ {
+ if (argc <= i + 1)
+ WEECHAT_COMMAND_ERROR;
+ ptr_server = irc_server_search (argv[i + 1]);
+ if (!ptr_server)
+ WEECHAT_COMMAND_ERROR;
+ i++;
+ }
+ else if (weechat_strcasecmp (argv[i], "-re") == 0)
+ {
+ if (argc <= i + 1)
+ WEECHAT_COMMAND_ERROR;
+ ptr_regex = argv_eol[i + 1];
+ i++;
+ }
+ else if (!ptr_channel_name)
+ ptr_channel_name = argv[i];
+ else if (!ptr_server_name)
+ ptr_server_name = argv[i];
+ else
+ WEECHAT_COMMAND_ERROR;
}
- if (argc > 1)
+ IRC_COMMAND_CHECK_SERVER("list", 1);
+
+ if (ptr_regex)
{
- ptr_channel_name = NULL;
- ptr_server_name = NULL;
- ptr_regex = NULL;
- for (i = 1; i < argc; i++)
+ new_regexp = malloc (sizeof (*new_regexp));
+ if (!new_regexp)
{
- if (weechat_strcasecmp (argv[i], "-re") == 0)
- {
- if (i < argc - 1)
- {
- ptr_regex = argv_eol[i + 1];
- i++;
- }
- }
- else
- {
- if (!ptr_channel_name)
- ptr_channel_name = argv[i];
- else if (!ptr_server_name)
- ptr_server_name = argv[i];
- }
+ weechat_printf (
+ ptr_server->buffer,
+ _("%s%s: not enough memory for regular expression"),
+ weechat_prefix ("error"), IRC_PLUGIN_NAME);
+ return WEECHAT_RC_OK;
}
- if (!ptr_channel_name && !ptr_server_name && !ptr_regex)
+ ret = weechat_string_regcomp (new_regexp,
+ ptr_regex,
+ REG_EXTENDED | REG_ICASE | REG_NOSUB);
+ if (ret != 0)
{
- irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
- "LIST");
+ regerror (ret, new_regexp, buf, sizeof (buf));
+ weechat_printf (
+ ptr_server->buffer,
+ _("%s%s: \"%s\" is not a valid regular expression "
+ "(%s)"),
+ weechat_prefix ("error"), IRC_PLUGIN_NAME,
+ ptr_regex, buf);
+ free (new_regexp);
+ return WEECHAT_RC_OK;
}
- else
+ if (ptr_server->cmd_list_regexp)
{
- if (ptr_regex)
- {
- ptr_server->cmd_list_regexp = malloc (
- sizeof (*ptr_server->cmd_list_regexp));
- if (ptr_server->cmd_list_regexp)
- {
- if ((ret = weechat_string_regcomp (
- ptr_server->cmd_list_regexp, ptr_regex,
- REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
- {
- regerror (ret, ptr_server->cmd_list_regexp,
- buf, sizeof (buf));
- weechat_printf (
- ptr_server->buffer,
- _("%s%s: \"%s\" is not a valid regular expression "
- "(%s)"),
- weechat_prefix ("error"), IRC_PLUGIN_NAME,
- argv_eol[1], buf);
- free (ptr_server->cmd_list_regexp);
- ptr_server->cmd_list_regexp = NULL;
- return WEECHAT_RC_OK;
- }
- }
- else
- {
- weechat_printf (
- ptr_server->buffer,
- _("%s%s: not enough memory for regular expression"),
- weechat_prefix ("error"), IRC_PLUGIN_NAME);
- return WEECHAT_RC_OK;
- }
- }
- irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
- "LIST%s%s%s%s",
- (ptr_channel_name) ? " " : "",
- (ptr_channel_name) ? ptr_channel_name : "",
- (ptr_server_name) ? " " : "",
- (ptr_server_name) ? ptr_server_name : "");
+ regfree (ptr_server->cmd_list_regexp);
+ free (ptr_server->cmd_list_regexp);
}
+ ptr_server->cmd_list_regexp = new_regexp;
}
- else
+ else if (ptr_server->cmd_list_regexp)
{
- irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
- "LIST");
+ regfree (ptr_server->cmd_list_regexp);
+ free (ptr_server->cmd_list_regexp);
+ ptr_server->cmd_list_regexp = NULL;
}
+ irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
+ "LIST%s%s%s%s",
+ (ptr_channel_name) ? " " : "",
+ (ptr_channel_name) ? ptr_channel_name : "",
+ (ptr_server_name) ? " " : "",
+ (ptr_server_name) ? ptr_server_name : "");
+
return WEECHAT_RC_OK;
}
@@ -6599,7 +6597,9 @@ irc_command_init ()
" list all channels beginning with \"#weechat\" (can be very slow "
"on large networks):\n"
" /list -re #weechat.*"),
- NULL, &irc_command_list, NULL, NULL);
+ "-server %(irc_servers)"
+ " || -re",
+ &irc_command_list, NULL, NULL);
weechat_hook_command (
"lusers",
N_("get statistics about the size of the IRC network"),