1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 09:43:13 +02:00

core: simplify function gui_buffer_notify_get

This commit is contained in:
Sébastien Helleu
2023-08-18 13:37:39 +02:00
parent b756598070
commit 2c8657826f
+25 -30
View File
@@ -301,48 +301,43 @@ gui_buffer_local_var_remove_all (struct t_gui_buffer *buffer)
int
gui_buffer_notify_get (struct t_gui_buffer *buffer)
{
char *option_name, *ptr_end;
int length;
char *option_name, *pos;
struct t_config_option *ptr_option;
if (!buffer)
if (!buffer || !buffer->full_name)
return CONFIG_ENUM(config_look_buffer_notify_default);
length = strlen (buffer->full_name) + 1;
option_name = malloc (length);
if (option_name)
{
snprintf (option_name, length, "%s", buffer->full_name);
option_name = strdup (buffer->full_name);
if (!option_name)
return CONFIG_ENUM(config_look_buffer_notify_default);
ptr_end = option_name + strlen (option_name);
while (ptr_end >= option_name)
{
ptr_option = config_file_search_option (weechat_config_file,
weechat_config_section_notify,
option_name);
if (ptr_option)
{
free (option_name);
return CONFIG_INTEGER(ptr_option);
}
ptr_end--;
while ((ptr_end >= option_name) && (ptr_end[0] != '.'))
{
ptr_end--;
}
if ((ptr_end >= option_name) && (ptr_end[0] == '.'))
ptr_end[0] = '\0';
}
ptr_option = NULL;
while (1)
{
ptr_option = config_file_search_option (weechat_config_file,
weechat_config_section_notify,
option_name);
free (option_name);
if (ptr_option)
{
free (option_name);
return CONFIG_INTEGER(ptr_option);
}
pos = strrchr (option_name, '.');
if (!pos)
break;
pos[0] = '\0';
}
ptr_option = config_file_search_option (weechat_config_file,
weechat_config_section_notify,
option_name);
free (option_name);
if (ptr_option)
return CONFIG_INTEGER(ptr_option);
/* notify level not found */
return CONFIG_ENUM(config_look_buffer_notify_default);
}