Fix the ~ expansion regex
[dana/openbox.git] / parser / parse.c
index 6daa851..897d738 100644 (file)
@@ -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;
 }
@@ -460,14 +456,17 @@ void parse_paths_shutdown(void)
 
 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;
 }