X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fpaths.c;h=68615433e1d9426dc58cdf462050cbe89937cf6c;hb=98c86118ca941d71c0c511c865d5913814012aed;hp=6357b777dc3ae11dc990380b649f448d58907b6a;hpb=07d5674d3984d008de1ecc768a296afbed731e4e;p=chaz%2Fopenbox diff --git a/obt/paths.c b/obt/paths.c index 6357b777..68615433 100644 --- a/obt/paths.c +++ b/obt/paths.c @@ -34,6 +34,7 @@ struct _ObtPaths gint ref; gchar *config_home; gchar *data_home; + gchar *cache_home; GSList *config_dirs; GSList *data_dirs; }; @@ -79,7 +80,7 @@ ObtPaths* obt_paths_new(void) ObtPaths *p; const gchar *path; - p = g_new(ObtPaths, 1); + p = g_new0(ObtPaths, 1); p->ref = 1; path = g_getenv("XDG_CONFIG_HOME"); @@ -95,6 +96,12 @@ ObtPaths* obt_paths_new(void) p->data_home = g_build_filename(g_get_home_dir(), ".local", "share", NULL); + path = g_getenv("XDG_CACHE_HOME"); + if (path && path[0] != '\0') /* not unset or empty */ + p->cache_home = g_build_filename(path, NULL); + else + p->cache_home = g_build_filename(g_get_home_dir(), ".cache", NULL); + path = g_getenv("XDG_CONFIG_DIRS"); if (path && path[0] != '\0') /* not unset or empty */ p->config_dirs = split_paths(path); @@ -154,6 +161,7 @@ void obt_paths_unref(ObtPaths *p) g_slist_free(p->data_dirs); g_free(p->config_home); g_free(p->data_home); + g_free(p->cache_home); obt_free0(p, ObtPaths, 1); } @@ -161,14 +169,16 @@ void obt_paths_unref(ObtPaths *p) gchar *obt_paths_expand_tilde(const gchar *f) { - gchar **spl; gchar *ret; + GRegex *regex; if (!f) return NULL; - spl = g_strsplit(f, "~", 0); - ret = g_strjoinv(g_get_home_dir(), spl); - g_strfreev(spl); + + regex = g_regex_new("(?:^|(?<=[ \\t]))~(?=[/ \\t$])", G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL); + ret = g_regex_replace_literal(regex, f, -1, 0, g_get_home_dir(), 0, NULL); + g_regex_unref(regex); + return ret; } @@ -223,6 +233,11 @@ const gchar* obt_paths_data_home(ObtPaths *p) return p->data_home; } +const gchar* obt_paths_cache_home(ObtPaths *p) +{ + return p->cache_home; +} + GSList* obt_paths_config_dirs(ObtPaths *p) { return p->config_dirs;