#include <stdint.h>
#include <stdlib.h>
+#include <libxml/xmlerror.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xmlwriter.h>
/* =================== Common API for xgettext and msgfmt =================== */
+/* ----------------------------- Error handling ----------------------------- */
+
+static void
+structured_error (void *data, xmlError *err)
+{
+ error (0, err->level == XML_ERR_FATAL ? EXIT_FAILURE : 0,
+ _("%s error: %s"), "libxml2", err->message);
+}
+
/* --------------------------------- Values --------------------------------- */
struct its_value_ty
if (doc == NULL)
{
const xmlError *err = xmlGetLastError ();
- error (0, 0, _("cannot read %s: %s"), filename, err->message);
+ error (0, err->level == XML_ERR_FATAL ? EXIT_FAILURE : 0,
+ _("cannot read %s: %s"), filename, err->message);
return false;
}
+ xmlSetStructuredErrorFunc (NULL, structured_error);
+
result = its_rule_list_add_from_doc (rules, doc);
xmlFreeDoc (doc);
+
+ xmlSetStructuredErrorFunc (NULL, NULL);
return result;
}
if (doc == NULL)
{
const xmlError *err = xmlGetLastError ();
- error (0, 0, _("cannot read %s: %s"), "(internal)", err->message);
+ error (0, err->level == XML_ERR_FATAL ? EXIT_FAILURE : 0,
+ _("cannot read %s: %s"), "(internal)", err->message);
return false;
}
+ xmlSetStructuredErrorFunc (NULL, structured_error);
+
result = its_rule_list_add_from_doc (rules, doc);
xmlFreeDoc (doc);
+
+ xmlSetStructuredErrorFunc (NULL, NULL);
return result;
}
if (doc == NULL)
{
const xmlError *err = xmlGetLastError ();
- error (0, 0, _("cannot read %s: %s"), logical_filename, err->message);
+ error (0, err->level == XML_ERR_FATAL ? EXIT_FAILURE : 0,
+ _("cannot read %s: %s"), logical_filename, err->message);
return;
}
+ xmlSetStructuredErrorFunc (NULL, structured_error);
+
its_rule_list_apply (rules, doc);
memset (&nodes, 0, sizeof (struct its_node_list_ty));
free (nodes.items);
xmlFreeDoc (doc);
+
+ xmlSetStructuredErrorFunc (NULL, NULL);
}
{
size_t i;
+ xmlSetStructuredErrorFunc (NULL, structured_error);
+
for (i = 0; i < context->nodes.nitems; i++)
its_merge_context_merge_node (context, context->nodes.items[i],
language,
mlp,
replace_text);
+
+ xmlSetStructuredErrorFunc (NULL, NULL);
}
struct its_merge_context_ty *
if (doc == NULL)
{
const xmlError *err = xmlGetLastError ();
- error (0, 0, _("cannot read %s: %s"), filename, err->message);
+ error (0, err->level == XML_ERR_FATAL ? EXIT_FAILURE : 0,
+ _("cannot read %s: %s"), filename, err->message);
return NULL;
}
+ xmlSetStructuredErrorFunc (NULL, structured_error);
+
its_rule_list_apply (rules, doc);
result = XMALLOC (struct its_merge_context_ty);
&result->nodes,
xmlDocGetRootElement (result->doc));
+ xmlSetStructuredErrorFunc (NULL, NULL);
return result;
}
its_merge_context_write (struct its_merge_context_ty *context,
FILE *fp)
{
+ xmlSetStructuredErrorFunc (NULL, structured_error);
+
xmlDocFormatDump (fp, context->doc, 1);
+
+ xmlSetStructuredErrorFunc (NULL, NULL);
}
void