X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=parser%2Fparse.c;h=2076bad1fb6c3d4a022ca0eebe422f756550d625;hb=c30df2e750d301f64a4a2cc56b43454104772079;hp=510320b6a48f669fed2b8d7eeced857532df255b;hpb=c4e4760c41f10aae6af19a4363cb247c71edee4b;p=chaz%2Fopenbox diff --git a/parser/parse.c b/parser/parse.c index 510320b6..2076bad1 100644 --- a/parser/parse.c +++ b/parser/parse.c @@ -1,4 +1,4 @@ -/* -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*- +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- parse.c for the Openbox window manager Copyright (c) 2003 Ben Jansens @@ -29,7 +29,7 @@ static GSList *xdg_config_dir_paths; static GSList *xdg_data_dir_paths; struct Callback { - char *tag; + gchar *tag; ParseCallback func; void *data; }; @@ -60,7 +60,7 @@ void parse_shutdown(ObParseInst *i) } } -void parse_register(ObParseInst *i, const char *tag, +void parse_register(ObParseInst *i, const gchar *tag, ParseCallback func, void *data) { struct Callback *c; @@ -113,7 +113,7 @@ gboolean parse_load_menu(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root) return r; } -gboolean parse_load(const char *path, const char *rootname, +gboolean parse_load(const gchar *path, const gchar *rootname, xmlDocPtr *doc, xmlNodePtr *root) { if ((*doc = xmlParseFile(path))) { @@ -136,7 +136,7 @@ gboolean parse_load(const char *path, const char *rootname, return TRUE; } -gboolean parse_load_mem(gpointer data, guint len, const char *rootname, +gboolean parse_load_mem(gpointer data, guint len, const gchar *rootname, xmlDocPtr *doc, xmlNodePtr *root) { if ((*doc = xmlParseMemory(data, len))) { @@ -161,7 +161,7 @@ gboolean parse_load_mem(gpointer data, guint len, const char *rootname, void parse_close(xmlDocPtr doc) { - xmlFree(doc); + xmlFreeDoc(doc); } void parse_tree(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) @@ -176,18 +176,18 @@ void parse_tree(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) } } -char *parse_string(xmlDocPtr doc, xmlNodePtr node) +gchar *parse_string(xmlDocPtr doc, xmlNodePtr node) { xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE); - char *s = g_strdup(c ? (char*)c : ""); + gchar *s = g_strdup(c ? (gchar*)c : ""); xmlFree(c); return s; } -int parse_int(xmlDocPtr doc, xmlNodePtr node) +gint parse_int(xmlDocPtr doc, xmlNodePtr node) { xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE); - int i = atoi((char*)c); + gint i = atoi((gchar*)c); xmlFree(c); return i; } @@ -206,7 +206,7 @@ gboolean parse_bool(xmlDocPtr doc, xmlNodePtr node) return b; } -gboolean parse_contains(const char *val, xmlDocPtr doc, xmlNodePtr node) +gboolean parse_contains(const gchar *val, xmlDocPtr doc, xmlNodePtr node) { xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE); gboolean r; @@ -215,7 +215,7 @@ gboolean parse_contains(const char *val, xmlDocPtr doc, xmlNodePtr node) return r; } -xmlNodePtr parse_find_node(const char *tag, xmlNodePtr node) +xmlNodePtr parse_find_node(const gchar *tag, xmlNodePtr node) { while (node) { if (!xmlStrcasecmp(node->name, (const xmlChar*) tag)) @@ -225,32 +225,32 @@ xmlNodePtr parse_find_node(const char *tag, xmlNodePtr node) return NULL; } -gboolean parse_attr_int(const char *name, xmlNodePtr node, int *value) +gboolean parse_attr_int(const gchar *name, xmlNodePtr node, gint *value) { xmlChar *c = xmlGetProp(node, (const xmlChar*) name); gboolean r = FALSE; if (c) { - *value = atoi((char*)c); + *value = atoi((gchar*)c); r = TRUE; } xmlFree(c); return r; } -gboolean parse_attr_string(const char *name, xmlNodePtr node, char **value) +gboolean parse_attr_string(const gchar *name, xmlNodePtr node, gchar **value) { xmlChar *c = xmlGetProp(node, (const xmlChar*) name); gboolean r = FALSE; if (c) { - *value = g_strdup((char*)c); + *value = g_strdup((gchar*)c); r = TRUE; } xmlFree(c); return r; } -gboolean parse_attr_contains(const char *val, xmlNodePtr node, - const char *name) +gboolean parse_attr_contains(const gchar *val, xmlNodePtr node, + const gchar *name) { xmlChar *c = xmlGetProp(node, (const xmlChar*) name); gboolean r; @@ -262,22 +262,14 @@ gboolean parse_attr_contains(const char *val, xmlNodePtr node, static GSList* split_paths(const gchar *paths) { GSList *list = NULL; - gchar *c, *e, *s; + gchar **spl, **it; - c = g_strdup(paths); - s = c; - e = c - 1; - g_message("paths %s", paths); - while ((e = strchr(e + 1, ':'))) { - *e = '\0'; - g_message("s %s", s); - if (s[0] != '\0') - list = g_slist_append(list, g_strdup(s)); - s = e + 1; - } - if (s[0] != '\0') - list = g_slist_append(list, g_strdup(s)); - g_free(c); + if (!paths) + return NULL; + spl = g_strsplit(paths, ":", -1); + for (it = spl; *it; ++it) + list = g_slist_append(list, *it); + g_free(spl); return list; } @@ -329,8 +321,8 @@ void parse_paths_startup() g_build_filename (G_DIR_SEPARATOR_S, "usr", "share", NULL)); - xdg_config_dir_paths = g_slist_append(xdg_config_dir_paths, - g_strdup(DATADIR)); + xdg_data_dir_paths = g_slist_append(xdg_data_dir_paths, + g_strdup(DATADIR)); } xdg_data_dir_paths = g_slist_prepend(xdg_data_dir_paths, xdg_data_home_path); @@ -348,6 +340,10 @@ void parse_paths_shutdown() g_free(it->data); g_slist_free(xdg_config_dir_paths); xdg_config_dir_paths = NULL; + for (it = xdg_data_dir_paths; it; it = g_slist_next(it)) + g_free(it->data); + g_slist_free(xdg_data_dir_paths); + xdg_data_dir_paths = NULL; } gchar *parse_expand_tilde(const gchar *f)