summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-hook.c5
-rw-r--r--src/core/wee-string.c10
-rw-r--r--src/core/wee-string.h1
-rw-r--r--src/core/weechat.h2
-rw-r--r--src/gui/curses/gui-curses-chat.c2
-rw-r--r--src/gui/gui-buffer.c2
-rw-r--r--src/gui/gui-chat.c12
-rw-r--r--src/gui/gui-color.c111
-rw-r--r--src/gui/gui-color.h2
-rw-r--r--src/plugins/plugin.c3
-rw-r--r--src/plugins/scripts/lua/weechat-lua-api.c9
-rw-r--r--src/plugins/scripts/perl/weechat-perl-api.c7
-rw-r--r--src/plugins/scripts/python/weechat-python-api.c7
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby-api.c14
-rw-r--r--src/plugins/scripts/tcl/weechat-tcl-api.c7
-rw-r--r--src/plugins/weechat-plugin.h6
16 files changed, 113 insertions, 87 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 41a38f245..2cc7dc010 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -1372,10 +1372,9 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line)
if (!line->message || !line->message[0])
return;
- prefix_no_color = (line->prefix) ?
- (char *)gui_color_decode ((unsigned char *)line->prefix) : NULL;
+ prefix_no_color = (line->prefix) ? gui_color_decode (line->prefix, NULL) : NULL;
- message_no_color = (char *)gui_color_decode ((unsigned char *)line->message);
+ message_no_color = gui_color_decode (line->message, NULL);
if (!message_no_color)
{
free (prefix_no_color);
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 85742f9a9..6d42c1387 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -1309,13 +1309,3 @@ string_format_size (unsigned long size)
return strdup (str_size);
}
-
-/*
- * string_remove_color: remove WeeChat color codes in string
- */
-
-char *
-string_remove_color (const char *string)
-{
- return (char *)gui_color_decode ((unsigned char *)string);
-}
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index 6a0ca4b9f..b4dde55d9 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -56,6 +56,5 @@ extern char *string_iconv_from_internal (const char *charset,
const char *string);
extern void string_iconv_fprintf (FILE *file, const char *data, ...);
extern char *string_format_size (unsigned long size);
-extern char *string_remove_color (const char *string);
#endif /* wee-string.h */
diff --git a/src/core/weechat.h b/src/core/weechat.h
index 8801eacc5..5c4ebcf88 100644
--- a/src/core/weechat.h
+++ b/src/core/weechat.h
@@ -51,7 +51,7 @@
#define WEECHAT_COPYRIGHT_DATE "(c) 2003-2009"
-#define WEECHAT_WEBSITE "http://weechat.flashtux.org"
+#define WEECHAT_WEBSITE "http://weechat.flashtux.org/"
/* log file */
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index c89f23186..ab77d7c57 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -597,7 +597,7 @@ gui_chat_display_time_and_prefix (struct t_gui_window *window,
prefix_highlighted = NULL;
if (line->highlight)
{
- prefix_highlighted = (char *)gui_color_decode ((unsigned char *)line->prefix);
+ prefix_highlighted = gui_color_decode (line->prefix, NULL);
if (!simulate)
{
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 84aeb528e..27c363442 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -1699,7 +1699,7 @@ gui_buffer_dump_hexa (struct t_gui_buffer *buffer)
{
/* display line without colors */
message_without_colors = (ptr_line->message) ?
- (char *)gui_color_decode ((unsigned char *)ptr_line->message) : NULL;
+ gui_color_decode (ptr_line->message, NULL) : NULL;
log_printf ("");
log_printf (" line %d: %s",
num_line,
diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c
index 29b96b667..5b6a1fac2 100644
--- a/src/gui/gui-chat.c
+++ b/src/gui/gui-chat.c
@@ -507,7 +507,7 @@ gui_chat_line_search (struct t_gui_line *line, const char *text,
if (line->prefix)
{
- prefix = (char *)gui_color_decode ((unsigned char *)line->prefix);
+ prefix = gui_color_decode (line->prefix, NULL);
if (prefix)
{
if ((case_sensitive && (strstr (prefix, text)))
@@ -519,7 +519,7 @@ gui_chat_line_search (struct t_gui_line *line, const char *text,
if (!rc)
{
- message = (char *)gui_color_decode ((unsigned char *)line->message);
+ message = gui_color_decode (line->message, NULL);
if (message)
{
if ((case_sensitive && (strstr (message, text)))
@@ -555,7 +555,7 @@ gui_chat_line_match_regex (struct t_gui_line *line, regex_t *regex_prefix,
if (line->prefix)
{
- prefix = (char *)gui_color_decode ((unsigned char *)line->prefix);
+ prefix = gui_color_decode (line->prefix, NULL);
if (!prefix
|| (regex_prefix && (regexec (regex_prefix, prefix, 0, NULL, 0) != 0)))
match_prefix = 0;
@@ -568,7 +568,7 @@ gui_chat_line_match_regex (struct t_gui_line *line, regex_t *regex_prefix,
if (line->message)
{
- message = (char *)gui_color_decode ((unsigned char *)line->message);
+ message = gui_color_decode (line->message, NULL);
if (!message
|| (regex_message && (regexec (regex_message, message, 0, NULL, 0) != 0)))
match_message = 0;
@@ -654,7 +654,7 @@ gui_chat_line_has_highlight (struct t_gui_buffer *buffer,
}
/* remove color codes from line message */
- msg_no_color = (char *)gui_color_decode ((unsigned char *)line->message);
+ msg_no_color = gui_color_decode (line->message, NULL);
if (!msg_no_color)
return 0;
@@ -803,7 +803,7 @@ gui_chat_build_string_prefix_message (struct t_gui_line *line)
if (string)
{
- string_without_colors = (char *)gui_color_decode ((unsigned char *)string);
+ string_without_colors = gui_color_decode (string, NULL);
if (string_without_colors)
{
free (string);
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index 3766dc217..66795d5c5 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -227,12 +227,18 @@ gui_color_get_custom (const char *color_name)
/*
* gui_color_decode: parses a message and remove WeeChat color codes
+ * if replacement is not NULL and not empty, it is used to
+ * replace color codes by first char of replacement (and
+ * next chars in string are NOT removed)
+ * if replacement is NULL or empty, color codes are removed,
+ * with following chars if they are related to color code
* After use, string returned has to be free()
*/
-unsigned char *
-gui_color_decode (const unsigned char *string)
+char *
+gui_color_decode (const char *string, const char *replacement)
{
+ const unsigned char *ptr_string;
unsigned char *out;
int out_length, out_pos, length;
@@ -244,65 +250,88 @@ gui_color_decode (const unsigned char *string)
if (!out)
return NULL;
+ ptr_string = (unsigned char *)string;
out_pos = 0;
- while (string && string[0] && (out_pos < out_length - 1))
+ while (ptr_string && ptr_string[0] && (out_pos < out_length - 1))
{
- switch (string[0])
+ switch (ptr_string[0])
{
case GUI_COLOR_COLOR_CHAR:
- string++;
- switch (string[0])
+ ptr_string++;
+ if (replacement && replacement[0])
{
- case GUI_COLOR_FG_CHAR:
- case GUI_COLOR_BG_CHAR:
- if (string[1] && string[2])
- string += 3;
- break;
- case GUI_COLOR_FG_BG_CHAR:
- if (string[1] && string[2] && (string[3] == ',')
- && string[4] && string[5])
- string += 6;
- break;
- case GUI_COLOR_BAR_CHAR:
- string++;
- switch (string[0])
- {
- case GUI_COLOR_BAR_FG_CHAR:
- case GUI_COLOR_BAR_BG_CHAR:
- case GUI_COLOR_BAR_DELIM_CHAR:
- case GUI_COLOR_BAR_START_INPUT_CHAR:
- case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
- string++;
- break;
- }
- break;
- default:
- if (isdigit (string[0]) && isdigit (string[1]))
- string += 2;
- break;
+ out[out_pos] = replacement[0];
+ out_pos++;
+ }
+ else
+ {
+ switch (ptr_string[0])
+ {
+ case GUI_COLOR_FG_CHAR:
+ case GUI_COLOR_BG_CHAR:
+ if (ptr_string[1] && ptr_string[2])
+ ptr_string += 3;
+ break;
+ case GUI_COLOR_FG_BG_CHAR:
+ if (ptr_string[1] && ptr_string[2] && (ptr_string[3] == ',')
+ && ptr_string[4] && ptr_string[5])
+ ptr_string += 6;
+ break;
+ case GUI_COLOR_BAR_CHAR:
+ ptr_string++;
+ switch (ptr_string[0])
+ {
+ case GUI_COLOR_BAR_FG_CHAR:
+ case GUI_COLOR_BAR_BG_CHAR:
+ case GUI_COLOR_BAR_DELIM_CHAR:
+ case GUI_COLOR_BAR_START_INPUT_CHAR:
+ case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
+ ptr_string++;
+ break;
+ }
+ break;
+ default:
+ if (isdigit (ptr_string[0]) && isdigit (ptr_string[1]))
+ ptr_string += 2;
+ break;
+ }
}
break;
case GUI_COLOR_SET_WEECHAT_CHAR:
case GUI_COLOR_REMOVE_WEECHAT_CHAR:
- string++;
- if (string[0])
- string++;
+ ptr_string++;
+ if (replacement && replacement[0])
+ {
+ out[out_pos] = replacement[0];
+ out_pos++;
+ }
+ else
+ {
+ if (ptr_string[0])
+ ptr_string++;
+ }
break;
case GUI_COLOR_RESET_CHAR:
- string++;
+ ptr_string++;
+ if (replacement && replacement[0])
+ {
+ out[out_pos] = replacement[0];
+ out_pos++;
+ }
break;
default:
- length = utf8_char_size ((char *)string);
+ length = utf8_char_size ((char *)ptr_string);
if (length == 0)
length = 1;
- memcpy (out + out_pos, string, length);
+ memcpy (out + out_pos, ptr_string, length);
out_pos += length;
- string += length;
+ ptr_string += length;
break;
}
}
out[out_pos] = '\0';
- return out;
+
+ return (char *)out;
}
/*
diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h
index 508ba7a12..602dd9f3b 100644
--- a/src/gui/gui-color.h
+++ b/src/gui/gui-color.h
@@ -126,7 +126,7 @@ extern struct t_gui_color *gui_color[];
extern int gui_color_search_config_int (const char *color_name);
extern const char *gui_color_get_custom (const char *color_name);
-extern unsigned char *gui_color_decode (const unsigned char *string);
+extern char *gui_color_decode (const char *string, const char *replacement);
extern void gui_color_free (struct t_gui_color *color);
/* color functions (GUI dependent) */
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 4e92d3d77..40f6a8f76 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -48,6 +48,7 @@
#include "../gui/gui-bar-item.h"
#include "../gui/gui-buffer.h"
#include "../gui/gui-chat.h"
+#include "../gui/gui-color.h"
#include "../gui/gui-nicklist.h"
#include "../gui/gui-window.h"
#include "plugin.h"
@@ -412,7 +413,7 @@ plugin_load (const char *filename)
new_plugin->string_split_command = &string_split_command;
new_plugin->string_free_splitted_command = &string_free_splitted_command;
new_plugin->string_format_size = &string_format_size;
- new_plugin->string_remove_color = &string_remove_color;
+ new_plugin->string_remove_color = &gui_color_decode;
new_plugin->utf8_has_8bits = &utf8_has_8bits;
new_plugin->utf8_is_valid = &utf8_is_valid;
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c
index 0f0d50fa8..9271d9ce4 100644
--- a/src/plugins/scripts/lua/weechat-lua-api.c
+++ b/src/plugins/scripts/lua/weechat-lua-api.c
@@ -371,7 +371,7 @@ weechat_lua_api_ngettext (lua_State *L)
static int
weechat_lua_api_string_remove_color (lua_State *L)
{
- const char *string;
+ const char *string, *replacement;
char *result;
int n;
@@ -388,15 +388,16 @@ weechat_lua_api_string_remove_color (lua_State *L)
n = lua_gettop (lua_current_interpreter);
- if (n < 1)
+ if (n < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
LUA_RETURN_EMPTY;
}
- string = lua_tostring (lua_current_interpreter, -1);
+ string = lua_tostring (lua_current_interpreter, -2);
+ replacement = lua_tostring (lua_current_interpreter, -1);
- result = weechat_string_remove_color (string);
+ result = weechat_string_remove_color (string, replacement);
LUA_RETURN_STRING_FREE(result);
}
diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c
index e38361d65..2a3ef2815 100644
--- a/src/plugins/scripts/perl/weechat-perl-api.c
+++ b/src/plugins/scripts/perl/weechat-perl-api.c
@@ -316,7 +316,7 @@ static XS (XS_weechat_api_ngettext)
static XS (XS_weechat_api_string_remove_color)
{
- char *result, *string;
+ char *result, *string, *replacement;
dXSARGS;
/* make C compiler happy */
@@ -328,14 +328,15 @@ static XS (XS_weechat_api_string_remove_color)
PERL_RETURN_EMPTY;
}
- if (items < 1)
+ if (items < 2)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
PERL_RETURN_EMPTY;
}
string = SvPV (ST (0), PL_na);
- result = weechat_string_remove_color (string);
+ replacement = SvPV (ST (1), PL_na);
+ result = weechat_string_remove_color (string, replacement);
PERL_RETURN_STRING_FREE(result);
}
diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c
index 76f580ee3..4f0d3a8d5 100644
--- a/src/plugins/scripts/python/weechat-python-api.c
+++ b/src/plugins/scripts/python/weechat-python-api.c
@@ -324,7 +324,7 @@ weechat_python_api_ngettext (PyObject *self, PyObject *args)
static PyObject *
weechat_python_api_string_remove_color (PyObject *self, PyObject *args)
{
- char *string, *result;
+ char *string, *replacement, *result;
PyObject *object;
/* make C compiler happy */
@@ -337,14 +337,15 @@ weechat_python_api_string_remove_color (PyObject *self, PyObject *args)
}
string = NULL;
+ replacement = NULL;
- if (!PyArg_ParseTuple (args, "s", &string))
+ if (!PyArg_ParseTuple (args, "ss", &string, &replacement))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
PYTHON_RETURN_EMPTY;
}
- result = weechat_string_remove_color (string);
+ result = weechat_string_remove_color (string, replacement);
PYTHON_RETURN_STRING_FREE(result);
}
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c
index 86ec14ef4..bf150363a 100644
--- a/src/plugins/scripts/ruby/weechat-ruby-api.c
+++ b/src/plugins/scripts/ruby/weechat-ruby-api.c
@@ -372,9 +372,10 @@ weechat_ruby_api_ngettext (VALUE class, VALUE single, VALUE plural,
*/
static VALUE
-weechat_ruby_api_string_remove_color (VALUE class, VALUE string)
+weechat_ruby_api_string_remove_color (VALUE class, VALUE string,
+ VALUE replacement)
{
- char *c_string, *result;
+ char *c_string, *c_replacement, *result;
VALUE return_value;
/* make C compiler happy */
@@ -387,18 +388,21 @@ weechat_ruby_api_string_remove_color (VALUE class, VALUE string)
}
c_string = NULL;
+ c_replacement = NULL;
- if (NIL_P (string))
+ if (NIL_P (string) || NIL_P (replacement))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
RUBY_RETURN_EMPTY;
}
Check_Type (string, T_STRING);
+ Check_Type (replacement, T_STRING);
c_string = STR2CSTR (string);
+ c_replacement = STR2CSTR (replacement);
- result = weechat_string_remove_color (c_string);
+ result = weechat_string_remove_color (c_string, c_replacement);
RUBY_RETURN_STRING_FREE(result);
}
@@ -6580,7 +6584,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "iconv_from_internal", &weechat_ruby_api_iconv_from_internal, 2);
rb_define_module_function (ruby_mWeechat, "gettext", &weechat_ruby_api_gettext, 1);
rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3);
- rb_define_module_function (ruby_mWeechat, "string_remove_color", &weechat_ruby_api_string_remove_color, 1);
+ rb_define_module_function (ruby_mWeechat, "string_remove_color", &weechat_ruby_api_string_remove_color, 2);
rb_define_module_function (ruby_mWeechat, "mkdir_home", &weechat_ruby_api_mkdir_home, 2);
rb_define_module_function (ruby_mWeechat, "mkdir", &weechat_ruby_api_mkdir, 2);
rb_define_module_function (ruby_mWeechat, "mkdir_parents", &weechat_ruby_api_mkdir_parents, 2);
diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c
index 60ede1b70..790122dad 100644
--- a/src/plugins/scripts/tcl/weechat-tcl-api.c
+++ b/src/plugins/scripts/tcl/weechat-tcl-api.c
@@ -443,7 +443,7 @@ weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj* objp;
- char *result, *string;
+ char *result, *replacement, *string;
int i;
/* make C compiler happy */
@@ -455,14 +455,15 @@ weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp,
TCL_RETURN_EMPTY;
}
- if (objc < 2)
+ if (objc < 3)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("string_remove_color");
TCL_RETURN_EMPTY;
}
string = Tcl_GetStringFromObj (objv[1], &i);
- result = weechat_string_remove_color (string);
+ replacement = Tcl_GetStringFromObj (objv[2], &i);
+ result = weechat_string_remove_color (string, replacement);
TCL_RETURN_STRING_FREE(result);
}
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index ffbb3dec1..96c1e79d7 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -167,7 +167,7 @@ struct t_weechat_plugin
char **(*string_split_command) (const char *command, char separator);
void (*string_free_splitted_command) (char **splitted_command);
char *(*string_format_size) (unsigned long size);
- char *(*string_remove_color) (const char *string);
+ char *(*string_remove_color) (const char *string, const char *replacement);
/* UTF-8 strings */
int (*utf8_has_8bits) (const char *string);
@@ -694,8 +694,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->string_free_splitted_command(__splitted_command)
#define weechat_string_format_size(__size) \
weechat_plugin->string_format_size(__size)
-#define weechat_string_remove_color(__string) \
- weechat_plugin->string_remove_color(__string)
+#define weechat_string_remove_color(__string, __replacement) \
+ weechat_plugin->string_remove_color(__string, __replacement)
/* UTF-8 strings */
#define weechat_utf8_has_8bits(__string) \