1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

more bug-hunting added --tree to dump the intermediate rng tree patch from

* relaxng.c: more bug-hunting
* testRelax.c include/libxml/relaxng.h: added --tree to dump the
  intermediate rng tree
* python/generator.py: patch from Stephane Bidoul to fix the generator
  on python < 2.2
Daniel
This commit is contained in:
Daniel Veillard
2003-02-16 15:44:18 +00:00
parent d2298791af
commit febcca40d4
5 changed files with 148 additions and 50 deletions

View File

@ -1,3 +1,11 @@
Sun Feb 16 16:40:52 CET 2003 Daniel Veillard <daniel@veillard.com>
* relaxng.c: more bug-hunting
* testRelax.c include/libxml/relaxng.h: added --tree to dump the
intermediate rng tree
* python/generator.py: patch from Stephane Bidoul to fix the generator
on python < 2.2
Fri Feb 14 17:49:26 CET 2003 Daniel Veillard <daniel@veillard.com> Fri Feb 14 17:49:26 CET 2003 Daniel Veillard <daniel@veillard.com>
* check-relaxng-test-suite.py relaxng.c: more testing on the * check-relaxng-test-suite.py relaxng.c: more testing on the

View File

@ -42,6 +42,8 @@ xmlRelaxNGPtr xmlRelaxNGParse (xmlRelaxNGParserCtxtPtr ctxt);
void xmlRelaxNGFree (xmlRelaxNGPtr schema); void xmlRelaxNGFree (xmlRelaxNGPtr schema);
void xmlRelaxNGDump (FILE *output, void xmlRelaxNGDump (FILE *output,
xmlRelaxNGPtr schema); xmlRelaxNGPtr schema);
void xmlRelaxNGDumpTree (FILE * output,
xmlRelaxNGPtr schema);
/* /*
* Interfaces for validating * Interfaces for validating
*/ */

View File

@ -1089,7 +1089,7 @@ def buildWrappers():
if reference_keepers.has_key(tclass): if reference_keepers.has_key(tclass):
list = reference_keepers[tclass] list = reference_keepers[tclass]
for pref in list: for pref in list:
if pref[0] == ref[0]: if pref[0] == classname:
classes.write(" __tmp.%s = self\n" % classes.write(" __tmp.%s = self\n" %
pref[1]) pref[1])
# #

179
relaxng.c
View File

@ -2311,6 +2311,89 @@ xmlRelaxNGParseDefine(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) {
return(ret); return(ret);
} }
/**
* xmlRelaxNGProcessExternalRef:
* @ctxt: the parser context
* @node: the externlRef node
*
* Process and compile an externlRef node
*
* Returns the xmlRelaxNGDefinePtr or NULL in case of error
*/
static xmlRelaxNGDefinePtr
xmlRelaxNGProcessExternalRef(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) {
xmlRelaxNGDocumentPtr docu;
xmlNodePtr root, tmp;
xmlChar *ns;
int newNs = 0;
xmlRelaxNGDefinePtr def;
docu = node->_private;
if (docu != NULL) {
def = xmlRelaxNGNewDefine(ctxt, node);
if (def == NULL)
return(NULL);
def->type = XML_RELAXNG_EXTERNALREF;
if (docu->content == NULL) {
/*
* Then do the parsing for good
*/
root = xmlDocGetRootElement(docu->doc);
if (root == NULL) {
if (ctxt->error != NULL)
ctxt->error(ctxt->userData,
"xmlRelaxNGParse: %s is empty\n",
ctxt->URL);
ctxt->nbErrors++;
return (NULL);
}
/*
* ns transmission rules
*/
ns = xmlGetProp(root, BAD_CAST "ns");
if (ns == NULL) {
tmp = node;
while ((tmp != NULL) &&
(tmp->type == XML_ELEMENT_NODE)) {
ns = xmlGetProp(tmp, BAD_CAST "ns");
if (ns != NULL) {
break;
}
tmp = tmp->parent;
}
if (ns != NULL) {
xmlSetProp(root, BAD_CAST "ns", ns);
newNs = 1;
xmlFree(ns);
}
} else {
xmlFree(ns);
}
/*
* Parsing to get a precompiled schemas.
*/
docu->schema = xmlRelaxNGParseDocument(ctxt, root);
if ((docu->schema != NULL) &&
(docu->schema->topgrammar != NULL)) {
docu->content = docu->schema->topgrammar->start;
}
/*
* the externalRef may be reused in a different ns context
*/
if (newNs == 1) {
xmlUnsetProp(root, BAD_CAST "ns");
}
}
def->content = docu->content;
} else {
def = NULL;
}
return(def);
}
/** /**
* xmlRelaxNGParsePattern: * xmlRelaxNGParsePattern:
* @ctxt: a Relax-NG parser context * @ctxt: a Relax-NG parser context
@ -2470,10 +2553,16 @@ xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) {
prev = (xmlRelaxNGDefinePtr) prev = (xmlRelaxNGDefinePtr)
xmlHashLookup(ctxt->grammar->refs, def->name); xmlHashLookup(ctxt->grammar->refs, def->name);
if (prev == NULL) { if (prev == NULL) {
if (ctxt->error != NULL) if (def->name != NULL) {
ctxt->error(ctxt->userData, if (ctxt->error != NULL)
"Internal error refs definitions '%s'\n", ctxt->error(ctxt->userData,
def->name); "Error refs definitions '%s'\n",
def->name);
} else {
if (ctxt->error != NULL)
ctxt->error(ctxt->userData,
"Error refs definitions\n");
}
ctxt->nbErrors++; ctxt->nbErrors++;
def = NULL; def = NULL;
} else { } else {
@ -2507,39 +2596,7 @@ xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node) {
} else if (IS_RELAXNG(node, "interleave")) { } else if (IS_RELAXNG(node, "interleave")) {
def = xmlRelaxNGParseInterleave(ctxt, node); def = xmlRelaxNGParseInterleave(ctxt, node);
} else if (IS_RELAXNG(node, "externalRef")) { } else if (IS_RELAXNG(node, "externalRef")) {
xmlRelaxNGDocumentPtr docu; def = xmlRelaxNGProcessExternalRef(ctxt, node);
xmlNodePtr root;
docu = node->_private;
if (docu != NULL) {
def = xmlRelaxNGNewDefine(ctxt, node);
if (def == NULL)
return(NULL);
def->type = XML_RELAXNG_EXTERNALREF;
if (docu->content == NULL) {
/*
* Then do the parsing for good
*/
root = xmlDocGetRootElement(docu->doc);
if (root == NULL) {
if (ctxt->error != NULL)
ctxt->error(ctxt->userData,
"xmlRelaxNGParse: %s is empty\n",
ctxt->URL);
ctxt->nbErrors++;
return (NULL);
}
docu->schema = xmlRelaxNGParseDocument(ctxt, root);
if ((docu->schema != NULL) &&
(docu->schema->topgrammar != NULL)) {
docu->content = docu->schema->topgrammar->start;
}
}
def->content = docu->content;
} else {
def = NULL;
}
} else if (IS_RELAXNG(node, "notAllowed")) { } else if (IS_RELAXNG(node, "notAllowed")) {
def = xmlRelaxNGNewDefine(ctxt, node); def = xmlRelaxNGNewDefine(ctxt, node);
if (def == NULL) if (def == NULL)
@ -3934,7 +3991,7 @@ xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, xmlDocPtr doc) {
cur->_private = incl; cur->_private = incl;
} else if ((xmlStrEqual(cur->name, BAD_CAST "element")) || } else if ((xmlStrEqual(cur->name, BAD_CAST "element")) ||
(xmlStrEqual(cur->name, BAD_CAST "attribute"))) { (xmlStrEqual(cur->name, BAD_CAST "attribute"))) {
xmlChar *name; xmlChar *name, *ns;
xmlNodePtr text = NULL; xmlNodePtr text = NULL;
/* /*
@ -3956,20 +4013,23 @@ xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, xmlDocPtr doc) {
text = node; text = node;
} }
} }
if (text == NULL) {
if (ctxt->error != NULL)
ctxt->error(ctxt->userData,
"Failed to create a name %s element\n", name);
ctxt->nbErrors++;
}
xmlUnsetProp(cur, BAD_CAST "name"); xmlUnsetProp(cur, BAD_CAST "name");
xmlFree(name); xmlFree(name);
} ns = xmlGetProp(cur, BAD_CAST "ns");
if (xmlStrEqual(cur->name, BAD_CAST "attribute")) { if (ns != NULL) {
if (text == NULL) { if (text != NULL) {
text = cur->children; xmlSetProp(text, BAD_CAST "ns", ns);
while (text != NULL) { /* xmlUnsetProp(cur, BAD_CAST "ns"); */
if ((text->type == XML_ELEMENT_NODE) &&
(xmlStrEqual(text->name, BAD_CAST "name")))
break;
text = text->next;
} }
} xmlFree(ns);
if (text != NULL) { } else if (xmlStrEqual(cur->name,
BAD_CAST "attribute")) {
xmlSetProp(text, BAD_CAST "ns", BAD_CAST ""); xmlSetProp(text, BAD_CAST "ns", BAD_CAST "");
} }
} }
@ -4453,6 +4513,27 @@ xmlRelaxNGDump(FILE * output, xmlRelaxNGPtr schema)
xmlRelaxNGDumpGrammar(output, schema->topgrammar, 1); xmlRelaxNGDumpGrammar(output, schema->topgrammar, 1);
} }
/**
* xmlRelaxNGDumpTree:
* @output: the file output
* @schema: a schema structure
*
* Dump the transformed RelaxNG tree.
*/
void
xmlRelaxNGDumpTree(FILE * output, xmlRelaxNGPtr schema)
{
if (schema == NULL) {
fprintf(output, "RelaxNG empty or failed to compile\n");
return;
}
if (schema->doc == NULL) {
fprintf(output, "no document\n");
} else {
xmlDocDump(output, schema->doc);
}
}
/************************************************************************ /************************************************************************
* * * *
* Validation implementation * * Validation implementation *

View File

@ -48,6 +48,7 @@
static int debug = 0; static int debug = 0;
#endif #endif
static int noout = 0; static int noout = 0;
static int tree = 0;
#ifdef HAVE_SYS_MMAN_H #ifdef HAVE_SYS_MMAN_H
static int memory = 0; static int memory = 0;
#endif #endif
@ -71,6 +72,9 @@ int main(int argc, char **argv) {
#endif #endif
if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) { if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) {
noout++; noout++;
} else
if ((!strcmp(argv[i], "-tree")) || (!strcmp(argv[i], "--tree"))) {
tree++;
} }
} }
xmlLineNumbersDefault(1); xmlLineNumbersDefault(1);
@ -123,6 +127,8 @@ int main(int argc, char **argv) {
if (debug) if (debug)
xmlRelaxNGDump(stdout, schema); xmlRelaxNGDump(stdout, schema);
#endif #endif
if (tree)
xmlRelaxNGDumpTree(stdout, schema);
} else { } else {
xmlDocPtr doc; xmlDocPtr doc;
@ -165,6 +171,7 @@ int main(int argc, char **argv) {
printf("\t--debug : dump a debug tree of the in-memory document\n"); printf("\t--debug : dump a debug tree of the in-memory document\n");
#endif #endif
printf("\t--noout : do not print the result\n"); printf("\t--noout : do not print the result\n");
printf("\t--tree : print the intermediate Relax-NG document tree\n");
#ifdef HAVE_SYS_MMAN_H #ifdef HAVE_SYS_MMAN_H
printf("\t--memory : test the schemas in memory parsing\n"); printf("\t--memory : test the schemas in memory parsing\n");
#endif #endif