2008-12-30 Bill Holmes <billholmes54@gmail.com>
[mono.git] / eglib / src / gmarkup.c
index 6f342abd922a6efeae0e57893de0900d00e239c6..c256f123a146a4694f5dfd229e2508bd72036f6b 100644 (file)
@@ -42,7 +42,7 @@
 #include <stdio.h>
 #include <glib.h>
 
-#define set_error(msg...) do { if (error != NULL) *error = g_error_new (GINT_TO_POINTER (1), 1, msg); } while (0);
+#define set_error(msg, ...) do { if (error != NULL) *error = g_error_new (GINT_TO_POINTER (1), 1, msg, __VA_ARGS__); } while (0);
 
 typedef enum {
        START,
@@ -114,7 +114,7 @@ parse_value (const char *p, const char *end, char **value, GError **error)
        int l;
        
        if (*p != '"'){
-               set_error ("Expected the attribute value to start with a quote");
+               set_error ("%s", "Expected the attribute value to start with a quote");
                return end;
        }
        start = ++p;
@@ -122,9 +122,9 @@ parse_value (const char *p, const char *end, char **value, GError **error)
                ;
        if (p == end)
                return end;
-       l = p - start;
+       l = (int)(p - start);
        p++;
-       *value = malloc (l + 1);
+       *value = g_malloc (l + 1);
        if (*value == NULL)
                return end;
        strncpy (*value, start, l);
@@ -143,8 +143,8 @@ parse_name (const char *p, const char *end, char **value)
        if (p == end)
                return end;
 
-       l = p - start;
-       *value = malloc (l + 1);
+       l = (int)(p - start);
+       *value = g_malloc (l + 1);
        if (*value == NULL)
                return end;
        strncpy (*value, start, l);
@@ -183,24 +183,24 @@ parse_attributes (const char *p, const char *end, char ***names, char ***values,
 
                        p = skip_space (p, end);
                        if (p == end){
-                               free (name);
+                               g_free (name);
                                return p;
                        }
                        if (*p != '='){
                                set_error ("Expected an = after the attribute name `%s'", name);
-                               free (name);
+                               g_free (name);
                                return end;
                        }
                        p++;
                        p = skip_space (p, end);
                        if (p == end){
-                               free (name);
+                               g_free (name);
                                return end;
                        }
 
                        p = parse_value (p, end, &value, error);
                        if (p == end){
-                               free (name);
+                               g_free (name);
                                return p;
                        }
 
@@ -258,7 +258,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                                        context->state = START_ELEMENT;
                                continue;
                        }
-                       set_error ("Expected < to start the document");
+                       set_error ("%s", "Expected < to start the document");
                        goto fail;
 
                case SKIP_XML_DECLARATION:
@@ -271,7 +271,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                        for (; p < end && isspace (*p); p++)
                                ;
                        if (p == end){
-                               set_error ("Unfinished element");
+                               set_error ("%s", "Unfinished element");
                                goto fail;
                        }
 
@@ -282,14 +282,14 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                        }
                        
                        if (!(isascii (*p) && isalpha (*p))){
-                               set_error ("Expected an element name");
+                               set_error ("%s", "Expected an element name");
                                goto fail;
                        }
                        
                        for (++p; p < end && (isalnum (*p) || (*p == '.')); p++)
                                ;
                        if (p == end){
-                               set_error ("Expected an element");
+                               set_error ("%s", "Expected an element");
                                goto fail;
                        }
                        element_end = p;
@@ -297,7 +297,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                        for (; p < end && isspace (*p); p++)
                                ;
                        if (p == end){
-                               set_error ("Unfinished element");
+                               set_error ("%s", "Unfinished element");
                                goto fail;
                        }
                        p = parse_attributes (p, end, &names, &values, error, &full_stop, context->state);
@@ -308,11 +308,11 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                                }
                                /* Only set the error if parse_attributes did not */
                                if (error != NULL && *error == NULL)
-                                       set_error ("Unfinished sequence");
+                                       set_error ("%s", "Unfinished sequence");
                                goto fail;
                        }
-                       l = element_end - element_start;
-                       ename = malloc (l + 1);
+                       l = (int)(element_end - element_start);
+                       ename = g_malloc (l + 1);
                        if (ename == NULL)
                                goto fail;
                        strncpy (ename, element_start, l);
@@ -331,7 +331,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                        }
 
                        if (error != NULL && *error != NULL){
-                               free (ename);
+                               g_free (ename);
                                goto fail;
                        }
                        
@@ -343,7 +343,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                                                goto fail;
                                        }
                                }
-                               free (ename);
+                               g_free (ename);
                        } else {
                                context->level = g_slist_prepend (context->level, ename);
                        }
@@ -396,7 +396,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                        char *text;
 
                        if (context->level == NULL){
-                               set_error ("Too many closing tags, not enough open tags");
+                               set_error ("%s", "Too many closing tags, not enough open tags");
                                goto fail;
                        }
                        
@@ -404,11 +404,11 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
                        if (context->parser.end_element != NULL){
                                context->parser.end_element (context, text, context->user_data, error);
                                if (error != NULL && *error != NULL){
-                                       free (text);
+                                       g_free (text);
                                        goto fail;
                                }
                        }
-                       free (text);
+                       g_free (text);
 
                        while (p < end && *p != '>')
                                p++;