mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 12:56:37 +02:00
core: use dynamic string functions to build bar window content
This commit is contained in:
+41
-76
@@ -680,14 +680,14 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
{
|
||||
enum t_gui_bar_filling filling;
|
||||
const char *ptr_content;
|
||||
char *content, *content2, str_reinit_color[32];
|
||||
char **content, *content2, str_reinit_color[32];
|
||||
char str_reinit_color_space[32], str_reinit_color_space_start_line[32];
|
||||
char str_start_item[32];
|
||||
char *item_value, *item_value2, ****split_items, **linear_items;
|
||||
int index_content, content_length, i, j, k, sub, index;
|
||||
int i, j, k, sub, index;
|
||||
int at_least_one_item, first_sub_item;
|
||||
int length_reinit_color_space, length_start_item, length;
|
||||
int max_length, max_length_screen;
|
||||
int length_reinit_color, length_reinit_color_space, length_start_item;
|
||||
int length, max_length, max_length_screen;
|
||||
int total_items, columns, lines;
|
||||
|
||||
if (!bar_window
|
||||
@@ -700,6 +700,7 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
snprintf (str_reinit_color, sizeof (str_reinit_color),
|
||||
"%c",
|
||||
GUI_COLOR_RESET_CHAR);
|
||||
length_reinit_color = strlen (str_reinit_color);
|
||||
|
||||
snprintf (str_reinit_color_space, sizeof (str_reinit_color_space),
|
||||
"%c ",
|
||||
@@ -721,10 +722,7 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
GUI_COLOR_BAR_START_ITEM);
|
||||
length_start_item = strlen (str_start_item);
|
||||
|
||||
content_length = 1;
|
||||
content = malloc (content_length);
|
||||
if (content)
|
||||
content[0] = '\0';
|
||||
content = string_dyn_alloc (256);
|
||||
filling = gui_bar_get_filling (bar_window->bar);
|
||||
at_least_one_item = 0;
|
||||
switch (filling)
|
||||
@@ -756,37 +754,38 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
}
|
||||
}
|
||||
else
|
||||
item_value = NULL;
|
||||
|
||||
content_length += ((filling == GUI_BAR_FILLING_HORIZONTAL) ? length_start_item : 0) +
|
||||
length_reinit_color_space +
|
||||
strlen ((item_value) ? item_value : ptr_content);
|
||||
content2 = realloc (content, content_length);
|
||||
if (!content2)
|
||||
{
|
||||
if (content)
|
||||
free (content);
|
||||
return NULL;
|
||||
item_value = NULL;
|
||||
}
|
||||
content = content2;
|
||||
if (at_least_one_item && first_sub_item)
|
||||
{
|
||||
/* first sub item: insert space after last item */
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
strcat (content, str_reinit_color_space);
|
||||
{
|
||||
string_dyn_concat (content,
|
||||
str_reinit_color_space,
|
||||
length_reinit_color_space);
|
||||
}
|
||||
else
|
||||
strcat (content, "\n");
|
||||
{
|
||||
string_dyn_concat (content, "\n", -1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat (content, str_reinit_color);
|
||||
string_dyn_concat (content, str_reinit_color,
|
||||
length_reinit_color);
|
||||
}
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
strcat (content, str_start_item);
|
||||
strcat (content,
|
||||
(item_value) ? item_value : ptr_content);
|
||||
{
|
||||
string_dyn_concat (content, str_start_item,
|
||||
length_start_item);
|
||||
}
|
||||
string_dyn_concat (
|
||||
content,
|
||||
(item_value) ? item_value : ptr_content,
|
||||
-1);
|
||||
first_sub_item = 0;
|
||||
|
||||
if (item_value)
|
||||
free (item_value);
|
||||
at_least_one_item = 1;
|
||||
@@ -795,33 +794,14 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
{
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
{
|
||||
content_length += length_start_item;
|
||||
content2 = realloc (content, content_length);
|
||||
if (!content2)
|
||||
{
|
||||
if (content)
|
||||
free (content);
|
||||
return NULL;
|
||||
}
|
||||
content = content2;
|
||||
strcat (content, str_start_item);
|
||||
string_dyn_concat (content, str_start_item,
|
||||
length_start_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (filling == GUI_BAR_FILLING_HORIZONTAL)
|
||||
{
|
||||
content_length += length_start_item;
|
||||
content2 = realloc (content, content_length);
|
||||
if (!content2)
|
||||
{
|
||||
if (content)
|
||||
free (content);
|
||||
return NULL;
|
||||
}
|
||||
content = content2;
|
||||
strcat (content, str_start_item);
|
||||
}
|
||||
string_dyn_concat (content, str_start_item, length_start_item);
|
||||
break;
|
||||
case GUI_BAR_FILLING_COLUMNS_HORIZONTAL: /* items in columns, with horizontal filling */
|
||||
case GUI_BAR_FILLING_COLUMNS_VERTICAL: /* items in columns, with vertical filling */
|
||||
@@ -914,21 +894,6 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
}
|
||||
|
||||
/* build content with lines and columns */
|
||||
content_length = 1 + (lines *
|
||||
((columns *
|
||||
(max_length + max_length_screen + length_reinit_color_space)) + 1));
|
||||
content2 = realloc (content, content_length);
|
||||
if (!content2)
|
||||
{
|
||||
if (content)
|
||||
free (content);
|
||||
free (split_items);
|
||||
free (linear_items);
|
||||
return NULL;
|
||||
}
|
||||
content = content2;
|
||||
content[0] = '\0';
|
||||
index_content = 0;
|
||||
for (i = 0; i < lines; i++)
|
||||
{
|
||||
for (j = 0; j < columns; j++)
|
||||
@@ -942,30 +907,27 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
{
|
||||
for (k = 0; k < max_length_screen; k++)
|
||||
{
|
||||
content[index_content++] = ' ';
|
||||
string_dyn_concat (content, " ", -1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy (content + index_content, linear_items[index]);
|
||||
index_content += strlen (linear_items[index]);
|
||||
string_dyn_concat (content, linear_items[index], -1);
|
||||
length = max_length_screen -
|
||||
gui_chat_strlen_screen (linear_items[index]);
|
||||
for (k = 0; k < length; k++)
|
||||
{
|
||||
content[index_content++] = ' ';
|
||||
string_dyn_concat (content, " ", -1);
|
||||
}
|
||||
}
|
||||
if (j < columns - 1)
|
||||
{
|
||||
strcpy (content + index_content,
|
||||
str_reinit_color_space);
|
||||
index_content += length_reinit_color_space;
|
||||
string_dyn_concat (content, str_reinit_color_space,
|
||||
length_reinit_color_space);
|
||||
}
|
||||
}
|
||||
content[index_content++] = '\n';
|
||||
string_dyn_concat (content, "\n", -1);
|
||||
}
|
||||
content[index_content] = '\0';
|
||||
|
||||
free (linear_items);
|
||||
}
|
||||
@@ -988,13 +950,16 @@ gui_bar_window_content_get_with_filling (struct t_gui_bar_window *bar_window,
|
||||
break;
|
||||
}
|
||||
|
||||
if (content_length == 1)
|
||||
if (!*content[0])
|
||||
{
|
||||
free (content);
|
||||
content = NULL;
|
||||
string_dyn_free (content, 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return content;
|
||||
content2 = *content;
|
||||
string_dyn_free (content, 0);
|
||||
|
||||
return content2;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user