Move all filepath handling to files.c

This commit is contained in:
James Booth
2016-07-24 21:35:12 +01:00
parent 29452f8f1b
commit a3a73cf003
19 changed files with 174 additions and 262 deletions

View File

@@ -35,18 +35,22 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
#include "common.h"
#include "log.h"
#include "config/files.h"
#include "config/preferences.h"
static char* _files_get_xdg_config_home(void);
static char* _files_get_xdg_data_home(void);
void
files_create_directories(void)
{
gchar *xdg_config = files_get_xdg_config_home();
gchar *xdg_data = files_get_xdg_data_home();
gchar *xdg_config = _files_get_xdg_config_home();
gchar *xdg_data = _files_get_xdg_data_home();
GString *themes_dir = g_string_new(xdg_config);
g_string_append(themes_dir, "/profanity/themes");
@@ -85,17 +89,17 @@ files_create_directories(void)
g_free(xdg_data);
}
gchar*
files_get_inputrc_path(void)
char*
files_get_inputrc_file(void)
{
gchar *xdg_config = files_get_xdg_config_home();
gchar *xdg_config = _files_get_xdg_config_home();
GString *inputrc_file = g_string_new(xdg_config);
g_free(xdg_config);
g_string_append(inputrc_file, "/profanity/inputrc");
if (g_file_test(inputrc_file->str, G_FILE_TEST_IS_REGULAR)) {
gchar *result = strdup(inputrc_file->str);
char *result = strdup(inputrc_file->str);
g_string_free(inputrc_file, TRUE);
return result;
@@ -106,8 +110,53 @@ files_get_inputrc_path(void)
return NULL;
}
gchar*
files_get_xdg_config_home(void)
char*
files_get_log_file(void)
{
gchar *xdg_data = _files_get_xdg_data_home();
GString *logfile = g_string_new(xdg_data);
g_string_append(logfile, "/profanity/logs/profanity");
if (!prefs_get_boolean(PREF_LOG_SHARED)) {
g_string_append_printf(logfile, "%d", getpid());
}
g_string_append(logfile, ".log");
char *result = strdup(logfile->str);
free(xdg_data);
g_string_free(logfile, TRUE);
return result;
}
char*
files_get_config_path(char *config_base)
{
gchar *xdg_config = _files_get_xdg_config_home();
GString *file_str = g_string_new(xdg_config);
g_string_append(file_str, "/profanity/");
g_string_append(file_str, config_base);
char *result = strdup(file_str->str);
g_free(xdg_config);
g_string_free(file_str, TRUE);
return result;
}
char*
files_get_data_path(char *data_base)
{
gchar *xdg_data = _files_get_xdg_data_home();
GString *file_str = g_string_new(xdg_data);
g_string_append(file_str, "/profanity/");
g_string_append(file_str, data_base);
char *result = strdup(file_str->str);
g_free(xdg_data);
g_string_free(file_str, TRUE);
return result;
}
static char*
_files_get_xdg_config_home(void)
{
gchar *xdg_config_home = getenv("XDG_CONFIG_HOME");
if (xdg_config_home)
@@ -118,15 +167,15 @@ files_get_xdg_config_home(void)
} else {
GString *default_path = g_string_new(getenv("HOME"));
g_string_append(default_path, "/.config");
gchar *result = strdup(default_path->str);
char *result = strdup(default_path->str);
g_string_free(default_path, TRUE);
return result;
}
}
gchar*
files_get_xdg_data_home(void)
static char*
_files_get_xdg_data_home(void)
{
gchar *xdg_data_home = getenv("XDG_DATA_HOME");
if (xdg_data_home)