]> Dogcows Code - chaz/openbox/blobdiff - parser/parse.c
Don't replace ~ when we shouldn't
[chaz/openbox] / parser / parse.c
index 8c2d012eaeb511e089c8f1fa01fb2a4f2268cc83..ed66f088f6ba33f715b805fce01a25e5123a427e 100644 (file)
@@ -46,7 +46,7 @@ static void destfunc(struct Callback *c)
     g_free(c);
 }
 
-ObParseInst* parse_startup()
+ObParseInst* parse_startup(void)
 {
     ObParseInst *i = g_new(ObParseInst, 1);
     i->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
@@ -79,25 +79,21 @@ void parse_register(ObParseInst *i, const gchar *tag,
     g_hash_table_insert(i->callbacks, c->tag, c);
 }
 
-gboolean parse_load_rc(const gchar *type, xmlDocPtr *doc, xmlNodePtr *root)
+gboolean parse_load_rc(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root)
 {
     GSList *it;
     gboolean r = FALSE;
-    gchar *fname;
 
-    if (type == NULL)
-        fname = g_strdup("rc.xml");
-    else
-        fname = g_strdup_printf("rc-%s.xml", type);
+    if (file && parse_load(file, "openbox_config", doc, root))
+        return TRUE;
 
     for (it = xdg_config_dir_paths; !r && it; it = g_slist_next(it)) {
         gchar *path;
 
-        path = g_build_filename(it->data, "openbox", fname, NULL);
+        path = g_build_filename(it->data, "openbox", "rc.xml", NULL);
         r = parse_load(path, "openbox_config", doc, root);
         g_free(path);
     }
-    g_free(fname);
 
     return r;
 }
@@ -374,7 +370,7 @@ static GSList* split_paths(const gchar *paths)
     return list;
 }
 
-void parse_paths_startup()
+void parse_paths_startup(void)
 {
     const gchar *path;
 
@@ -436,7 +432,7 @@ void parse_paths_startup()
                                         (GSListFunc) g_slist_prepend);
 }
 
-void parse_paths_shutdown()
+void parse_paths_shutdown(void)
 {
     GSList *it;
 
@@ -460,14 +456,16 @@ void parse_paths_shutdown()
 
 gchar *parse_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;
 }
 
@@ -512,22 +510,22 @@ gboolean parse_mkdir_path(const gchar *path, gint mode)
     return ret;
 }
 
-const gchar* parse_xdg_config_home_path()
+const gchar* parse_xdg_config_home_path(void)
 {
     return xdg_config_home_path;
 }
 
-const gchar* parse_xdg_data_home_path()
+const gchar* parse_xdg_data_home_path(void)
 {
     return xdg_data_home_path;
 }
 
-GSList* parse_xdg_config_dir_paths()
+GSList* parse_xdg_config_dir_paths(void)
 {
     return xdg_config_dir_paths;
 }
 
-GSList* parse_xdg_data_dir_paths()
+GSList* parse_xdg_data_dir_paths(void)
 {
     return xdg_data_dir_paths;
 }
This page took 0.025872 seconds and 4 git commands to generate.