From 8a722d04938583dc3620de05fd52f0baecce9fbb Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 10 May 2009 14:21:20 +0200 Subject: Consolidate data types --- src/xml-parser.c | 65 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'src/xml-parser.c') diff --git a/src/xml-parser.c b/src/xml-parser.c index 34c0ebd..8c4301b 100644 --- a/src/xml-parser.c +++ b/src/xml-parser.c @@ -37,18 +37,17 @@ * xml_parser_load: initialize and load the XML document */ TXMLFile * -xml_parser_load (const char *filename) +xml_parser_load (const gchar *filename) { TXMLFile *file; - file = malloc (sizeof (TXMLFile)); - memset (file, 0, sizeof (TXMLFile)); + file = g_malloc0 (sizeof (TXMLFile)); /* Load XML document */ file->doc = xmlParseFile (filename); if (file->doc == NULL) { log_error ("Error: unable to parse file \"%s\"\n", filename); - free (file); + g_free (file); return NULL; } @@ -57,7 +56,7 @@ xml_parser_load (const char *filename) if (file->xpathCtx == NULL) { log_error ("Error: unable to create new XPath context\n"); xmlFreeDoc (file->doc); - free (file); + g_free (file); return FALSE; } @@ -74,24 +73,24 @@ xml_parser_close (TXMLFile *file) if (file) { xmlXPathFreeContext (file->xpathCtx); - xmlFreeDoc (file->doc); - free (file); - file = NULL; + xmlFreeDoc (file->doc); + g_free (file); + file = NULL; } } /* * xml_file_get_node_name: retrieve name of the XPath node */ -char * -xml_file_get_node_name (TXMLFile *file, const char *x_path) +gchar * +xml_file_get_node_name (TXMLFile *file, const gchar *x_path) { xmlXPathObjectPtr xpathObj; xmlNodePtr cur; - char *attrv; + gchar *attrv; if ((! file) || (! x_path)) - return NULL; + return NULL; /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); @@ -104,7 +103,7 @@ xml_file_get_node_name (TXMLFile *file, const char *x_path) if ((xpathObj->nodesetval) && (xpathObj->nodesetval->nodeNr > 0)) { cur = xpathObj->nodesetval->nodeTab[0]; if (cur->name) - attrv = strdup ((const char *) cur->name); + attrv = g_strdup ((const gchar *) cur->name); } xmlXPathFreeObject (xpathObj); @@ -117,16 +116,16 @@ xml_file_get_node_name (TXMLFile *file, const char *x_path) * - multiple matched nodes will be concatenated into one string * - otherwise please use [0], [1] etc. quantificators */ -char * -xml_file_get_node_value (TXMLFile *file, const char *x_path) +gchar * +xml_file_get_node_value (TXMLFile *file, const gchar *x_path) { xmlXPathObjectPtr xpathObj; xmlNodePtr cur; - char *val, *valx; + gchar *val, *valx; int i; if ((! file) || (! x_path)) - return NULL; + return NULL; /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); @@ -152,11 +151,11 @@ xml_file_get_node_value (TXMLFile *file, const char *x_path) { if (val == NULL) { - val = g_strdup ((char *) cur->content); + val = g_strdup ((gchar *) cur->content); } else { - valx = g_strconcat (val, (char *) cur->content, NULL); + valx = g_strconcat (val, (gchar *) cur->content, NULL); g_free (val); val = valx; } @@ -172,16 +171,16 @@ xml_file_get_node_value (TXMLFile *file, const char *x_path) /* * xml_file_get_node_attribute: retrieve attribute value from XPath node */ -char * -xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *attr) +gchar * +xml_file_get_node_attribute (TXMLFile *file, const gchar *x_path, const gchar *attr) { xmlXPathObjectPtr xpathObj; xmlNodePtr cur; xmlChar *attrvx; - char *attrv; + gchar *attrv; if ((! file) || (! x_path)) - return NULL; + return NULL; /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); @@ -195,7 +194,7 @@ xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *att cur = xpathObj->nodesetval->nodeTab[0]; attrvx = xmlGetProp (cur, (const xmlChar *) attr); if (attrvx) { - attrv = strdup ((char*) attrvx); + attrv = g_strdup ((gchar*) attrvx); xmlFree (attrvx); } @@ -209,18 +208,18 @@ xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *att return attrv; } -long -xml_file_get_node_attribute_long (TXMLFile *file, const char *x_path, const char *attr, const int _default) +long int +xml_file_get_node_attribute_long (TXMLFile *file, const gchar *x_path, const gchar *attr, const int _default) { - char *s; + gchar *s; long int i; s = xml_file_get_node_attribute (file, x_path, attr); if (s == NULL) - return _default; + return _default; i = atol (s); - free (s); + g_free (s); return i; } @@ -228,9 +227,9 @@ xml_file_get_node_attribute_long (TXMLFile *file, const char *x_path, const char * xml_file_get_node_present: existency test of the XPath node */ gboolean -xml_file_get_node_present (TXMLFile *file, const char *x_path) +xml_file_get_node_present (TXMLFile *file, const gchar *x_path) { - return xml_file_node_get_children_count (file, x_path) > 0; + return (xml_file_node_get_children_count (file, x_path) > 0); } @@ -238,13 +237,13 @@ xml_file_get_node_present (TXMLFile *file, const char *x_path) * xml_file_node_get_children_count: retrieve number of children items of the specified XPath node */ int -xml_file_node_get_children_count (TXMLFile *file, const char *x_path) +xml_file_node_get_children_count (TXMLFile *file, const gchar *x_path) { xmlXPathObjectPtr xpathObj; int count; if ((! file) || (! x_path)) - return 0; + return 0; /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); -- cgit v1.2.3