1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 12:56:37 +02:00

logger: call function string_eval_path_home() to evaluate logger file path

This commit is contained in:
Sébastien Helleu
2015-06-25 07:40:13 +02:00
parent 52437427af
commit efdbd1ea13
+15 -45
View File
@@ -71,72 +71,42 @@ struct t_hook *logger_timer = NULL; /* timer to flush log files */
char *
logger_get_file_path ()
{
char *file_path, *file_path2, *file_path3, *file_path4;
const char *weechat_dir;
char *path, *path2;
int length;
time_t seconds;
struct tm *date_tmp;
file_path = NULL;
file_path2 = NULL;
file_path3 = NULL;
file_path4 = NULL;
path = NULL;
path2 = NULL;
weechat_dir = weechat_info_get ("weechat_dir", "");
if (!weechat_dir)
goto end;
/* evaluate path */
file_path = weechat_string_eval_expression (
/* replace %h and "~", evaluate path */
path = weechat_string_eval_path_home (
weechat_config_string (logger_config_file_path), NULL, NULL, NULL);
if (!file_path)
goto end;
/* replace "~" with user home */
file_path2 = weechat_string_expand_home (file_path);
if (!file_path2)
goto end;
/* replace "%h" with WeeChat home (at beginning of string only) */
if (strncmp (file_path2, "%h", 2) == 0)
{
length = strlen (weechat_dir) + strlen (file_path2 + 2) + 1;
file_path3 = malloc (length);
if (file_path3)
snprintf (file_path3, length, "%s%s", weechat_dir, file_path2 + 2);
}
else
file_path3 = strdup (file_path2);
if (!file_path3)
if (!path)
goto end;
/* replace date/time specifiers in path */
length = strlen (file_path3) + 256 + 1;
file_path4 = malloc (length);
if (!file_path4)
length = strlen (path) + 256 + 1;
path2 = malloc (length);
if (!path2)
goto end;
seconds = time (NULL);
date_tmp = localtime (&seconds);
file_path4[0] = '\0';
strftime (file_path4, length - 1, file_path3, date_tmp);
path2[0] = '\0';
strftime (path2, length - 1, path, date_tmp);
if (weechat_logger_plugin->debug)
{
weechat_printf_tags (NULL,
"no_log",
"%s: file path = \"%s\"",
LOGGER_PLUGIN_NAME, file_path4);
LOGGER_PLUGIN_NAME, path2);
}
end:
if (file_path)
free (file_path);
if (file_path2)
free (file_path2);
if (file_path3)
free (file_path3);
return file_path4;
if (path)
free (path);
return path2;
}
/*