1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 17:23:15 +02:00

core: display a more explicit error when a filter fails to be added (closes #522)

This commit is contained in:
Sébastien Helleu
2015-09-09 09:22:40 +02:00
parent 145ec0db35
commit 8688c48e42
15 changed files with 319 additions and 139 deletions
+2 -15
View File
@@ -2184,14 +2184,6 @@ COMMAND_CALLBACK(filter)
if (string_strcasecmp (argv[1], "add") == 0)
{
COMMAND_MIN_ARGS(6, "add");
if (gui_filter_search_by_name (argv[2]))
{
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
_("%sError: filter \"%s\" already exists"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
argv[2]);
return WEECHAT_RC_OK;
}
if ((strcmp (argv[4], "*") == 0) && (strcmp (argv_eol[5], "*") == 0))
{
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
@@ -2201,7 +2193,8 @@ COMMAND_CALLBACK(filter)
return WEECHAT_RC_OK;
}
ptr_filter = gui_filter_new (1, argv[2], argv[3], argv[4], argv_eol[5]);
ptr_filter = gui_filter_new (1, argv[2], argv[3], argv[4],
argv_eol[5]);
if (ptr_filter)
{
gui_filter_all_buffers ();
@@ -2211,12 +2204,6 @@ COMMAND_CALLBACK(filter)
argv[2]);
command_filter_display (ptr_filter);
}
else
{
gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
_("%sError adding filter"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
}
return WEECHAT_RC_OK;
}
+47 -6
View File
@@ -38,6 +38,7 @@
#include "../plugins/plugin.h"
#include "gui-filter.h"
#include "gui-buffer.h"
#include "gui-chat.h"
#include "gui-line.h"
#include "gui-window.h"
@@ -253,6 +254,21 @@ gui_filter_search_by_name (const char *name)
return NULL;
}
/*
* Displays an error when a new filter is created.
*/
void
gui_filter_new_error (const char *name, const char *error)
{
gui_chat_printf_date_tags (
NULL, 0, GUI_FILTER_TAG_NO_FILTER,
_("%sError adding filter \"%s\": %s"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
(name) ? name : "",
error);
}
/*
* Creates a new filter.
*
@@ -265,15 +281,22 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name,
{
struct t_gui_filter *new_filter;
regex_t *regex1, *regex2;
char *pos_tab, *regex_prefix, **tags_array;
char *pos_tab, *regex_prefix, **tags_array, buf[512], str_error[512];
const char *ptr_start_regex, *pos_regex_message;
int i;
int i, rc;
if (!name || !buffer_name || !tags || !regex)
{
gui_filter_new_error (name, _("not enough arguments"));
return NULL;
}
if (gui_filter_search_by_name (name))
{
gui_filter_new_error (name,
_("a filter with same name already exists"));
return NULL;
}
ptr_start_regex = regex;
if ((ptr_start_regex[0] == '!')
@@ -305,9 +328,16 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name,
regex1 = malloc (sizeof (*regex1));
if (regex1)
{
if (string_regcomp (regex1, regex_prefix,
REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
rc = string_regcomp (regex1, regex_prefix,
REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (rc != 0)
{
regerror (rc, regex1, buf, sizeof (buf));
snprintf (str_error, sizeof (str_error),
/* TRANSLATORS: %s is the error returned by regerror */
_("invalid regular expression (%s)"),
buf);
gui_filter_new_error (name, str_error);
free (regex_prefix);
free (regex1);
return NULL;
@@ -320,9 +350,16 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name,
regex2 = malloc (sizeof (*regex2));
if (regex2)
{
if (string_regcomp (regex2, pos_regex_message,
REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
rc = string_regcomp (regex2, pos_regex_message,
REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (rc != 0)
{
regerror (rc, regex2, buf, sizeof (buf));
snprintf (str_error, sizeof (str_error),
/* TRANSLATORS: %s is the error returned by regerror */
_("invalid regular expression (%s)"),
buf);
gui_filter_new_error (name, str_error);
if (regex_prefix)
free (regex_prefix);
if (regex1)
@@ -390,6 +427,10 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name,
(void) hook_signal_send ("filter_added",
WEECHAT_HOOK_SIGNAL_POINTER, new_filter);
}
else
{
gui_filter_new_error (name, _("not enough memory"));
}
return new_filter;
}