X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fparse.c;h=b44e968d589f3ee7bef87dc02347ba4b0a61edb2;hb=04dc598a1fb195065403055fbb95589dd3511daa;hp=d181b67920ec4894e7a2f4413808a3d5bdbac6dd;hpb=7e47a57027e043d4fe908d5f0acb7882d4f9330f;p=chaz%2Fopenbox diff --git a/obt/parse.c b/obt/parse.c index d181b679..b44e968d 100644 --- a/obt/parse.c +++ b/obt/parse.c @@ -99,7 +99,7 @@ void obt_parse_register(ObtParseInst *i, const gchar *tag, { struct Callback *c; - if ((c = g_hash_table_lookup(i->callbacks, tag))) { + if (g_hash_table_lookup(i->callbacks, tag)) { g_error("Tag '%s' already registered", tag); return; } @@ -277,6 +277,13 @@ gboolean obt_parse_load_mem(ObtParseInst *i, return r; } +gboolean obt_parse_save_file(ObtParseInst *inst, + const gchar *path, + gboolean pretty) +{ + return xmlSaveFormatFile(path, inst->doc, pretty) != -1; +} + void obt_parse_close(ObtParseInst *i) { if (i && i->doc) { @@ -307,7 +314,9 @@ void obt_parse_tree_from_root(ObtParseInst *i) gchar *obt_parse_node_string(xmlNodePtr node) { xmlChar *c = xmlNodeGetContent(node); - gchar *s = g_strdup(c ? (gchar*)c : ""); + gchar *s; + if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */ + s = g_strdup(c ? (gchar*)c : ""); xmlFree(c); return s; } @@ -315,7 +324,9 @@ gchar *obt_parse_node_string(xmlNodePtr node) gint obt_parse_node_int(xmlNodePtr node) { xmlChar *c = xmlNodeGetContent(node); - gint i = c ? atoi((gchar*)c) : 0; + gint i; + if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */ + i = c ? atoi((gchar*)c) : 0; xmlFree(c); return i; } @@ -324,6 +335,7 @@ gboolean obt_parse_node_bool(xmlNodePtr node) { xmlChar *c = xmlNodeGetContent(node); gboolean b = FALSE; + if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */ if (c && !xmlStrcasecmp(c, (const xmlChar*) "true")) b = TRUE; else if (c && !xmlStrcasecmp(c, (const xmlChar*) "yes")) @@ -338,6 +350,7 @@ gboolean obt_parse_node_contains(xmlNodePtr node, const gchar *val) { xmlChar *c = xmlNodeGetContent(node); gboolean r; + if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */ r = !xmlStrcasecmp(c, (const xmlChar*) val); xmlFree(c); return r; @@ -359,6 +372,7 @@ gboolean obt_parse_attr_bool(xmlNodePtr node, const gchar *name, 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")) @@ -381,6 +395,7 @@ gboolean obt_parse_attr_int(xmlNodePtr node, const gchar *name, gint *value) 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; } @@ -394,6 +409,7 @@ gboolean obt_parse_attr_string(xmlNodePtr node, const gchar *name, 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; } @@ -406,8 +422,10 @@ gboolean obt_parse_attr_contains(xmlNodePtr node, const gchar *name, { xmlChar *c = xmlGetProp(node, (const xmlChar*) name); gboolean r = FALSE; - if (c) + if (c) { + g_strstrip((char*)c); /* strip leading/trailing whitespace */ r = !xmlStrcasecmp(c, (const xmlChar*) val); + } xmlFree(c); return r; }