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

@@ -51,38 +51,31 @@
void
scripts_init(void)
{
gchar *data_home = files_get_xdg_data_home();
GString *scriptsdir = g_string_new(data_home);
free(data_home);
g_string_append(scriptsdir, "/profanity/scripts");
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
// mkdir if doesn't exist
errno = 0;
int res = g_mkdir_with_parents(scriptsdir->str, S_IRWXU);
int res = g_mkdir_with_parents(scriptsdir, S_IRWXU);
if (res == -1) {
char *errmsg = strerror(errno);
if (errmsg) {
log_error("Error creating directory: %s, %s", scriptsdir->str, errmsg);
log_error("Error creating directory: %s, %s", scriptsdir, errmsg);
} else {
log_error("Error creating directory: %s", scriptsdir->str);
log_error("Error creating directory: %s", scriptsdir);
}
}
g_string_free(scriptsdir, TRUE);
free(scriptsdir);
}
GSList*
scripts_list(void)
{
gchar *data_home = files_get_xdg_data_home();
GString *scriptsdir = g_string_new(data_home);
free(data_home);
g_string_append(scriptsdir, "/profanity/scripts");
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
GSList *result = NULL;
GDir *scripts = g_dir_open(scriptsdir->str, 0, NULL);
g_string_free(scriptsdir, TRUE);
GDir *scripts = g_dir_open(scriptsdir, 0, NULL);
free(scriptsdir);
if (scripts) {
const gchar *script = g_dir_read_name(scripts);
@@ -99,11 +92,10 @@ scripts_list(void)
GSList*
scripts_read(const char *const script)
{
gchar *data_home = files_get_xdg_data_home();
GString *scriptpath = g_string_new(data_home);
free(data_home);
g_string_append(scriptpath, "/profanity/scripts/");
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
GString *scriptpath = g_string_new(scriptsdir);
free(scriptsdir);
g_string_append(scriptpath, "/");
g_string_append(scriptpath, script);
FILE *scriptfile = g_fopen(scriptpath->str, "r");
@@ -137,11 +129,10 @@ scripts_read(const char *const script)
gboolean
scripts_exec(const char *const script)
{
gchar *data_home = files_get_xdg_data_home();
GString *scriptpath = g_string_new(data_home);
free(data_home);
g_string_append(scriptpath, "/profanity/scripts/");
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
GString *scriptpath = g_string_new(scriptsdir);
free(scriptsdir);
g_string_append(scriptpath, "/");
g_string_append(scriptpath, script);
FILE *scriptfile = g_fopen(scriptpath->str, "r");