gint ref;
gchar *config_home;
gchar *data_home;
+ gchar *cache_home;
GSList *config_dirs;
GSList *data_dirs;
+ GSList *autostart_dirs;
};
static gint slist_path_cmp(const gchar *a, const gchar *b)
{
ObtPaths *p;
const gchar *path;
+ GSList *it;
- p = g_new(ObtPaths, 1);
+ p = g_slice_new0(ObtPaths);
p->ref = 1;
path = g_getenv("XDG_CONFIG_HOME");
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);
g_strdup(p->config_home),
(GSListFunc) g_slist_prepend);
+ for (it = p->config_dirs; it; it = g_slist_next(it)) {
+ gchar *const s = g_strdup_printf("%s/autostart", (gchar*)it->data);
+ p->autostart_dirs = g_slist_append(p->autostart_dirs, s);
+ }
+
path = g_getenv("XDG_DATA_DIRS");
if (path && path[0] != '\0') /* not unset or empty */
p->data_dirs = split_paths(path);
for (it = p->data_dirs; it; it = g_slist_next(it))
g_free(it->data);
g_slist_free(p->data_dirs);
+ for (it = p->autostart_dirs; it; it = g_slist_next(it))
+ g_free(it->data);
+ g_slist_free(p->autostart_dirs);
g_free(p->config_home);
g_free(p->data_home);
+ g_free(p->cache_home);
- obt_free0(p, ObtPaths, 1);
+ g_slice_free(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;
}
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;
{
return p->data_dirs;
}
+
+GSList* obt_paths_autostart_dirs(ObtPaths *p)
+{
+ return p->autostart_dirs;
+}