@@ -299,6 +299,13 @@ void static inline attr_alloc(attr_buffer* b, int ask)
299 b->alloc = buf2;
299 b->alloc = buf2;
302+void set_error(document* d, char* msg)
304+ if (d->error_message != NULL) return; // keep the first error message
305+ d->error_message = malloc(strlen(msg)+1);
306+ strcpy(d->error_message, msg);
302// you now expect a name, perhaps preceeded by whitespace
309// you now expect a name, perhaps preceeded by whitespace
303// the name may be empty
310// the name may be empty
304str static inline parse_name(document* d)
311str static inline parse_name(document* d)
@@ -326,7 +333,7 @@ str static inline parse_attrval(document* d)
326 int start = doc_position(d);
333 int start = doc_position(d);
327 if (!find(d, c))
334 if (!find(d, c))
329− d->error_message = _strdup("Couldn't find closing attribute bit");
336+ set_error(d, "Couldn't find closing attribute bit");
330 return start_length(0, 0);
337 return start_length(0, 0);
332 skip(d, 1);
339 skip(d, 1);
@@ -385,7 +392,7 @@ void static inline parse_tag(document* d)
386 else if (c != '>')
393 else if (c != '>')
388− d->error_message = _strdup("Gunk at the end of the tag");
395+ set_error(d, "Gunk at the end of the tag");
391 d->nodes.nodes[me].inner.start = doc_position(d);
398 d->nodes.nodes[me].inner.start = doc_position(d);
@@ -408,10 +415,10 @@ void static inline parse_tag(document* d)
411− d->error_message = _strdup("Mismatch in closing tags");
418+ set_error(d, "Mismatch in closing tags");
414− d->error_message = _strdup("Weirdness when trying to close tags");
421+ set_error(d, "Weirdness when trying to close tags");
417// Parser until </, return the index of your node children
424// Parser until </, return the index of your node children
@@ -483,7 +490,7 @@ document* document_parse(char* s, int slen)
484 if (d->cursor < d->end && d->error_message == NULL)
491 if (d->cursor < d->end && d->error_message == NULL)
486− d->error_message = _strdup("Trailing junk at the end of the document");
493+ set_error(d, "Trailing junk at the end of the document");
488 return d;
495 return d;