⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 error.c

📁 libxml,在UNIX/LINUX下非常重要的一个库,为XML相关应用提供方便.目前上载的是最新版本,若要取得最新版本,请参考里面的readme.
💻 C
📖 第 1 页 / 共 2 页
字号:
     */    if (msg == NULL) {        str = (char *) xmlStrdup(BAD_CAST "No error message provided");    } else {        XML_GET_VAR_STR(msg, str);    }    /*     * specific processing if a parser context is provided     */    if (ctxt != NULL) {        if (file == NULL) {            input = ctxt->input;            if ((input != NULL) && (input->filename == NULL) &&                (ctxt->inputNr > 1)) {                input = ctxt->inputTab[ctxt->inputNr - 2];            }            if (input != NULL) {                file = input->filename;                line = input->line;                col = input->col;            }        }        to = &ctxt->lastError;    } else if ((node != NULL) && (file == NULL)) {	int i;	if ((node->doc != NULL) && (node->doc->URL != NULL))	    baseptr = node;	for (i = 0;	     ((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE));	     i++)	     node = node->parent;        if ((baseptr == NULL) && (node != NULL) &&	    (node->doc != NULL) && (node->doc->URL != NULL))	    baseptr = node;	if ((node != NULL) && (node->type == XML_ELEMENT_NODE))	    line = node->line;    }    /*     * Save the information about the error     */    xmlResetError(to);    to->domain = domain;    to->code = code;    to->message = str;    to->level = level;    if (file != NULL)        to->file = (char *) xmlStrdup((const xmlChar *) file);    else if (baseptr != NULL) {#ifdef LIBXML_XINCLUDE_ENABLED	/*	 * We check if the error is within an XInclude section and,	 * if so, attempt to print out the href of the XInclude instead	 * of the usual "base" (doc->URL) for the node (bug 152623).	 */        xmlNodePtr prev = baseptr;	int inclcount = 0;	while (prev != NULL) {	    if (prev->prev == NULL)	        prev = prev->parent;	    else {	        prev = prev->prev;		if (prev->type == XML_XINCLUDE_START) {		    if (--inclcount < 0)		        break;		} else if (prev->type == XML_XINCLUDE_END)		    inclcount++;	    }	}	if (prev != NULL) {	    to->file = (char *) xmlGetProp(prev, BAD_CAST "href");	} else#endif	    to->file = (char *) xmlStrdup(baseptr->doc->URL);	file = to->file;    }    to->line = line;    if (str1 != NULL)        to->str1 = (char *) xmlStrdup((const xmlChar *) str1);    if (str2 != NULL)        to->str2 = (char *) xmlStrdup((const xmlChar *) str2);    if (str3 != NULL)        to->str3 = (char *) xmlStrdup((const xmlChar *) str3);    to->int1 = int1;    to->int2 = col;    to->node = node;    to->ctxt = ctx;    if (to != &xmlLastError)        xmlCopyError(to,&xmlLastError);    /*     * Find the callback channel if channel param is NULL     */    if ((ctxt != NULL) && (channel == NULL) && (xmlStructuredError == NULL) && (ctxt->sax != NULL)) {        if (level == XML_ERR_WARNING)	    channel = ctxt->sax->warning;        else	    channel = ctxt->sax->error;	data = ctxt->userData;    } else if (channel == NULL) {        if (xmlStructuredError != NULL)	    schannel = xmlStructuredError;	else	    channel = xmlGenericError;	data = xmlGenericErrorContext;    }    if (schannel != NULL) {        schannel(data, to);	return;    }    if (channel == NULL)        return;    if ((channel == xmlParserError) ||        (channel == xmlParserWarning) ||	(channel == xmlParserValidityError) ||	(channel == xmlParserValidityWarning))	xmlReportError(to, ctxt, str, NULL, NULL);    else if ((channel == (xmlGenericErrorFunc) fprintf) ||             (channel == xmlGenericErrorDefaultFunc))	xmlReportError(to, ctxt, str, channel, data);    else	channel(data, "%s", str);}/** * __xmlSimpleError: * @domain: where the error comes from * @code: the error code * @node: the context node * @extra:  extra informations * * Handle an out of memory condition */void__xmlSimpleError(int domain, int code, xmlNodePtr node,                 const char *msg, const char *extra){    if (code == XML_ERR_NO_MEMORY) {	if (extra)	    __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,			    XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,			    NULL, NULL, 0, 0,			    "Memory allocation failed : %s\n", extra);	else	    __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,			    XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,			    NULL, NULL, 0, 0, "Memory allocation failed\n");    } else {	__xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,			code, XML_ERR_ERROR, NULL, 0, extra,			NULL, NULL, 0, 0, msg, extra);    }}/** * xmlParserError: * @ctx:  an XML parser context * @msg:  the message to display/transmit * @...:  extra parameters for the message display *  * Display and format an error messages, gives file, line, position and * extra parameters. */voidxmlParserError(void *ctx, const char *msg, ...){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlParserInputPtr input = NULL;    xmlParserInputPtr cur = NULL;    char * str;    if (ctxt != NULL) {	input = ctxt->input;	if ((input != NULL) && (input->filename == NULL) &&	    (ctxt->inputNr > 1)) {	    cur = input;	    input = ctxt->inputTab[ctxt->inputNr - 2];	}	xmlParserPrintFileInfo(input);    }    xmlGenericError(xmlGenericErrorContext, "error: ");    XML_GET_VAR_STR(msg, str);    xmlGenericError(xmlGenericErrorContext, "%s", str);    if (str != NULL)	xmlFree(str);    if (ctxt != NULL) {	xmlParserPrintFileContext(input);	if (cur != NULL) {	    xmlParserPrintFileInfo(cur);	    xmlGenericError(xmlGenericErrorContext, "\n");	    xmlParserPrintFileContext(cur);	}    }}/** * xmlParserWarning: * @ctx:  an XML parser context * @msg:  the message to display/transmit * @...:  extra parameters for the message display *  * Display and format a warning messages, gives file, line, position and * extra parameters. */voidxmlParserWarning(void *ctx, const char *msg, ...){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlParserInputPtr input = NULL;    xmlParserInputPtr cur = NULL;    char * str;    if (ctxt != NULL) {	input = ctxt->input;	if ((input != NULL) && (input->filename == NULL) &&	    (ctxt->inputNr > 1)) {	    cur = input;	    input = ctxt->inputTab[ctxt->inputNr - 2];	}	xmlParserPrintFileInfo(input);    }            xmlGenericError(xmlGenericErrorContext, "warning: ");    XML_GET_VAR_STR(msg, str);    xmlGenericError(xmlGenericErrorContext, "%s", str);    if (str != NULL)	xmlFree(str);    if (ctxt != NULL) {	xmlParserPrintFileContext(input);	if (cur != NULL) {	    xmlParserPrintFileInfo(cur);	    xmlGenericError(xmlGenericErrorContext, "\n");	    xmlParserPrintFileContext(cur);	}    }}/************************************************************************ * 									* * 			Handling of validation errors			* * 									* ************************************************************************//** * xmlParserValidityError: * @ctx:  an XML parser context * @msg:  the message to display/transmit * @...:  extra parameters for the message display *  * Display and format an validity error messages, gives file, * line, position and extra parameters. */voidxmlParserValidityError(void *ctx, const char *msg, ...){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlParserInputPtr input = NULL;    char * str;    int len = xmlStrlen((const xmlChar *) msg);    static int had_info = 0;    if ((len > 1) && (msg[len - 2] != ':')) {	if (ctxt != NULL) {	    input = ctxt->input;	    if ((input->filename == NULL) && (ctxt->inputNr > 1))		input = ctxt->inputTab[ctxt->inputNr - 2];			    if (had_info == 0) {		xmlParserPrintFileInfo(input);	    }	}	xmlGenericError(xmlGenericErrorContext, "validity error: ");	had_info = 0;    } else {	had_info = 1;    }    XML_GET_VAR_STR(msg, str);    xmlGenericError(xmlGenericErrorContext, "%s", str);    if (str != NULL)	xmlFree(str);    if ((ctxt != NULL) && (input != NULL)) {	xmlParserPrintFileContext(input);    }}/** * xmlParserValidityWarning: * @ctx:  an XML parser context * @msg:  the message to display/transmit * @...:  extra parameters for the message display *  * Display and format a validity warning messages, gives file, line, * position and extra parameters. */voidxmlParserValidityWarning(void *ctx, const char *msg, ...){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    xmlParserInputPtr input = NULL;    char * str;    int len = xmlStrlen((const xmlChar *) msg);    if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) {	input = ctxt->input;	if ((input->filename == NULL) && (ctxt->inputNr > 1))	    input = ctxt->inputTab[ctxt->inputNr - 2];	xmlParserPrintFileInfo(input);    }            xmlGenericError(xmlGenericErrorContext, "validity warning: ");    XML_GET_VAR_STR(msg, str);    xmlGenericError(xmlGenericErrorContext, "%s", str);    if (str != NULL)	xmlFree(str);    if (ctxt != NULL) {	xmlParserPrintFileContext(input);    }}/************************************************************************ *									* *			Extended Error Handling				* *									* ************************************************************************//** * xmlGetLastError: * * Get the last global error registered. This is per thread if compiled * with thread support. * * Returns NULL if no error occured or a pointer to the error */xmlErrorPtrxmlGetLastError(void){    if (xmlLastError.code == XML_ERR_OK)        return (NULL);    return (&xmlLastError);}/** * xmlResetError: * @err: pointer to the error. * * Cleanup the error. */voidxmlResetError(xmlErrorPtr err){    if (err == NULL)        return;    if (err->code == XML_ERR_OK)        return;    if (err->message != NULL)        xmlFree(err->message);    if (err->file != NULL)        xmlFree(err->file);    if (err->str1 != NULL)        xmlFree(err->str1);    if (err->str2 != NULL)        xmlFree(err->str2);    if (err->str3 != NULL)        xmlFree(err->str3);    memset(err, 0, sizeof(xmlError));    err->code = XML_ERR_OK;}/** * xmlResetLastError: * * Cleanup the last global error registered. For parsing error * this does not change the well-formedness result. */voidxmlResetLastError(void){    if (xmlLastError.code == XML_ERR_OK)        return;    xmlResetError(&xmlLastError);}/** * xmlCtxtGetLastError: * @ctx:  an XML parser context * * Get the last parsing error registered. * * Returns NULL if no error occured or a pointer to the error */xmlErrorPtrxmlCtxtGetLastError(void *ctx){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    if (ctxt == NULL)        return (NULL);    if (ctxt->lastError.code == XML_ERR_OK)        return (NULL);    return (&ctxt->lastError);}/** * xmlCtxtResetLastError: * @ctx:  an XML parser context * * Cleanup the last global error registered. For parsing error * this does not change the well-formedness result. */voidxmlCtxtResetLastError(void *ctx){    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;    if (ctxt == NULL)        return;    if (ctxt->lastError.code == XML_ERR_OK)        return;    xmlResetError(&ctxt->lastError);}/** * xmlCopyError: * @from:  a source error * @to:  a target error * * Save the original error to the new place. * * Returns 0 in case of success and -1 in case of error. */intxmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {    char *message, *file, *str1, *str2, *str3;    if ((from == NULL) || (to == NULL))        return(-1);    message = (char *) xmlStrdup((xmlChar *) from->message);    file = (char *) xmlStrdup ((xmlChar *) from->file);    str1 = (char *) xmlStrdup ((xmlChar *) from->str1);    str2 = (char *) xmlStrdup ((xmlChar *) from->str2);    str3 = (char *) xmlStrdup ((xmlChar *) from->str3);    if (to->message != NULL)        xmlFree(to->message);    if (to->file != NULL)        xmlFree(to->file);    if (to->str1 != NULL)        xmlFree(to->str1);    if (to->str2 != NULL)        xmlFree(to->str2);    if (to->str3 != NULL)        xmlFree(to->str3);    to->domain = from->domain;    to->code = from->code;    to->level = from->level;    to->line = from->line;    to->node = from->node;    to->int1 = from->int1;    to->int2 = from->int2;    to->node = from->node;    to->ctxt = from->ctxt;    to->message = message;    to->file = file;    to->str1 = str1;    to->str2 = str2;    to->str3 = str3;    return 0;}#define bottom_error#include "elfgcchack.h"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -