summaryrefslogtreecommitdiff
path: root/relaxng.c
diff options
context:
space:
mode:
authorMike Hommey <glandium@debian.org>2006-04-29 21:57:40 +0200
committerMike Hommey <glandium@debian.org>2006-04-29 21:57:40 +0200
commit07a67fa4bcc1b8bf2651ab41e5fc54a05059cf7e (patch)
tree7b377fd8e804a983cb2c57a43be1093ef179c5fd /relaxng.c
parentc5d565931c4823dc8f62fffcb65aecfec516f7b9 (diff)
downloadlibxml2-07a67fa4bcc1b8bf2651ab41e5fc54a05059cf7e.tar.gz
Load /tmp/libxml2-2.6.24 intoupstream/2.6.24.dfsg
libxml2/branches/upstream/current.
Diffstat (limited to 'relaxng.c')
-rw-r--r--relaxng.c143
1 files changed, 101 insertions, 42 deletions
diff --git a/relaxng.c b/relaxng.c
index 7e92057..478f31a 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -45,27 +45,29 @@ static const xmlChar *xmlRelaxNGNs = (const xmlChar *)
(xmlStrEqual(node->ns->href, xmlRelaxNGNs)))
-/* #define DEBUG 1 */
+#if 0
+#define DEBUG 1
-/* #define DEBUG_GRAMMAR 1 */
+#define DEBUG_GRAMMAR 1
-/* #define DEBUG_CONTENT 1 */
+#define DEBUG_CONTENT 1
-/* #define DEBUG_TYPE 1 */
+#define DEBUG_TYPE 1
-/* #define DEBUG_VALID 1 */
+#define DEBUG_VALID 1
-/* #define DEBUG_INTERLEAVE 1 */
+#define DEBUG_INTERLEAVE 1
-/* #define DEBUG_LIST 1 */
+#define DEBUG_LIST 1
-/* #define DEBUG_INCLUDE */
+#define DEBUG_INCLUDE 1
-/* #define DEBUG_ERROR 1 */
+#define DEBUG_ERROR 1
-/* #define DEBUG_COMPILE 1 */
+#define DEBUG_COMPILE 1
-/* #define DEBUG_PROGRESSIVE 1 */
+#define DEBUG_PROGRESSIVE 1
+#endif
#define MAX_ERROR 5
@@ -1157,7 +1159,7 @@ xmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt,
ctxt->freeStates = tmp;
ctxt->freeStatesMax *= 2;
}
- if ((ctxt == NULL) || (ctxt->freeState == NULL)) {
+ if ((ctxt == NULL) || (ctxt->freeStates == NULL)) {
xmlFree(states->tabState);
xmlFree(states);
} else {
@@ -1561,8 +1563,10 @@ xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt,
children, name) == 1) {
found = 1;
}
+#ifdef DEBUG_INCLUDE
if (href != NULL)
xmlFree(href);
+#endif
}
}
}
@@ -3575,7 +3579,7 @@ xmlRelaxNGParseValue(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
static xmlRelaxNGDefinePtr
xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
{
- xmlRelaxNGDefinePtr def = NULL, except, last = NULL;
+ xmlRelaxNGDefinePtr def = NULL, except;
xmlRelaxNGDefinePtr param, lastparam = NULL;
xmlRelaxNGTypeLibraryPtr lib;
xmlChar *type;
@@ -3683,7 +3687,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
if ((content != NULL)
&& (xmlStrEqual(content->name, BAD_CAST "except"))) {
xmlNodePtr child;
- xmlRelaxNGDefinePtr tmp2, last2 = NULL;
+ xmlRelaxNGDefinePtr tmp2, last = NULL;
except = xmlRelaxNGNewDefine(ctxt, node);
if (except == NULL) {
@@ -3691,11 +3695,7 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
}
except->type = XML_RELAXNG_EXCEPT;
child = content->children;
- if (last == NULL) {
- def->content = except;
- } else {
- last->next = except;
- }
+ def->content = except;
if (child == NULL) {
xmlRngPErr(ctxt, content, XML_RNGP_EXCEPT_NO_CONTENT,
"except has no content\n", NULL, NULL);
@@ -3703,11 +3703,11 @@ xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
while (child != NULL) {
tmp2 = xmlRelaxNGParsePattern(ctxt, child);
if (tmp2 != NULL) {
- if (last2 == NULL) {
- except->content = last2 = tmp2;
+ if (last == NULL) {
+ except->content = last = tmp2;
} else {
- last2->next = tmp2;
- last2 = tmp2;
+ last->next = tmp2;
+ last = tmp2;
}
}
child = child->next;
@@ -7394,13 +7394,16 @@ xmlRelaxNGParse(xmlRelaxNGParserCtxtPtr ctxt)
if (root == NULL) {
xmlRngPErr(ctxt, (xmlNodePtr) doc,
XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n",
- ctxt->URL, NULL);
- xmlFreeDoc(doc);
+ (ctxt->URL ? ctxt->URL : "schemas"), NULL);
+
+ xmlFreeDoc(ctxt->document);
+ ctxt->document = NULL;
return (NULL);
}
ret = xmlRelaxNGParseDocument(ctxt, root);
if (ret == NULL) {
- xmlFreeDoc(doc);
+ xmlFreeDoc(ctxt->document);
+ ctxt->document = NULL;
return (NULL);
}
@@ -7510,6 +7513,27 @@ xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
return (0);
}
+/**
+ * xmlRelaxNGSetParserStructuredErrors:
+ * @ctxt: a Relax-NG parser context
+ * @serror: the error callback
+ * @ctx: contextual data for the callbacks
+ *
+ * Set the callback functions used to handle errors for a parsing context
+ */
+void
+xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCtxtPtr ctxt,
+ xmlStructuredErrorFunc serror,
+ void *ctx)
+{
+ if (ctxt == NULL)
+ return;
+ ctxt->serror = serror;
+ ctxt->error = NULL;
+ ctxt->warning = NULL;
+ ctxt->userData = ctx;
+}
+
#ifdef LIBXML_OUTPUT_ENABLED
/************************************************************************
@@ -7780,8 +7804,6 @@ xmlRelaxNGValidateCompiledCallback(xmlRegExecCtxtPtr exec ATTRIBUTE_UNUSED,
#endif
if (ctxt == NULL) {
fprintf(stderr, "callback on %s missing context\n", token);
- if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
- ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
return;
}
if (define == NULL) {
@@ -7825,10 +7847,11 @@ xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt,
xmlRegExecCtxtPtr exec;
xmlNodePtr cur;
int ret = 0;
- int oldperr = ctxt->perr;
+ int oldperr;
if ((ctxt == NULL) || (regexp == NULL))
return (-1);
+ oldperr = ctxt->perr;
exec = xmlRegNewExecCtxt(regexp,
xmlRelaxNGValidateCompiledCallback, ctxt);
ctxt->perr = 0;
@@ -7987,7 +8010,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec
xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata;
xmlRelaxNGDefinePtr define = (xmlRelaxNGDefinePtr) transdata;
xmlRelaxNGValidStatePtr state, oldstate;
- xmlNodePtr node = ctxt->pnode;
+ xmlNodePtr node;
int ret = 0, oldflags;
#ifdef DEBUG_PROGRESSIVE
@@ -7998,6 +8021,7 @@ xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec
fprintf(stderr, "callback on %s missing context\n", token);
return;
}
+ node = ctxt->pnode;
ctxt->pstate = 1;
if (define == NULL) {
if (token[0] == '#')
@@ -8751,13 +8775,8 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
cur = ctxt->state->value;
}
ctxt->flags = oldflags;
- if (ret != 0) {
- if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
- xmlRelaxNGDumpValidError(ctxt);
- } else {
- if (ctxt->errNr > 0)
- xmlRelaxNGPopErrors(ctxt, 0);
- }
+ if (ctxt->errNr > 0)
+ xmlRelaxNGPopErrors(ctxt, 0);
break;
}
case XML_RELAXNG_EXCEPT:{
@@ -9253,21 +9272,56 @@ xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt,
} else if (ctxt->states != NULL) {
int j;
int found = 0;
+ int best = -1;
+ int lowattr = -1;
+
+ /*
+ * PBM: what happen if there is attributes checks in the interleaves
+ */
for (j = 0; j < ctxt->states->nbState; j++) {
cur = ctxt->states->tabState[j]->seq;
cur = xmlRelaxNGSkipIgnored(ctxt, cur);
if (cur == NULL) {
+ if (found == 0) {
+ lowattr = ctxt->states->tabState[j]->nbAttrLeft;
+ best = j;
+ }
found = 1;
- break;
- }
+ if (ctxt->states->tabState[j]->nbAttrLeft <= lowattr) {
+ /* try to keep the latest one to mach old heuristic */
+ lowattr = ctxt->states->tabState[j]->nbAttrLeft;
+ best = j;
+ }
+ if (lowattr == 0)
+ break;
+ } else if (found == 0) {
+ if (lowattr == -1) {
+ lowattr = ctxt->states->tabState[j]->nbAttrLeft;
+ best = j;
+ } else
+ if (ctxt->states->tabState[j]->nbAttrLeft <= lowattr) {
+ /* try to keep the latest one to mach old heuristic */
+ lowattr = ctxt->states->tabState[j]->nbAttrLeft;
+ best = j;
+ }
+ }
}
+ /*
+ * BIG PBM: here we pick only one restarting point :-(
+ */
if (ctxt->states->nbState > 0) {
xmlRelaxNGFreeValidState(ctxt, oldstate);
- oldstate =
- ctxt->states->tabState[ctxt->states->nbState - 1];
+ if (best != -1) {
+ oldstate = ctxt->states->tabState[best];
+ ctxt->states->tabState[best] = NULL;
+ } else {
+ oldstate =
+ ctxt->states->tabState[ctxt->states->nbState - 1];
+ ctxt->states->tabState[ctxt->states->nbState - 1] = NULL;
+ }
}
- for (j = 0; j < ctxt->states->nbState - 1; j++) {
+ for (j = 0; j < ctxt->states->nbState ; j++) {
xmlRelaxNGFreeValidState(ctxt, ctxt->states->tabState[j]);
}
xmlRelaxNGFreeStates(ctxt, ctxt->states);
@@ -10040,6 +10094,11 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
if (states == NULL) {
xmlRelaxNGNewStates(ctxt,
res->nbState - base);
+ states = ctxt->states;
+ if (states == NULL) {
+ progress = 0;
+ break;
+ }
}
states->nbState = 0;
for (i = base; i < res->nbState; i++)