try to work on bug #109225 and provide better error reports. this change

* relaxng.c: try to work on bug #109225 and provide better
  error reports.
* result/relaxng/* : this change the output of a number of tests
* xinclude.c: fixing the parsed entity redefinition problem
  raised on the list.
* test/schemas/date_0.xsd: updated the date test c.f. E2-12
Daniel
diff --git a/ChangeLog b/ChangeLog
index 78d0771..a6afc7d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Mon Mar 31 18:05:22 CEST 2003 Daniel Veillard <daniel@veillard.com>
+
+	* relaxng.c: try to work on bug #109225 and provide better
+	  error reports.
+	* result/relaxng/* : this change the output of a number of tests
+	* xinclude.c: fixing the parsed entity redefinition problem
+	  raised on the list.
+	* test/schemas/date_0.xsd: updated the date test c.f. E2-12
+
 Mon Mar 31 13:19:04 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
 	* xmlschemastypes.c: fixed date comparison to handle the tzo
diff --git a/relaxng.c b/relaxng.c
index 568e6a7..723e5fd 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -55,6 +55,7 @@
 /* #define DEBUG_INTERLEAVE 1 */
 /* #define DEBUG_LIST 1 */
 /* #define DEBUG_INCLUDE */
+/* #define DEBUG_ERROR 1 */
 
 #define UNBOUNDED (1 << 30)
 #define TODO 								\
@@ -327,6 +328,7 @@
     int                     flags;	/* validation flags */
     int                     depth;	/* validation depth */
     int                     idref;	/* requires idref checking */
+    int                     errNo;	/* the first error found */
 
     /*
      * Errors accumulated in branches may have to be stacked to be
@@ -1547,6 +1549,10 @@
 	const xmlChar *arg1, const xmlChar *arg2, int dup)
 {
     xmlRelaxNGValidErrorPtr cur;
+#ifdef DEBUG_ERROR
+    xmlGenericError(xmlGenericErrorContext,
+	    "Pushing error %d at %d on stack\n", err, ctxt->errNr);
+#endif
     if (ctxt->errTab == NULL) {
 	ctxt->errMax = 8;
 	ctxt->errNr = 0;
@@ -2051,10 +2057,16 @@
     if (ctxt->error == NULL)
         return;
 
+#ifdef DEBUG_ERROR
+    xmlGenericError(xmlGenericErrorContext,
+	    "Show error %d\n", err);
+#endif
     msg = xmlRelaxNGGetErrorString(err, arg1, arg2);
     if (msg == NULL)
 	return;
 
+    if (ctxt->errNo == XML_RELAXNG_OK)
+	ctxt->errNo = err;
     xmlRelaxNGValidErrorContext(ctxt, node, child);
     ctxt->error(ctxt->userData, "%s\n", msg);
     xmlFree(msg);
@@ -2072,6 +2084,10 @@
     int i;
     xmlRelaxNGValidErrorPtr err;
 
+#ifdef DEBUG_ERROR
+    xmlGenericError(xmlGenericErrorContext,
+	    "Pop errors till level %d\n", level);
+#endif
     for (i = level;i < ctxt->errNr;i++) {
 	err = &ctxt->errTab[i];
 	if (err->flags & ERROR_IS_DUP) {
@@ -2099,6 +2115,10 @@
     int i, j;
     xmlRelaxNGValidErrorPtr err, dup;
 
+#ifdef DEBUG_ERROR
+    xmlGenericError(xmlGenericErrorContext,
+	    "Dumping error stack %d errors\n", ctxt->errNr);
+#endif
     for (i = 0;i < ctxt->errNr;i++) {
 	err = &ctxt->errTab[i];
 	for (j = 0;j < i;j++) {
@@ -2142,6 +2162,10 @@
     if ((ctxt == NULL) || (ctxt->error == NULL))
 	return;
 
+#ifdef DEBUG_ERROR
+    xmlGenericError(xmlGenericErrorContext,
+	    "Adding error %d\n", err);
+#endif
     /*
      * generate the error directly
      */
@@ -7992,7 +8016,7 @@
 	    VALID_ERR(XML_RELAXNG_ERR_NOSTATE);
 	    return(-1);
 	}
-	if (ret < 0)
+	if (res == -1) /* continues on -2 */
 	    break;
 	defines = defines->next;
     }
@@ -8315,16 +8339,20 @@
 		    ret = xmlRelaxNGValidateElementEnd(ctxt);
 		xmlRelaxNGFreeValidState(ctxt,state);
 	    }
+	    if (ret == 0) {
+		node->_private = define;
+	    }
 	    ctxt->flags = oldflags;
 	    ctxt->state = oldstate;
 	    if (oldstate != NULL)
 		oldstate->seq = xmlRelaxNGSkipIgnored(ctxt, node->next);
-	    if (ret == 0) {
-		node->_private = define;
-	    }
 	    if (ret != 0) {
-		if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
+		if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
 		    xmlRelaxNGDumpValidError(ctxt);
+		    ret = 0;
+		} else {
+		    ret = -2;
+		}
 	    } else {
 		if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr);
 	    }
@@ -8346,6 +8374,7 @@
 #endif
 	    break;
         case XML_RELAXNG_OPTIONAL: {
+	    errNr = ctxt->errNr;
 	    oldflags = ctxt->flags;
 	    ctxt->flags |= FLAGS_IGNORABLE;
 	    oldstate = xmlRelaxNGCopyValidState(ctxt, ctxt->state);
@@ -8356,6 +8385,7 @@
 		ctxt->state = oldstate;
 		ctxt->flags = oldflags;
 		ret = 0;
+		if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr);
 		break;
 	    }
 	    if (ctxt->states != NULL) {
@@ -8366,6 +8396,7 @@
 		    xmlRelaxNGFreeValidState(ctxt,oldstate);
 		    ctxt->flags = oldflags;
 		    ret = -1;
+		    if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr);
 		    break;
 		}
 		xmlRelaxNGAddStates(ctxt, ctxt->states, oldstate);
@@ -8374,19 +8405,23 @@
 	    }
 	    ctxt->flags = oldflags;
 	    ret = 0;
+	    if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr);
 	    break;
         }
         case XML_RELAXNG_ONEORMORE:
+	    errNr = ctxt->errNr;
 	    ret = xmlRelaxNGValidateDefinitionList(ctxt, define->content);
 	    if (ret != 0) {
 		break;
 	    }
+	    if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr);
 	    /* no break on purpose */
         case XML_RELAXNG_ZEROORMORE: {
 	    int progress;
 	    xmlRelaxNGStatesPtr states = NULL, res = NULL;
 	    int base, j;
 
+	    errNr = ctxt->errNr;
 	    res = xmlRelaxNGNewStates(ctxt, 1);
 	    if (res == NULL) {
 		ret = -1;
@@ -8498,6 +8533,7 @@
 	    }
 	    ctxt->states = res;
 	    ctxt->flags = oldflags;
+	    if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr);
 	    ret = 0;
 	    break;
 	}
@@ -8507,6 +8543,7 @@
 
 	    node = xmlRelaxNGSkipIgnored(ctxt, node);
 
+	    errNr = ctxt->errNr;
 	    if ((define->dflags & IS_TRIABLE) && (define->data != NULL)) {
 		xmlHashTablePtr triage = (xmlHashTablePtr) define->data;
 
@@ -8538,12 +8575,13 @@
 		    break;
 		}
 		ret = xmlRelaxNGValidateDefinition(ctxt, list);
+		if (ret == 0) {
+		}
 		break;
 	    }
 
             list = define->content;
 	    oldflags = ctxt->flags;
-	    errNr = ctxt->errNr;
 	    ctxt->flags |= FLAGS_IGNORABLE;
 
 	    while (list != NULL) {
@@ -8579,9 +8617,10 @@
 	    }
 	    ctxt->flags = oldflags;
 	    if (ret != 0) {
-		if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
+		if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
 		    xmlRelaxNGDumpValidError(ctxt);
-	    } else if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
+		}
+	    } else {
 		if (ctxt->errNr > errNr) xmlRelaxNGPopErrors(ctxt, errNr);
 	    }
 	    break;
@@ -8919,6 +8958,7 @@
     if ((ctxt == NULL) || (ctxt->schema == NULL) || (doc == NULL))
 	return(-1);
 
+    ctxt->errNo = XML_RELAXNG_OK;
     schema = ctxt->schema;
     grammar = schema->topgrammar;
     if (grammar == NULL) {
@@ -8982,6 +9022,8 @@
 	if (xmlValidateDocumentFinal(&vctxt, doc) != 1)
 	    ret = -1;
     }
+    if ((ret == 0) && (ctxt->errNo != XML_RELAXNG_OK))
+	ret = -1;
 
     return(ret);
 }
@@ -9021,6 +9063,7 @@
     ret->states = NULL;
     ret->freeState = NULL;
     ret->freeStates = NULL;
+    ret->errNo = XML_RELAXNG_OK;
     return (ret);
 }
 
diff --git a/result/relaxng/tutor10_7_3.err b/result/relaxng/tutor10_7_3.err
index 8e2d82b..ebbc9aa 100644
--- a/result/relaxng/tutor10_7_3.err
+++ b/result/relaxng/tutor10_7_3.err
@@ -1,4 +1,2 @@
 RNG validity error: file ./test/relaxng/tutor10_7_3.xml line 2 element card
-Element card failed to validate attributes
-RNG validity error: file ./test/relaxng/tutor10_7_3.xml line 2 element card
 Element addressBook has extra content: card
diff --git a/result/relaxng/tutor10_8_3.err b/result/relaxng/tutor10_8_3.err
index 12cfcb7..34eb5e9 100644
--- a/result/relaxng/tutor10_8_3.err
+++ b/result/relaxng/tutor10_8_3.err
@@ -1,4 +1,2 @@
 RNG validity error: file ./test/relaxng/tutor10_8_3.xml line 2 element card
-Element card failed to validate attributes
-RNG validity error: file ./test/relaxng/tutor10_8_3.xml line 2 element card
 Element addressBook has extra content: card
diff --git a/result/relaxng/tutor3_5_2.err b/result/relaxng/tutor3_5_2.err
index 5cbf203..ed09a33 100644
--- a/result/relaxng/tutor3_5_2.err
+++ b/result/relaxng/tutor3_5_2.err
@@ -1,6 +1,2 @@
-RNG validity error: file ./test/relaxng/tutor3_5_2.xml line 2 element email
-Expecting element name, got email
-RNG validity error: file ./test/relaxng/tutor3_5_2.xml line 2 element email
-Element card failed to validate content
 RNG validity error: file ./test/relaxng/tutor3_5_2.xml line 2 element card
 Element addressBook has extra content: card
diff --git a/result/relaxng/tutor3_7_err b/result/relaxng/tutor3_7_err
index b30a3c4..24088bb 100644
--- a/result/relaxng/tutor3_7_err
+++ b/result/relaxng/tutor3_7_err
@@ -1,6 +1,4 @@
 RNG validity error: file ./test/relaxng/tutor3_7.rng line 1 element element
-Expecting an element , got nothing
-RNG validity error: file ./test/relaxng/tutor3_7.rng line 1 element element
 Invalid sequence in interleave
 RNG validity error: file ./test/relaxng/tutor3_7.rng line 1 element element
 Element element failed to validate content
diff --git a/result/relaxng/tutor6_2_4.err b/result/relaxng/tutor6_2_4.err
index dcba864..69e34dc 100644
--- a/result/relaxng/tutor6_2_4.err
+++ b/result/relaxng/tutor6_2_4.err
@@ -2,5 +2,3 @@
 Error validating value 
 RNG validity error: file ./test/relaxng/tutor6_2_4.xml line 4 element text
 Element preferredFormat failed to validate content
-RNG validity error: file ./test/relaxng/tutor6_2_4.xml line 1 element card
-Element card failed to validate content
diff --git a/result/relaxng/tutor9_5_2.err b/result/relaxng/tutor9_5_2.err
index 75a04d5..650ca98 100644
--- a/result/relaxng/tutor9_5_2.err
+++ b/result/relaxng/tutor9_5_2.err
@@ -1,6 +1,2 @@
 RNG validity error: file ./test/relaxng/tutor9_5_2.xml line 2 element card
-Invalid sequence in interleave
-RNG validity error: file ./test/relaxng/tutor9_5_2.xml line 2 element card
-Element card failed to validate content
-RNG validity error: file ./test/relaxng/tutor9_5_2.xml line 2 element card
 Element addressBook has extra content: card
diff --git a/result/relaxng/tutor9_5_3.err b/result/relaxng/tutor9_5_3.err
index 6a028af..eee06c7 100644
--- a/result/relaxng/tutor9_5_3.err
+++ b/result/relaxng/tutor9_5_3.err
@@ -1,4 +1,2 @@
 RNG validity error: file ./test/relaxng/tutor9_5_3.xml line 2 element card
-Invalid attribute error for element card
-RNG validity error: file ./test/relaxng/tutor9_5_3.xml line 2 element card
 Element addressBook has extra content: card
diff --git a/result/relaxng/tutor9_6_2.err b/result/relaxng/tutor9_6_2.err
index 939fa38..259cb07 100644
--- a/result/relaxng/tutor9_6_2.err
+++ b/result/relaxng/tutor9_6_2.err
@@ -1,4 +1,2 @@
 RNG validity error: file ./test/relaxng/tutor9_6_2.xml line 2 element card
-Element card failed to validate content
-RNG validity error: file ./test/relaxng/tutor9_6_2.xml line 2 element card
 Element addressBook has extra content: card
diff --git a/result/relaxng/tutor9_6_3.err b/result/relaxng/tutor9_6_3.err
index f9f3483..2157e52 100644
--- a/result/relaxng/tutor9_6_3.err
+++ b/result/relaxng/tutor9_6_3.err
@@ -1,4 +1,2 @@
 RNG validity error: file ./test/relaxng/tutor9_6_3.xml line 2 element card
-Invalid attribute error for element card
-RNG validity error: file ./test/relaxng/tutor9_6_3.xml line 2 element card
 Element addressBook has extra content: card
diff --git a/test/schemas/date_0.xsd b/test/schemas/date_0.xsd
index aa919b0..8784212 100644
--- a/test/schemas/date_0.xsd
+++ b/test/schemas/date_0.xsd
@@ -78,8 +78,8 @@
           <xsd:element name="mon1">
             <xsd:simpleType>
               <xsd:restriction base="xsd:gMonth">
-                <xsd:maxInclusive value="--01--Z"/>
-                <xsd:minInclusive value="--05--Z"/>
+                <xsd:maxInclusive value="--01Z"/>
+                <xsd:minInclusive value="--05Z"/>
               </xsd:restriction>
             </xsd:simpleType>
           </xsd:element>
diff --git a/xinclude.c b/xinclude.c
index 5181214..976d381 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -1079,6 +1079,16 @@
     }
     return;
 error:
+    switch (ent->etype) {
+        case XML_INTERNAL_PARAMETER_ENTITY:
+        case XML_EXTERNAL_PARAMETER_ENTITY:
+        case XML_INTERNAL_PREDEFINED_ENTITY:
+        case XML_INTERNAL_GENERAL_ENTITY:
+        case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
+	    return;
+        case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
+	    break;
+    }
     xmlGenericError(xmlGenericErrorContext,
 		"XInclude: mismatch in redefinition of entity %s\n", ent->name);
     ctxt->nbErrors++;