Rebase for libxml 2.9.7
[platform/upstream/libxml2.git] / error.c
diff --git a/error.c b/error.c
index a891faa..50e9e6f 100644 (file)
--- a/error.c
+++ b/error.c
@@ -18,7 +18,7 @@
 
 void XMLCDECL xmlGenericErrorDefaultFunc       (void *ctx ATTRIBUTE_UNUSED,
                                 const char *msg,
-                                ...);
+                                ...) LIBXML_ATTR_FORMAT(2,3);
 
 #define XML_GET_VAR_STR(msg, str) {                            \
     int       size, prev_size = -1;                            \
@@ -33,7 +33,7 @@ void XMLCDECL xmlGenericErrorDefaultFunc      (void *ctx ATTRIBUTE_UNUSED,
                                                                \
     while (size < 64000) {                                     \
        va_start(ap, msg);                                      \
-       chars = vsnprintf(str, size, msg, ap);                  \
+       chars = vsnprintf(str, size, msg, ap);                  \
        va_end(ap);                                             \
        if ((chars > -1) && (chars < size)) {                   \
            if (prev_size == chars) {                           \
@@ -54,9 +54,9 @@ void XMLCDECL xmlGenericErrorDefaultFunc      (void *ctx ATTRIBUTE_UNUSED,
 }
 
 /************************************************************************
- *                                                                     *
- *                     Handling of out of context errors               *
- *                                                                     *
+ *                                                                     *
+ *                     Handling of out of context errors               *
+ *                                                                     *
  ************************************************************************/
 
 /**
@@ -64,7 +64,7 @@ void XMLCDECL xmlGenericErrorDefaultFunc      (void *ctx ATTRIBUTE_UNUSED,
  * @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 XMLCDECL
@@ -82,7 +82,7 @@ xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
 /**
  * initGenericErrorDefaultFunc:
  * @handler:  the handler
- * 
+ *
  * Set or reset (if NULL) the default handler for generic errors
  * to the builtin error function.
  */
@@ -137,15 +137,15 @@ xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
 }
 
 /************************************************************************
- *                                                                     *
- *                     Handling of parsing errors                      *
- *                                                                     *
+ *                                                                     *
+ *                     Handling of parsing errors                      *
+ *                                                                     *
  ************************************************************************/
 
 /**
  * xmlParserPrintFileInfo:
  * @input:  an xmlParserInputPtr input
- * 
+ *
  * Displays the associated file and line informations for the current input
  */
 
@@ -165,19 +165,21 @@ xmlParserPrintFileInfo(xmlParserInputPtr input) {
 /**
  * xmlParserPrintFileContext:
  * @input:  an xmlParserInputPtr input
- * 
+ *
  * Displays current context within the input content for error tracking
  */
 
 static void
-xmlParserPrintFileContextInternal(xmlParserInputPtr input , 
+xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
                xmlGenericErrorFunc channel, void *data ) {
     const xmlChar *cur, *base;
     unsigned int n, col;       /* GCC warns if signed, because compared with sizeof() */
     xmlChar  content[81]; /* space for 80 chars + line terminator */
     xmlChar *ctnt;
 
-    if (input == NULL) return;
+    if ((input == NULL) || (input->cur == NULL))
+        return;
+
     cur = input->cur;
     base = input->base;
     /* skip backwards over any end-of-lines */
@@ -186,8 +188,8 @@ xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
     }
     n = 0;
     /* search backwards for beginning-of-line (to max buff size) */
-    while ((n++ < (sizeof(content)-1)) && (cur > base) && 
-          (*(cur) != '\n') && (*(cur) != '\r'))
+    while ((n++ < (sizeof(content)-1)) && (cur > base) &&
+          (*(cur) != '\n') && (*(cur) != '\r'))
         cur--;
     if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
     /* calculate the error position in terms of the current position */
@@ -196,8 +198,8 @@ xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
     n = 0;
     ctnt = content;
     /* copy selected text to our buffer */
-    while ((*cur != 0) && (*(cur) != '\n') && 
-          (*(cur) != '\r') && (n < sizeof(content)-1)) {
+    while ((*cur != 0) && (*(cur) != '\n') &&
+          (*(cur) != '\r') && (n < sizeof(content)-1)) {
                *ctnt++ = *cur++;
        n++;
     }
@@ -221,7 +223,7 @@ xmlParserPrintFileContextInternal(xmlParserInputPtr input ,
 /**
  * xmlParserPrintFileContext:
  * @input:  an xmlParserInputPtr input
- * 
+ *
  * Displays current context within the input content for error tracking
  */
 void
@@ -292,7 +294,10 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
     } else {
         if (file != NULL)
             channel(data, "%s:%d: ", file, line);
-        else if ((line != 0) && (domain == XML_FROM_PARSER))
+        else if ((line != 0) &&
+                ((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)||
+                 (domain == XML_FROM_SCHEMASP)||(domain == XML_FROM_DTD) ||
+                 (domain == XML_FROM_RELAXNGP)||(domain == XML_FROM_RELAXNGV)))
             channel(data, "Entity: line %d: ", line);
     }
     if (name != NULL) {
@@ -360,6 +365,15 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
         case XML_FROM_I18N:
             channel(data, "encoding ");
             break;
+        case XML_FROM_SCHEMATRONV:
+            channel(data, "schematron ");
+            break;
+        case XML_FROM_BUFFER:
+            channel(data, "internal buffer ");
+            break;
+        case XML_FROM_URI:
+            channel(data, "URI ");
+            break;
         default:
             break;
     }
@@ -429,7 +443,7 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str,
  * @str2: extra string info
  * @str3: extra string info
  * @int1: extra int info
- * @col: column number of the error or 0 if N/A 
+ * @col: column number of the error or 0 if N/A
  * @msg:  the message to display/transmit
  * @...:  extra parameters for the message display
  *
@@ -521,6 +535,8 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
 
        if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
            line = node->line;
+       if ((line == 0) || (line == 65535))
+           line = xmlGetLineNo(node);
     }
 
     /*
@@ -601,8 +617,11 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
        data = ctxt->userData;
     } else if (channel == NULL) {
        channel = xmlGenericError;
-       if (!data)
+       if (ctxt != NULL) {
+           data = ctxt;
+       } else {
            data = xmlGenericErrorContext;
+       }
     }
     if (channel == NULL)
         return;
@@ -654,7 +673,7 @@ __xmlSimpleError(int domain, int code, xmlNodePtr node,
  * @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.
  */
@@ -697,7 +716,7 @@ xmlParserError(void *ctx, const char *msg, ...)
  * @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.
  */
@@ -718,7 +737,7 @@ xmlParserWarning(void *ctx, const char *msg, ...)
        }
        xmlParserPrintFileInfo(input);
     }
-        
+
     xmlGenericError(xmlGenericErrorContext, "warning: ");
     XML_GET_VAR_STR(msg, str);
     xmlGenericError(xmlGenericErrorContext, "%s", str);
@@ -736,9 +755,9 @@ xmlParserWarning(void *ctx, const char *msg, ...)
 }
 
 /************************************************************************
- *                                                                     *
- *                     Handling of validation errors                   *
- *                                                                     *
+ *                                                                     *
+ *                     Handling of validation errors                   *
+ *                                                                     *
  ************************************************************************/
 
 /**
@@ -746,7 +765,7 @@ xmlParserWarning(void *ctx, const char *msg, ...)
  * @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.
  */
@@ -764,7 +783,7 @@ xmlParserValidityError(void *ctx, const char *msg, ...)
            input = ctxt->input;
            if ((input->filename == NULL) && (ctxt->inputNr > 1))
                input = ctxt->inputTab[ctxt->inputNr - 2];
-               
+
            if (had_info == 0) {
                xmlParserPrintFileInfo(input);
            }
@@ -790,7 +809,7 @@ xmlParserValidityError(void *ctx, const char *msg, ...)
  * @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.
  */
@@ -809,7 +828,7 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...)
 
        xmlParserPrintFileInfo(input);
     }
-        
+
     xmlGenericError(xmlGenericErrorContext, "validity warning: ");
     XML_GET_VAR_STR(msg, str);
     xmlGenericError(xmlGenericErrorContext, "%s", str);
@@ -834,7 +853,7 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...)
  * 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
+ * Returns NULL if no error occurred or a pointer to the error
  */
 xmlErrorPtr
 xmlGetLastError(void)
@@ -891,7 +910,7 @@ xmlResetLastError(void)
  *
  * Get the last parsing error registered.
  *
- * Returns NULL if no error occured or a pointer to the error
+ * Returns NULL if no error occurred or a pointer to the error
  */
 xmlErrorPtr
 xmlCtxtGetLastError(void *ctx)