1998-08-13 03:39:55 +00:00
/*
1998-10-20 06:14:16 +00:00
* error . c : module displaying / handling XML parser errors
*
1999-01-17 19:11:59 +00:00
* See Copyright for the status of this software .
*
1998-10-20 06:14:16 +00:00
* Daniel Veillard < Daniel . Veillard @ w3 . org >
1998-08-13 03:39:55 +00:00
*/
1999-12-22 11:30:41 +00:00
# ifdef WIN32
# include "win32config.h"
# else
# include "config.h"
# endif
1998-08-13 03:39:55 +00:00
# include <stdio.h>
# include <stdarg.h>
2000-04-03 19:48:13 +00:00
# include <libxml/parser.h>
2000-10-25 19:56:55 +00:00
# include <libxml/xmlerror.h>
/************************************************************************
* *
* Handling of out of context errors *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlGenericErrorDefaultFunc :
* @ ctx : an error context
* @ msg : the message to display / transmit
* @ . . . : extra parameters for the message display
*
* Default handler for out of context error messages .
*/
void
xmlGenericErrorDefaultFunc ( void * ctx , const char * msg , . . . ) {
va_list args ;
if ( xmlGenericErrorContext = = NULL )
xmlGenericErrorContext = ( void * ) stderr ;
va_start ( args , msg ) ;
vfprintf ( ( FILE * ) xmlGenericErrorContext , msg , args ) ;
va_end ( args ) ;
}
xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc ;
void * xmlGenericErrorContext = NULL ;
/**
* xmlSetGenericErrorFunc :
* @ ctx : the new error handling context
* @ handler : the new handler function
*
* Function to reset the handler and the error context for out of
* context error messages .
* This simply means that @ handler will be called for subsequent
* error messages while not parsing nor validating . And @ ctx will
* be passed as first argument to @ handler
* One can simply force messages to be emitted to another FILE * than
* stderr by setting @ ctx to this file handle and @ handler to NULL .
*/
void
xmlSetGenericErrorFunc ( void * ctx , xmlGenericErrorFunc handler ) {
if ( ctx ! = NULL )
xmlGenericErrorContext = ctx ;
if ( handler ! = NULL )
xmlGenericError = handler ;
}
/************************************************************************
* *
* Handling of parsing errors *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-08-13 03:39:55 +00:00
1999-08-29 21:02:19 +00:00
/**
* xmlParserPrintFileInfo :
* @ input : an xmlParserInputPtr input
*
* Displays the associated file and line informations for the current input
*/
void
1999-08-10 19:04:08 +00:00
xmlParserPrintFileInfo ( xmlParserInputPtr input ) {
if ( input ! = NULL ) {
if ( input - > filename )
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext ,
" %s:%d: " , input - > filename ,
1999-08-10 19:04:08 +00:00
input - > line ) ;
else
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext ,
" Entity: line %d: " , input - > line ) ;
1999-08-10 19:04:08 +00:00
}
}
1999-08-29 21:02:19 +00:00
/**
* xmlParserPrintFileContext :
* @ input : an xmlParserInputPtr input
*
* Displays current context within the input content for error tracking
*/
void
1999-08-10 19:04:08 +00:00
xmlParserPrintFileContext ( xmlParserInputPtr input ) {
1999-09-23 22:19:22 +00:00
const xmlChar * cur , * base ;
1998-08-13 03:39:55 +00:00
int n ;
2000-01-03 11:08:02 +00:00
if ( input = = NULL ) return ;
1999-08-10 19:04:08 +00:00
cur = input - > cur ;
base = input - > base ;
1999-02-22 10:33:01 +00:00
while ( ( cur > base ) & & ( ( * cur = = ' \n ' ) | | ( * cur = = ' \r ' ) ) ) {
1998-08-13 03:39:55 +00:00
cur - - ;
}
n = 0 ;
1999-03-01 12:28:53 +00:00
while ( ( n + + < 80 ) & & ( cur > base ) & & ( * cur ! = ' \n ' ) & & ( * cur ! = ' \r ' ) )
1998-08-13 03:39:55 +00:00
cur - - ;
if ( ( * cur = = ' \n ' ) | | ( * cur = = ' \r ' ) ) cur + + ;
base = cur ;
n = 0 ;
while ( ( * cur ! = 0 ) & & ( * cur ! = ' \n ' ) & & ( * cur ! = ' \r ' ) & & ( n < 79 ) ) {
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext ,
" %c " , ( unsigned char ) * cur + + ) ;
1998-08-13 03:39:55 +00:00
n + + ;
}
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " \n " ) ;
1999-08-10 19:04:08 +00:00
cur = input - > cur ;
1998-08-13 03:39:55 +00:00
while ( ( * cur = = ' \n ' ) | | ( * cur = = ' \r ' ) )
cur - - ;
n = 0 ;
1999-03-01 12:28:53 +00:00
while ( ( cur ! = base ) & & ( n + + < 80 ) ) {
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " " ) ;
1998-08-13 03:39:55 +00:00
base + + ;
}
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " ^ \n " ) ;
1998-08-13 03:39:55 +00:00
}
1999-08-10 19:04:08 +00:00
/**
* 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 .
*/
void
xmlParserError ( void * ctx , const char * msg , . . . )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
2000-09-10 16:14:55 +00:00
xmlParserInputPtr input = NULL ;
1999-08-29 21:02:19 +00:00
xmlParserInputPtr cur = NULL ;
1999-08-10 19:04:08 +00:00
va_list args ;
2000-09-10 16:14:55 +00:00
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 ) ;
1999-08-29 21:02:19 +00:00
}
1999-08-10 19:04:08 +00:00
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " error: " ) ;
1999-08-10 19:04:08 +00:00
va_start ( args , msg ) ;
2000-10-25 19:56:55 +00:00
vfprintf ( xmlGenericErrorContext , msg , args ) ;
1999-08-10 19:04:08 +00:00
va_end ( args ) ;
2000-09-10 16:14:55 +00:00
if ( ctxt ! = NULL ) {
xmlParserPrintFileContext ( input ) ;
if ( cur ! = NULL ) {
xmlParserPrintFileInfo ( cur ) ;
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " \n " ) ;
2000-09-10 16:14:55 +00:00
xmlParserPrintFileContext ( cur ) ;
}
1999-08-29 21:02:19 +00:00
}
1999-08-10 19:04:08 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlParserWarning :
1999-06-02 17:44:04 +00:00
* @ ctx : an XML parser context
1998-10-20 06:14:16 +00:00
* @ 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 .
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
1999-05-29 11:51:49 +00:00
xmlParserWarning ( void * ctx , const char * msg , . . . )
1998-10-20 06:14:16 +00:00
{
1999-05-29 11:51:49 +00:00
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
2000-09-10 16:14:55 +00:00
xmlParserInputPtr input = NULL ;
1999-08-29 21:02:19 +00:00
xmlParserInputPtr cur = NULL ;
1998-08-13 03:39:55 +00:00
va_list args ;
2000-09-10 16:14:55 +00:00
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 ) ;
1999-08-29 21:02:19 +00:00
}
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " warning: " ) ;
1999-08-10 19:04:08 +00:00
va_start ( args , msg ) ;
2000-10-25 19:56:55 +00:00
vfprintf ( xmlGenericErrorContext , msg , args ) ;
1999-03-24 20:42:16 +00:00
va_end ( args ) ;
1999-08-10 19:04:08 +00:00
2000-10-25 19:56:55 +00:00
2000-09-10 16:14:55 +00:00
if ( ctxt ! = NULL ) {
xmlParserPrintFileContext ( input ) ;
if ( cur ! = NULL ) {
xmlParserPrintFileInfo ( cur ) ;
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " \n " ) ;
2000-09-10 16:14:55 +00:00
xmlParserPrintFileContext ( cur ) ;
}
1999-08-29 21:02:19 +00:00
}
1999-08-10 19:04:08 +00:00
}
2000-10-25 19:56:55 +00:00
/************************************************************************
* *
* Handling of validation errors *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-08-10 19:04:08 +00:00
/**
* 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 .
*/
void
xmlParserValidityError ( void * ctx , const char * msg , . . . )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
2000-09-10 16:14:55 +00:00
xmlParserInputPtr input = NULL ;
1999-08-10 19:04:08 +00:00
va_list args ;
2000-09-10 16:14:55 +00:00
if ( ctxt ! = NULL ) {
input = ctxt - > input ;
if ( ( input - > filename = = NULL ) & & ( ctxt - > inputNr > 1 ) )
input = ctxt - > inputTab [ ctxt - > inputNr - 2 ] ;
xmlParserPrintFileInfo ( input ) ;
}
1999-08-10 19:04:08 +00:00
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " validity error: " ) ;
1999-08-10 19:04:08 +00:00
va_start ( args , msg ) ;
2000-10-25 19:56:55 +00:00
vfprintf ( xmlGenericErrorContext , msg , args ) ;
1999-08-10 19:04:08 +00:00
va_end ( args ) ;
2000-09-10 16:14:55 +00:00
if ( ctxt ! = NULL ) {
xmlParserPrintFileContext ( input ) ;
}
1999-08-10 19:04:08 +00:00
}
/**
* 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 .
*/
void
xmlParserValidityWarning ( void * ctx , const char * msg , . . . )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
2000-09-10 16:14:55 +00:00
xmlParserInputPtr input = NULL ;
1999-08-10 19:04:08 +00:00
va_list args ;
2000-09-10 16:14:55 +00:00
if ( ctxt ! = NULL ) {
input = ctxt - > input ;
if ( ( input - > filename = = NULL ) & & ( ctxt - > inputNr > 1 ) )
input = ctxt - > inputTab [ ctxt - > inputNr - 2 ] ;
1999-08-10 19:04:08 +00:00
2000-09-10 16:14:55 +00:00
xmlParserPrintFileInfo ( input ) ;
}
1999-08-10 19:04:08 +00:00
2000-10-25 19:56:55 +00:00
xmlGenericError ( xmlGenericErrorContext , " validity warning: " ) ;
1999-08-10 19:04:08 +00:00
va_start ( args , msg ) ;
2000-10-25 19:56:55 +00:00
vfprintf ( xmlGenericErrorContext , msg , args ) ;
1999-08-10 19:04:08 +00:00
va_end ( args ) ;
2000-09-10 16:14:55 +00:00
if ( ctxt ! = NULL ) {
xmlParserPrintFileContext ( input ) ;
}
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
2000-10-25 19:56:55 +00:00