]> Dogcows Code - chaz/openbox/commitdiff
add parse_attr_bool, and fix a possible segfault
authorDana Jansens <danakj@orodu.net>
Sun, 4 Mar 2007 07:09:55 +0000 (07:09 +0000)
committerDana Jansens <danakj@orodu.net>
Sun, 4 Mar 2007 07:09:55 +0000 (07:09 +0000)
parser/parse.c
parser/parse.h

index f8aed0b5b0228258eef79b2abf28cf2a48dea939..6df247251ed09a6c7f85e34b25924849205bc22e 100644 (file)
@@ -226,6 +226,28 @@ xmlNodePtr parse_find_node(const gchar *tag, xmlNodePtr node)
     return NULL;
 }
 
+gboolean parse_attr_bool(const gchar *name, xmlNodePtr node, gboolean *value)
+{
+    xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
+    gboolean r = FALSE;
+    if (c) {
+        if (!xmlStrcasecmp(c, (const xmlChar*) "true"))
+            *value = TRUE, r = TRUE;
+        else if (!xmlStrcasecmp(c, (const xmlChar*) "yes"))
+            *value = TRUE, r = TRUE;
+        else if (!xmlStrcasecmp(c, (const xmlChar*) "on"))
+            *value = TRUE, r = TRUE;
+        else if (!xmlStrcasecmp(c, (const xmlChar*) "false"))
+            *value = FALSE, r = TRUE;
+        else if (!xmlStrcasecmp(c, (const xmlChar*) "no"))
+            *value = FALSE, r = TRUE;
+        else if (!xmlStrcasecmp(c, (const xmlChar*) "off"))
+            *value = FALSE, r = TRUE;
+    }
+    xmlFree(c);
+    return r;
+}
+
 gboolean parse_attr_int(const gchar *name, xmlNodePtr node, gint *value)
 {
     xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
@@ -254,8 +276,9 @@ gboolean parse_attr_contains(const gchar *val, xmlNodePtr node,
                              const gchar *name)
 {
     xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
-    gboolean r;
-    r = !xmlStrcasecmp(c, (const xmlChar*) val);
+    gboolean r = FALSE;
+    if (c)
+        r = !xmlStrcasecmp(c, (const xmlChar*) val);
     xmlFree(c);
     return r;
 }
index da754cbe29236d0e3b2abe7afae19f7d1ecaa7d3..ac3acba2fed3a0b05e6b83670e0efaad35e5439a 100644 (file)
@@ -67,6 +67,7 @@ gboolean parse_attr_contains(const gchar *val, xmlNodePtr node,
 
 gboolean parse_attr_string(const gchar *name, xmlNodePtr node, gchar **value);
 gboolean parse_attr_int(const gchar *name, xmlNodePtr node, gint *value);
+gboolean parse_attr_bool(const gchar *name, xmlNodePtr node, gboolean *value);
 
 /* paths */
 
This page took 0.023116 seconds and 4 git commands to generate.