From e2238d5617c3f16e3f8fff16609d692064affd1e Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 9 Oct 2003 13:14:55 +0000 Subject: [PATCH] converted too small cleanup Daniel * HTMLtree.c include/libxml/xmlerror.h: converted too * tree.c: small cleanup Daniel --- ChangeLog | 5 + HTMLtree.c | 71 ++-- include/libxml/xmlerror.h | 666 ++++++++++++++++++-------------------- tree.c | 7 +- 4 files changed, 378 insertions(+), 371 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31fc99bf..95a0c771 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Oct 9 15:13:53 CEST 2003 Daniel Veillard + + * HTMLtree.c include/libxml/xmlerror.h: converted too + * tree.c: small cleanup + Thu Oct 9 13:44:57 CEST 2003 Daniel Veillard * xinclude.c: comment fix diff --git a/HTMLtree.c b/HTMLtree.c index 41ce1eef..11a61255 100644 --- a/HTMLtree.c +++ b/HTMLtree.c @@ -316,6 +316,55 @@ htmlIsBooleanAttr(const xmlChar *name) } #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 @@ htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, } 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 @@ htmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { xmlInitParser(); if (cur == NULL) { -#ifdef DEBUG_TREE - xmlGenericError(xmlGenericErrorContext, - "htmlDocDumpMemory : document == NULL\n"); -#endif *mem = NULL; *size = 0; return; @@ -561,8 +605,7 @@ htmlDtdDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, 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, "