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,
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;
}
{
struct stat s;
- g_print("Trying to load file %s for %s\n", path, rootname);
-
if (stat(path, &s) < 0)
return FALSE;
void parse_tree(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
{
while (node) {
- struct Callback *c = g_hash_table_lookup(i->callbacks, node->name);
+ if (node->name) {
+ struct Callback *c = g_hash_table_lookup(i->callbacks, node->name);
- if (c)
- c->func(i, doc, node, c->data);
+ if (c)
+ c->func(i, doc, node, c->data);
+ }
node = node->next;
}
gchar *parse_string(xmlDocPtr doc, xmlNodePtr node)
{
xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
- gchar *s = g_strdup(c ? (gchar*)c : "");
+ gchar *s;
+ if (c) g_strstrip((char*)c);
+ s = g_strdup(c ? (gchar*)c : "");
xmlFree(c);
return s;
}
gint parse_int(xmlDocPtr doc, xmlNodePtr node)
{
xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
- gint i = atoi((gchar*)c);
+ gint i;
+ if (c) g_strstrip((char*)c);
+ i = c ? atoi((gchar*)c) : 0;
xmlFree(c);
return i;
}
{
xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
gboolean b = FALSE;
- if (!xmlStrcasecmp(c, (const xmlChar*) "true"))
+ if (c) g_strstrip((char*)c);
+ if (c && !xmlStrcasecmp(c, (const xmlChar*) "true"))
b = TRUE;
- else if (!xmlStrcasecmp(c, (const xmlChar*) "yes"))
+ else if (c && !xmlStrcasecmp(c, (const xmlChar*) "yes"))
b = TRUE;
- else if (!xmlStrcasecmp(c, (const xmlChar*) "on"))
+ else if (c && !xmlStrcasecmp(c, (const xmlChar*) "on"))
b = TRUE;
xmlFree(c);
return b;
{
xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
gboolean r;
+ if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */
r = !xmlStrcasecmp(c, (const xmlChar*) val);
xmlFree(c);
return r;
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
gboolean r = FALSE;
if (c) {
+ g_strstrip((char*)c); /* strip leading/trailing whitespace */
if (!xmlStrcasecmp(c, (const xmlChar*) "true"))
*value = TRUE, r = TRUE;
else if (!xmlStrcasecmp(c, (const xmlChar*) "yes"))
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
gboolean r = FALSE;
if (c) {
+ g_strstrip((char*)c); /* strip leading/trailing whitespace */
*value = atoi((gchar*)c);
r = TRUE;
}
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
gboolean r = FALSE;
if (c) {
+ g_strstrip((char*)c); /* strip leading/trailing whitespace */
*value = g_strdup((gchar*)c);
r = TRUE;
}
{
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
gboolean r = FALSE;
- if (c)
+ if (c) {
+ g_strstrip((char*)c);
r = !xmlStrcasecmp(c, (const xmlChar*) val);
+ }
xmlFree(c);
return r;
}
return list;
}
-void parse_paths_startup()
+void parse_paths_startup(void)
{
const gchar *path;
xdg_config_dir_paths = slist_path_add(xdg_config_dir_paths,
g_strdup(xdg_config_home_path),
(GSListFunc) g_slist_prepend);
-
+
path = g_getenv("XDG_DATA_DIRS");
if (path && path[0] != '\0') /* not unset or empty */
xdg_data_dir_paths = split_paths(path);
(GSListFunc) g_slist_prepend);
}
-void parse_paths_shutdown()
+void parse_paths_shutdown(void)
{
GSList *it;
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;
}
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;
}