summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hook/wee-hook-hsignal.c2
-rw-r--r--src/core/hook/wee-hook-line.c2
-rw-r--r--src/core/hook/wee-hook-signal.c2
-rw-r--r--src/core/wee-command.c2
-rw-r--r--src/core/wee-config-file.c2
-rw-r--r--src/core/wee-dir.c2
-rw-r--r--src/core/wee-input.c2
-rw-r--r--src/core/wee-string.c41
-rw-r--r--src/core/wee-string.h3
-rw-r--r--src/gui/gui-buffer.c6
-rw-r--r--src/gui/gui-filter.c3
-rw-r--r--src/gui/gui-focus.c3
-rw-r--r--src/plugins/fset/fset-option.c2
-rw-r--r--src/plugins/guile/weechat-guile-api.c2
-rw-r--r--src/plugins/irc/irc-mode.c2
-rw-r--r--src/plugins/javascript/weechat-js-api.cpp2
-rw-r--r--src/plugins/lua/weechat-lua-api.c2
-rw-r--r--src/plugins/perl/weechat-perl-api.c2
-rw-r--r--src/plugins/python/weechat-python-api.c2
-rw-r--r--src/plugins/ruby/weechat-ruby-api.c2
-rw-r--r--src/plugins/tcl/weechat-tcl-api.c2
-rw-r--r--src/plugins/trigger/trigger-callback.c2
-rw-r--r--src/plugins/weechat-plugin.h13
23 files changed, 66 insertions, 37 deletions
diff --git a/src/core/hook/wee-hook-hsignal.c b/src/core/hook/wee-hook-hsignal.c
index 37dfa32a8..505336688 100644
--- a/src/core/hook/wee-hook-hsignal.c
+++ b/src/core/hook/wee-hook-hsignal.c
@@ -44,7 +44,7 @@ char *
hook_hsignal_get_description (struct t_hook *hook)
{
return string_rebuild_split_string (
- (const char **)(HOOK_HSIGNAL(hook, signals)), ";");
+ (const char **)(HOOK_HSIGNAL(hook, signals)), ";", 0, -1);
}
/*
diff --git a/src/core/hook/wee-hook-line.c b/src/core/hook/wee-hook-line.c
index fa787eba1..00bd7f138 100644
--- a/src/core/hook/wee-hook-line.c
+++ b/src/core/hook/wee-hook-line.c
@@ -167,7 +167,7 @@ hook_line_exec (struct t_gui_line *line)
HASHTABLE_SET_STR_NOT_NULL("str_time", line->data->str_time);
HASHTABLE_SET_INT("tags_count", line->data->tags_count);
str_tags = string_rebuild_split_string (
- (const char **)line->data->tags_array, ",");
+ (const char **)line->data->tags_array, ",", 0, -1);
HASHTABLE_SET_STR_NOT_NULL("tags", str_tags);
if (str_tags)
free (str_tags);
diff --git a/src/core/hook/wee-hook-signal.c b/src/core/hook/wee-hook-signal.c
index 9cd72efcb..f08f20550 100644
--- a/src/core/hook/wee-hook-signal.c
+++ b/src/core/hook/wee-hook-signal.c
@@ -44,7 +44,7 @@ char *
hook_signal_get_description (struct t_hook *hook)
{
return string_rebuild_split_string (
- (const char **)(HOOK_SIGNAL(hook, signals)), ";");
+ (const char **)(HOOK_SIGNAL(hook, signals)), ";", 0, -1);
}
/*
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index a34ef109d..5006b67be 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -5583,7 +5583,7 @@ COMMAND_CALLBACK(repeat)
repeat_args[1] = strdup (argv_eol[arg_count + 1]);
repeat_args[2] = (input_commands_allowed) ?
string_rebuild_split_string (
- (const char **)input_commands_allowed, ",") : NULL;
+ (const char **)input_commands_allowed, ",", 0, -1) : NULL;
hook_timer (NULL, interval, 0, count - 1,
&command_repeat_timer_cb, repeat_args, NULL);
}
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c
index 68a1d457a..297c20b6b 100644
--- a/src/core/wee-config-file.c
+++ b/src/core/wee-config-file.c
@@ -3388,7 +3388,7 @@ config_file_add_option_to_infolist (struct t_infolist *infolist,
goto error;
}
string_values = string_rebuild_split_string (
- (const char **)option->string_values, "|");
+ (const char **)option->string_values, "|", 0, -1);
if (!infolist_new_var_string (ptr_item, "string_values", string_values))
{
if (string_values)
diff --git a/src/core/wee-dir.c b/src/core/wee-dir.c
index e0a0a7361..7a0b702e0 100644
--- a/src/core/wee-dir.c
+++ b/src/core/wee-dir.c
@@ -1036,5 +1036,5 @@ dir_get_string_home_dirs ()
dirs[3] = weechat_runtime_dir;
dirs[4] = NULL;
- return string_rebuild_split_string ((const char **)dirs, ":");
+ return string_rebuild_split_string ((const char **)dirs, ":", 0, -1);
}
diff --git a/src/core/wee-input.c b/src/core/wee-input.c
index 3635ffce4..e635e8dfc 100644
--- a/src/core/wee-input.c
+++ b/src/core/wee-input.c
@@ -428,7 +428,7 @@ input_data_delayed (struct t_gui_buffer *buffer, const char *data,
else if (input_commands_allowed)
{
new_commands_allowed = string_rebuild_split_string (
- (const char **)input_commands_allowed, ",");
+ (const char **)input_commands_allowed, ",", 0, -1);
}
else
{
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 7d27ab367..e0f3af037 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -2445,39 +2445,58 @@ string_free_split_shared (char **split_string)
}
/*
- * Rebuilds a split string using a delimiter.
+ * Rebuilds a split string using a delimiter and optional index of start/end
+ * string.
+ *
+ * If index_end < 0, then all arguments are used until NULL is found.
+ * If NULL is found before index_end, then the build stops there (at NULL).
*
* Note: result must be free after use.
*/
char *
string_rebuild_split_string (const char **split_string,
- const char *separator)
+ const char *separator,
+ int index_start, int index_end)
{
int i, length, length_separator;
char *result;
- if (!split_string)
+ if (!split_string || (index_start < 0)
+ || ((index_end >= 0) && (index_end < index_start)))
+ {
return NULL;
+ }
length = 0;
length_separator = (separator) ? strlen (separator) : 0;
for (i = 0; split_string[i]; i++)
{
- length += strlen (split_string[i]) + length_separator;
+ if ((index_end >= 0) && (i > index_end))
+ break;
+ if (i >= index_start)
+ length += strlen (split_string[i]) + length_separator;
}
+ if (length == 0)
+ return strdup ("");
+
result = malloc (length + 1);
- if (result)
- {
- result[0] = '\0';
+ if (!result)
+ return NULL;
- for (i = 0; split_string[i]; i++)
+ result[0] = '\0';
+
+ for (i = index_start; split_string[i]; i++)
+ {
+ if ((index_end >= 0) && (i > index_end))
+ break;
+ strcat (result, split_string[i]);
+ if (separator && ((index_end < 0) || (i + 1 <= index_end))
+ && split_string[i + 1])
{
- strcat (result, split_string[i]);
- if (separator && split_string[i + 1])
- strcat (result, separator);
+ strcat (result, separator);
}
}
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index 450829db1..abf65b8c1 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -97,7 +97,8 @@ extern char **string_split_shell (const char *string, int *num_items);
extern void string_free_split (char **split_string);
extern void string_free_split_shared (char **split_string);
extern char *string_rebuild_split_string (const char **split_string,
- const char *separator);
+ const char *separator,
+ int index_start, int index_end);
extern char **string_split_command (const char *command, char separator);
extern void string_free_split_command (char **split_command);
extern char ***string_split_tags (const char *tags, int *num_tags);
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index cb9c46562..889b86a6b 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -4703,7 +4703,8 @@ gui_buffer_dump_hexa (struct t_gui_buffer *buffer)
if (message_without_colors)
free (message_without_colors);
tags = string_rebuild_split_string ((const char **)ptr_line->data->tags_array,
- ",");
+ ",",
+ 0, -1);
log_printf (" tags: '%s', displayed: %d, highlight: %d",
(tags) ? tags : "(none)",
ptr_line->data->displayed,
@@ -4921,7 +4922,8 @@ gui_buffer_print_log ()
{
num--;
tags = string_rebuild_split_string ((const char **)ptr_line->data->tags_array,
- ",");
+ ",",
+ 0, -1);
log_printf (" line N-%05d: y:%d, str_time:'%s', tags:'%s', "
"displayed:%d, highlight:%d, refresh_needed:%d, "
"prefix:'%s'",
diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c
index e5d877706..356770879 100644
--- a/src/gui/gui-filter.c
+++ b/src/gui/gui-filter.c
@@ -593,7 +593,8 @@ gui_filter_add_to_infolist (struct t_infolist *infolist,
{
snprintf (option_name, sizeof (option_name), "tag_%05d", i + 1);
tags = string_rebuild_split_string ((const char **)filter->tags_array[i],
- "+");
+ "+",
+ 0, -1);
if (tags)
{
if (!infolist_new_var_string (ptr_item, option_name, tags))
diff --git a/src/gui/gui-focus.c b/src/gui/gui-focus.c
index a57b5a7a9..3e57a0408 100644
--- a/src/gui/gui-focus.c
+++ b/src/gui/gui-focus.c
@@ -201,7 +201,8 @@ gui_focus_to_hashtable (struct t_gui_focus_info *focus_info, const char *key)
{
str_time = gui_color_decode (((focus_info->chat_line)->data)->str_time, NULL);
str_prefix = gui_color_decode (((focus_info->chat_line)->data)->prefix, NULL);
- str_tags = string_rebuild_split_string ((const char **)((focus_info->chat_line)->data)->tags_array, ",");
+ str_tags = string_rebuild_split_string (
+ (const char **)((focus_info->chat_line)->data)->tags_array, ",", 0, -1);
str_message = gui_color_decode (((focus_info->chat_line)->data)->message, NULL);
nick = gui_line_get_nick_tag (focus_info->chat_line);
HASHTABLE_SET_POINTER("_chat_line", focus_info->chat_line);
diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c
index ce2a02a0e..2ee03a7b9 100644
--- a/src/plugins/fset/fset-option.c
+++ b/src/plugins/fset/fset-option.c
@@ -571,7 +571,7 @@ fset_option_set_values (struct t_fset_option *fset_option,
if (ptr_string_values)
{
fset_option->string_values = weechat_string_rebuild_split_string (
- ptr_string_values, ",");
+ ptr_string_values, ",", 0, -1);
}
else
{
diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c
index 5d1309990..e847f6167 100644
--- a/src/plugins/guile/weechat-guile-api.c
+++ b/src/plugins/guile/weechat-guile-api.c
@@ -2601,7 +2601,7 @@ weechat_guile_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c
index 7174bce24..4fe3f7187 100644
--- a/src/plugins/irc/irc-mode.c
+++ b/src/plugins/irc/irc-mode.c
@@ -69,7 +69,7 @@ irc_mode_get_arguments (const char *arguments)
argv2[argc] = NULL;
new_arguments = weechat_string_rebuild_split_string (
- (const char **)argv2, " ");
+ (const char **)argv2, " ", 0, -1);
weechat_string_free_split (argv);
free (argv2);
diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp
index 8c0e95b6c..271108387 100644
--- a/src/plugins/javascript/weechat-js-api.cpp
+++ b/src/plugins/javascript/weechat-js-api.cpp
@@ -2521,7 +2521,7 @@ weechat_js_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index fdbe2ed13..678061137 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -2736,7 +2736,7 @@ weechat_lua_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c
index c3b70d5cf..895730620 100644
--- a/src/plugins/perl/weechat-perl-api.c
+++ b/src/plugins/perl/weechat-perl-api.c
@@ -2631,7 +2631,7 @@ weechat_perl_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c
index dbbe6d1e0..3bacf63f7 100644
--- a/src/plugins/python/weechat-python-api.c
+++ b/src/plugins/python/weechat-python-api.c
@@ -2642,7 +2642,7 @@ weechat_python_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c
index 74f240a83..8bad2f8e2 100644
--- a/src/plugins/ruby/weechat-ruby-api.c
+++ b/src/plugins/ruby/weechat-ruby-api.c
@@ -3216,7 +3216,7 @@ weechat_ruby_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c
index 0eee83317..6e4d2b1d5 100644
--- a/src/plugins/tcl/weechat-tcl-api.c
+++ b/src/plugins/tcl/weechat-tcl-api.c
@@ -2936,7 +2936,7 @@ weechat_tcl_api_hook_print_cb (const void *pointer, void *data,
func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg;
func_argv[1] = (char *)API_PTR2STR(buffer);
func_argv[2] = timebuffer;
- func_argv[3] = weechat_string_rebuild_split_string (tags, ",");
+ func_argv[3] = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (!func_argv[3])
func_argv[3] = strdup ("");
func_argv[4] = &displayed;
diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c
index 0659911f4..b5bc3585c 100644
--- a/src/plugins/trigger/trigger-callback.c
+++ b/src/plugins/trigger/trigger-callback.c
@@ -1030,7 +1030,7 @@ trigger_callback_print_cb (const void *pointer, void *data,
free (str_no_color);
}
- str_tags = weechat_string_rebuild_split_string (tags, ",");
+ str_tags = weechat_string_rebuild_split_string (tags, ",", 0, -1);
if (str_tags)
{
/* build string with tags and commas around: ",tag1,tag2,tag3," */
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 8146031d8..43e04964c 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -68,7 +68,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
-#define WEECHAT_PLUGIN_API_VERSION "20220720-01"
+#define WEECHAT_PLUGIN_API_VERSION "20220720-02"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -333,7 +333,8 @@ struct t_weechat_plugin
char **(*string_split_shell) (const char *string, int *num_items);
void (*string_free_split) (char **split_string);
char *(*string_rebuild_split_string) (const char **split_string,
- const char *separator);
+ const char *separator,
+ int index_start, int index_end);
char **(*string_split_command) (const char *command, char separator);
void (*string_free_split_command) (char **split_command);
char *(*string_format_size) (unsigned long long size);
@@ -1286,9 +1287,13 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
#define weechat_string_free_split(__split_string) \
(weechat_plugin->string_free_split)(__split_string)
#define weechat_string_rebuild_split_string(__split_string, \
- __separator) \
+ __separator, \
+ __index_start, \
+ __index_end) \
(weechat_plugin->string_rebuild_split_string)(__split_string, \
- __separator)
+ __separator, \
+ __index_start, \
+ __index_end)
#define weechat_string_split_command(__command, __separator) \
(weechat_plugin->string_split_command)(__command, __separator)
#define weechat_string_free_split_command(__split_command) \