diff options
author | James Booth <boothj5@gmail.com> | 2013-01-28 19:52:49 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-01-28 19:52:49 +0000 |
commit | 6c3b42cd24c5982059e4f76cfe4406f58775d3d7 (patch) | |
tree | 18081ec08655d1348fc3cf249843bb472397484b | |
parent | 1d5046bc9747c981f7e9631987a4cb484a9534d9 (diff) | |
download | profani-tty-6c3b42cd24c5982059e4f76cfe4406f58775d3d7.tar.gz |
Flattened files.c and xdg_base.c
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | src/files.c | 62 | ||||
-rw-r--r-- | src/xdg_base.c | 64 | ||||
-rw-r--r-- | src/xdg_base.h | 31 |
4 files changed, 52 insertions, 109 deletions
diff --git a/Makefile.am b/Makefile.am index 0f4877b9..91e23827 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,8 +9,8 @@ profanity_SOURCES = src/command.c src/contact.c src/command_history.c src/xmpp.h src/chat_log.h src/tinyurl.c src/tinyurl.h src/chat_session.c \ src/chat_session.h src/release.c src/release.h src/muc.c \ src/muc.h src/xmpp_stanza.c src/command_parser.c \ - src/theme.c src/theme.h src/window.c src/window.h src/xdg_base.c \ - src/xdg_base.h src/files.c src/files.h src/accounts.c src/accounts.h \ + src/theme.c src/theme.h src/window.c src/window.h \ + src/files.c src/files.h src/accounts.c src/accounts.h \ src/jid.h src/jid.c src/xmpp_caps.c src/xmpp_iq.c TESTS = tests/testsuite diff --git a/src/files.c b/src/files.c index 3fe456d4..1dac6269 100644 --- a/src/files.c +++ b/src/files.c @@ -25,8 +25,6 @@ #include <string.h> #include <sys/stat.h> -#include "xdg_base.h" - #include <glib.h> static void _files_create_config_directory(void); @@ -36,6 +34,8 @@ static void _files_create_log_directory(void); static void _files_create_themes_directory(void); static void _create_dir(char *name); static void _mkdir_recursive(const char *dir); +static gchar* _xdg_get_config_home(void); +static gchar* _xdg_get_data_home(void); void files_create_directories(void) @@ -50,7 +50,7 @@ files_create_directories(void) gchar * files_get_chatlog_dir(void) { - gchar *xdg_data = xdg_get_data_home(); + gchar *xdg_data =_xdg_get_data_home(); GString *chatlogs_dir = g_string_new(xdg_data); g_string_append(chatlogs_dir, "/profanity/chatlogs"); gchar *result = strdup(chatlogs_dir->str); @@ -63,7 +63,7 @@ files_get_chatlog_dir(void) gchar * files_get_preferences_file(void) { - gchar *xdg_config = xdg_get_config_home(); + gchar *xdg_config = _xdg_get_config_home(); GString *prefs_file = g_string_new(xdg_config); g_string_append(prefs_file, "/profanity/profrc"); gchar *result = strdup(prefs_file->str); @@ -76,7 +76,7 @@ files_get_preferences_file(void) gchar * files_get_log_file(void) { - gchar *xdg_data = xdg_get_data_home(); + gchar *xdg_data = _xdg_get_data_home(); GString *logfile = g_string_new(xdg_data); g_string_append(logfile, "/profanity/logs/profanity.log"); gchar *result = strdup(logfile->str); @@ -89,7 +89,7 @@ files_get_log_file(void) gchar * files_get_accounts_file(void) { - gchar *xdg_data = xdg_get_data_home(); + gchar *xdg_data = _xdg_get_data_home(); GString *logfile = g_string_new(xdg_data); g_string_append(logfile, "/profanity/accounts"); gchar *result = strdup(logfile->str); @@ -102,7 +102,7 @@ files_get_accounts_file(void) gchar * files_get_themes_dir(void) { - gchar *xdg_config = xdg_get_config_home(); + gchar *xdg_config = _xdg_get_config_home(); GString *themes_dir = g_string_new(xdg_config); g_string_append(themes_dir, "/profanity/themes"); gchar *result = strdup(themes_dir->str); @@ -115,7 +115,7 @@ files_get_themes_dir(void) static void _files_create_config_directory(void) { - gchar *xdg_config = xdg_get_config_home(); + gchar *xdg_config = _xdg_get_config_home(); GString *prof_conf_dir = g_string_new(xdg_config); g_string_append(prof_conf_dir, "/profanity"); _mkdir_recursive(prof_conf_dir->str); @@ -126,7 +126,7 @@ _files_create_config_directory(void) static void _files_create_data_directory(void) { - gchar *xdg_data = xdg_get_data_home(); + gchar *xdg_data = _xdg_get_data_home(); GString *prof_data_dir = g_string_new(xdg_data); g_string_append(prof_data_dir, "/profanity"); _mkdir_recursive(prof_data_dir->str); @@ -137,7 +137,7 @@ _files_create_data_directory(void) static void _files_create_chatlog_directory(void) { - gchar *xdg_data = xdg_get_data_home(); + gchar *xdg_data = _xdg_get_data_home(); GString *chatlogs_dir = g_string_new(xdg_data); g_string_append(chatlogs_dir, "/profanity/chatlogs"); _mkdir_recursive(chatlogs_dir->str); @@ -148,7 +148,7 @@ _files_create_chatlog_directory(void) static void _files_create_log_directory(void) { - gchar *xdg_data = xdg_get_data_home(); + gchar *xdg_data = _xdg_get_data_home(); GString *chatlogs_dir = g_string_new(xdg_data); g_string_append(chatlogs_dir, "/profanity/logs"); _mkdir_recursive(chatlogs_dir->str); @@ -159,7 +159,7 @@ _files_create_log_directory(void) static void _files_create_themes_directory(void) { - gchar *xdg_config = xdg_get_config_home(); + gchar *xdg_config = _xdg_get_config_home(); GString *themes_dir = g_string_new(xdg_config); g_string_append(themes_dir, "/profanity/themes"); _mkdir_recursive(themes_dir->str); @@ -192,3 +192,41 @@ _mkdir_recursive(const char *dir) } } +static gchar * +_xdg_get_config_home(void) +{ + gchar *xdg_config_home = getenv("XDG_CONFIG_HOME"); + if (xdg_config_home != NULL) + g_strstrip(xdg_config_home); + + if ((xdg_config_home != NULL) && (strcmp(xdg_config_home, "") != 0)) { + return strdup(xdg_config_home); + } else { + GString *default_path = g_string_new(getenv("HOME")); + g_string_append(default_path, "/.config"); + gchar *result = strdup(default_path->str); + g_string_free(default_path, TRUE); + + return result; + } +} + +static gchar * +_xdg_get_data_home(void) +{ + gchar *xdg_data_home = getenv("XDG_DATA_HOME"); + if (xdg_data_home != NULL) + g_strstrip(xdg_data_home); + + if ((xdg_data_home != NULL) && (strcmp(xdg_data_home, "") != 0)) { + return strdup(xdg_data_home); + } else { + GString *default_path = g_string_new(getenv("HOME")); + g_string_append(default_path, "/.local/share"); + gchar *result = strdup(default_path->str); + g_string_free(default_path, TRUE); + + return result; + } +} + diff --git a/src/xdg_base.c b/src/xdg_base.c deleted file mode 100644 index 175f4894..00000000 --- a/src/xdg_base.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * xdg_base.c - * - * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com> - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#include <stdlib.h> -#include <string.h> - -#include <glib.h> - -gchar * -xdg_get_config_home(void) -{ - gchar *xdg_config_home = getenv("XDG_CONFIG_HOME"); - if (xdg_config_home != NULL) - g_strstrip(xdg_config_home); - - if ((xdg_config_home != NULL) && (strcmp(xdg_config_home, "") != 0)) { - return strdup(xdg_config_home); - } else { - GString *default_path = g_string_new(getenv("HOME")); - g_string_append(default_path, "/.config"); - gchar *result = strdup(default_path->str); - g_string_free(default_path, TRUE); - - return result; - } -} - -gchar * -xdg_get_data_home(void) -{ - gchar *xdg_data_home = getenv("XDG_DATA_HOME"); - if (xdg_data_home != NULL) - g_strstrip(xdg_data_home); - - if ((xdg_data_home != NULL) && (strcmp(xdg_data_home, "") != 0)) { - return strdup(xdg_data_home); - } else { - GString *default_path = g_string_new(getenv("HOME")); - g_string_append(default_path, "/.local/share"); - gchar *result = strdup(default_path->str); - g_string_free(default_path, TRUE); - - return result; - } -} diff --git a/src/xdg_base.h b/src/xdg_base.h deleted file mode 100644 index 8c017085..00000000 --- a/src/xdg_base.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * xdg_base.h - * - * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com> - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef XDG_BASE_H -#define XDG_BASE_H - -#include <glib.h> - -gchar* xdg_get_config_home(void); -gchar* xdg_get_data_home(void); - -#endif |