#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,
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;
;
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);
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);
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;
}
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:
for (; p < end && isspace (*p); p++)
;
if (p == end){
- set_error ("Unfinished element");
+ set_error ("%s", "Unfinished element");
goto fail;
}
}
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;
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);
}
/* 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);
}
if (error != NULL && *error != NULL){
- free (ename);
+ g_free (ename);
goto fail;
}
goto fail;
}
}
- free (ename);
+ g_free (ename);
} else {
context->level = g_slist_prepend (context->level, ename);
}
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;
}
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++;