1998-08-13 07:39:55 +04:00
/*
1998-10-20 10:14:16 +04:00
* error . c : module displaying / handling XML parser errors
*
1999-01-17 22:11:59 +03:00
* See Copyright for the status of this software .
*
1998-10-20 10:14:16 +04:00
* Daniel Veillard < Daniel . Veillard @ w3 . org >
1998-08-13 07:39:55 +04:00
*/
# include <stdio.h>
# include <stdarg.h>
# include "parser.h"
1999-08-30 01:02:19 +04:00
/**
* xmlParserPrintFileInfo :
* @ input : an xmlParserInputPtr input
*
* Displays the associated file and line informations for the current input
*/
void
1999-08-10 23:04:08 +04:00
xmlParserPrintFileInfo ( xmlParserInputPtr input ) {
if ( input ! = NULL ) {
if ( input - > filename )
fprintf ( stderr , " %s:%d: " , input - > filename ,
input - > line ) ;
else
1999-08-30 01:02:19 +04:00
fprintf ( stderr , " Entity: line %d: " , input - > line ) ;
1999-08-10 23:04:08 +04:00
}
}
1999-08-30 01:02:19 +04:00
/**
* xmlParserPrintFileContext :
* @ input : an xmlParserInputPtr input
*
* Displays current context within the input content for error tracking
*/
void
1999-08-10 23:04:08 +04:00
xmlParserPrintFileContext ( xmlParserInputPtr input ) {
1998-08-13 07:39:55 +04:00
const CHAR * cur , * base ;
int n ;
1999-08-10 23:04:08 +04:00
cur = input - > cur ;
base = input - > base ;
1999-02-22 13:33:01 +03:00
while ( ( cur > base ) & & ( ( * cur = = ' \n ' ) | | ( * cur = = ' \r ' ) ) ) {
1998-08-13 07:39:55 +04:00
cur - - ;
}
n = 0 ;
1999-03-01 15:28:53 +03:00
while ( ( n + + < 80 ) & & ( cur > base ) & & ( * cur ! = ' \n ' ) & & ( * cur ! = ' \r ' ) )
1998-08-13 07:39:55 +04:00
cur - - ;
if ( ( * cur = = ' \n ' ) | | ( * cur = = ' \r ' ) ) cur + + ;
base = cur ;
n = 0 ;
while ( ( * cur ! = 0 ) & & ( * cur ! = ' \n ' ) & & ( * cur ! = ' \r ' ) & & ( n < 79 ) ) {
fprintf ( stderr , " %c " , ( unsigned char ) * cur + + ) ;
n + + ;
}
fprintf ( stderr , " \n " ) ;
1999-08-10 23:04:08 +04:00
cur = input - > cur ;
1998-08-13 07:39:55 +04:00
while ( ( * cur = = ' \n ' ) | | ( * cur = = ' \r ' ) )
cur - - ;
n = 0 ;
1999-03-01 15:28:53 +03:00
while ( ( cur ! = base ) & & ( n + + < 80 ) ) {
1998-08-13 07:39:55 +04:00
fprintf ( stderr , " " ) ;
base + + ;
}
fprintf ( stderr , " ^ \n " ) ;
}
1999-08-10 23:04:08 +04: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 ;
xmlParserInputPtr input ;
1999-08-30 01:02:19 +04:00
xmlParserInputPtr cur = NULL ;
1999-08-10 23:04:08 +04:00
va_list args ;
input = ctxt - > input ;
1999-08-30 01:02:19 +04:00
if ( ( input - > filename = = NULL ) & & ( ctxt - > inputNr > 1 ) ) {
cur = input ;
1999-08-10 23:04:08 +04:00
input = ctxt - > inputTab [ ctxt - > inputNr - 2 ] ;
1999-08-30 01:02:19 +04:00
}
1999-08-10 23:04:08 +04:00
xmlParserPrintFileInfo ( input ) ;
fprintf ( stderr , " error: " ) ;
va_start ( args , msg ) ;
vfprintf ( stderr , msg , args ) ;
va_end ( args ) ;
xmlParserPrintFileContext ( input ) ;
1999-08-30 01:02:19 +04:00
if ( cur ! = NULL ) {
xmlParserPrintFileInfo ( cur ) ;
fprintf ( stderr , " \n " ) ;
xmlParserPrintFileContext ( cur ) ;
}
1999-08-10 23:04:08 +04:00
}
1998-10-20 10:14:16 +04:00
/**
* xmlParserWarning :
1999-06-02 21:44:04 +04:00
* @ ctx : an XML parser context
1998-10-20 10:14:16 +04: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 07:39:55 +04:00
*/
1998-10-20 10:14:16 +04:00
void
1999-05-29 15:51:49 +04:00
xmlParserWarning ( void * ctx , const char * msg , . . . )
1998-10-20 10:14:16 +04:00
{
1999-05-29 15:51:49 +04:00
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
1999-08-10 23:04:08 +04:00
xmlParserInputPtr input ;
1999-08-30 01:02:19 +04:00
xmlParserInputPtr cur = NULL ;
1998-08-13 07:39:55 +04:00
va_list args ;
1999-08-10 23:04:08 +04:00
input = ctxt - > input ;
1999-08-30 01:02:19 +04:00
if ( ( input - > filename = = NULL ) & & ( ctxt - > inputNr > 1 ) ) {
cur = input ;
1999-08-10 23:04:08 +04:00
input = ctxt - > inputTab [ ctxt - > inputNr - 2 ] ;
1999-08-30 01:02:19 +04:00
}
1999-08-10 23:04:08 +04:00
xmlParserPrintFileInfo ( input ) ;
1998-08-13 07:39:55 +04:00
fprintf ( stderr , " warning: " ) ;
1999-08-10 23:04:08 +04:00
va_start ( args , msg ) ;
1998-08-13 07:39:55 +04:00
vfprintf ( stderr , msg , args ) ;
1999-03-24 23:42:16 +03:00
va_end ( args ) ;
1999-08-10 23:04:08 +04:00
xmlParserPrintFileContext ( input ) ;
1999-08-30 01:02:19 +04:00
if ( cur ! = NULL ) {
xmlParserPrintFileInfo ( cur ) ;
fprintf ( stderr , " \n " ) ;
xmlParserPrintFileContext ( cur ) ;
}
1999-08-10 23:04:08 +04: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 ;
xmlParserInputPtr input ;
va_list args ;
input = ctxt - > input ;
if ( ( input - > filename = = NULL ) & & ( ctxt - > inputNr > 1 ) )
input = ctxt - > inputTab [ ctxt - > inputNr - 2 ] ;
xmlParserPrintFileInfo ( input ) ;
fprintf ( stderr , " validity error: " ) ;
va_start ( args , msg ) ;
vfprintf ( stderr , msg , args ) ;
va_end ( args ) ;
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 .
*/
void
xmlParserValidityWarning ( void * ctx , const char * msg , . . . )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
xmlParserInputPtr input ;
va_list args ;
input = ctxt - > input ;
if ( ( input - > filename = = NULL ) & & ( ctxt - > inputNr > 1 ) )
input = ctxt - > inputTab [ ctxt - > inputNr - 2 ] ;
xmlParserPrintFileInfo ( input ) ;
fprintf ( stderr , " validity warning: " ) ;
va_start ( args , msg ) ;
vfprintf ( stderr , msg , args ) ;
va_end ( args ) ;
xmlParserPrintFileContext ( input ) ;
1998-08-13 07:39:55 +04:00
}
1998-10-20 10:14:16 +04:00