converted too small cleanup Daniel
* HTMLtree.c include/libxml/xmlerror.h: converted too
* tree.c: small cleanup
Daniel
diff --git a/HTMLtree.c b/HTMLtree.c
index 41ce1ee..11a6125 100644
--- a/HTMLtree.c
+++ b/HTMLtree.c
@@ -318,6 +318,55 @@
#ifdef LIBXML_OUTPUT_ENABLED
/************************************************************************
* *
+ * Output error handlers *
+ * *
+ ************************************************************************/
+/**
+ * htmlSaveErrMemory:
+ * @extra: extra informations
+ *
+ * Handle an out of memory condition
+ */
+static void
+htmlSaveErrMemory(const char *extra)
+{
+ __xmlSimpleError(XML_FROM_OUTPUT, XML_ERR_NO_MEMORY, NULL, NULL, extra);
+}
+
+/**
+ * htmlSaveErr:
+ * @code: the error number
+ * @node: the location of the error.
+ * @extra: extra informations
+ *
+ * Handle an out of memory condition
+ */
+static void
+htmlSaveErr(int code, xmlNodePtr node, const char *extra)
+{
+ const char *msg = NULL;
+
+ switch(code) {
+ case XML_SAVE_NOT_UTF8:
+ msg = "string is not in UTF-8";
+ break;
+ case XML_SAVE_CHAR_INVALID:
+ msg = "invalid character value";
+ break;
+ case XML_SAVE_UNKNOWN_ENCODING:
+ msg = "unknown encoding %s";
+ break;
+ case XML_SAVE_NO_DOCTYPE:
+ msg = "HTML has no DOCTYPE";
+ break;
+ default:
+ msg = "unexpected error number";
+ }
+ __xmlSimpleError(XML_FROM_OUTPUT, code, node, msg, extra);
+}
+
+/************************************************************************
+ * *
* Dumping HTML tree content to a simple buffer *
* *
************************************************************************/
@@ -352,8 +401,7 @@
}
outbuf = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer));
if (outbuf == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "htmlNodeDumpFormat: out of memory!\n");
+ htmlSaveErrMemory("allocating HTML output buffer");
return (-1);
}
memset(outbuf, 0, (size_t) sizeof(xmlOutputBuffer));
@@ -475,10 +523,6 @@
xmlInitParser();
if (cur == NULL) {
-#ifdef DEBUG_TREE
- xmlGenericError(xmlGenericErrorContext,
- "htmlDocDumpMemory : document == NULL\n");
-#endif
*mem = NULL;
*size = 0;
return;
@@ -561,8 +605,7 @@
xmlDtdPtr cur = doc->intSubset;
if (cur == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "htmlDtdDumpOutput : no internal subset\n");
+ htmlSaveErr(XML_SAVE_NO_DOCTYPE, (xmlNodePtr) doc, NULL);
return;
}
xmlOutputBufferWriteString(buf, "<!DOCTYPE ");
@@ -602,8 +645,6 @@
*/
if (cur == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "htmlAttrDumpOutput : property == NULL\n");
return;
}
xmlOutputBufferWriteString(buf, " ");
@@ -655,8 +696,6 @@
static void
htmlAttrListDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur, const char *encoding) {
if (cur == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "htmlAttrListDumpOutput : property == NULL\n");
return;
}
while (cur != NULL) {
@@ -681,8 +720,6 @@
htmlNodeListDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc,
xmlNodePtr cur, const char *encoding, int format) {
if (cur == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "htmlNodeListDumpOutput : node == NULL\n");
return;
}
while (cur != NULL) {
@@ -709,8 +746,6 @@
xmlInitParser();
if (cur == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "htmlNodeDumpFormatOutput : node == NULL\n");
return;
}
/*
@@ -958,10 +993,6 @@
xmlInitParser();
if (cur == NULL) {
-#ifdef DEBUG_TREE
- xmlGenericError(xmlGenericErrorContext,
- "htmlDocDump : document == NULL\n");
-#endif
return(-1);
}