mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-26 00:37:43 +03:00
applied patch from Aswin to fix tree skipping fixed a comment and added a
* xmlreader.c: applied patch from Aswin to fix tree skipping * include/libxml/entities.h entities.c: fixed a comment and added a new xmlNewEntity() entry point * runtest.c: be less verbose * tree.c: space and tabs cleanups daniel svn path=/trunk/; revision=3774
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
Mon Aug 25 16:52:53 CEST 2008 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* xmlreader.c: applied patch from Aswin to fix tree skipping
|
||||||
|
* include/libxml/entities.h entities.c: fixed a comment and
|
||||||
|
added a new xmlNewEntity() entry point
|
||||||
|
* runtest.c: be less verbose
|
||||||
|
* tree.c: space and tabs cleanups
|
||||||
|
|
||||||
Mon Aug 25 10:56:30 CEST 2008 Daniel Veillard <daniel@veillard.com>
|
Mon Aug 25 10:56:30 CEST 2008 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* include/libxml/entities.h entities.c SAX2.c parser.c: rework
|
* include/libxml/entities.h entities.c SAX2.c parser.c: rework
|
||||||
|
|||||||
118
entities.c
118
entities.c
@@ -139,45 +139,19 @@ xmlFreeEntity(xmlEntityPtr entity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xmlAddEntity : register a new entity for an entities table.
|
* xmlCreateEntity:
|
||||||
|
*
|
||||||
|
* internal routine doing the entity node strutures allocations
|
||||||
*/
|
*/
|
||||||
static xmlEntityPtr
|
static xmlEntityPtr
|
||||||
xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
|
xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type,
|
||||||
const xmlChar *ExternalID, const xmlChar *SystemID,
|
const xmlChar *ExternalID, const xmlChar *SystemID,
|
||||||
const xmlChar *content) {
|
const xmlChar *content) {
|
||||||
xmlDictPtr dict = NULL;
|
|
||||||
xmlEntitiesTablePtr table = NULL;
|
|
||||||
xmlEntityPtr ret;
|
xmlEntityPtr ret;
|
||||||
|
|
||||||
if (name == NULL)
|
|
||||||
return(NULL);
|
|
||||||
if (dtd == NULL)
|
|
||||||
return(NULL);
|
|
||||||
if (dtd->doc != NULL)
|
|
||||||
dict = dtd->doc->dict;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case XML_INTERNAL_GENERAL_ENTITY:
|
|
||||||
case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
|
|
||||||
case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
|
|
||||||
if (dtd->entities == NULL)
|
|
||||||
dtd->entities = xmlHashCreateDict(0, dict);
|
|
||||||
table = dtd->entities;
|
|
||||||
break;
|
|
||||||
case XML_INTERNAL_PARAMETER_ENTITY:
|
|
||||||
case XML_EXTERNAL_PARAMETER_ENTITY:
|
|
||||||
if (dtd->pentities == NULL)
|
|
||||||
dtd->pentities = xmlHashCreateDict(0, dict);
|
|
||||||
table = dtd->pentities;
|
|
||||||
break;
|
|
||||||
case XML_INTERNAL_PREDEFINED_ENTITY:
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
if (table == NULL)
|
|
||||||
return(NULL);
|
|
||||||
ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
|
ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
xmlEntitiesErrMemory("xmlAddEntity:: malloc failed");
|
xmlEntitiesErrMemory("xmlCreateEntity: malloc failed");
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
memset(ret, 0, sizeof(xmlEntity));
|
memset(ret, 0, sizeof(xmlEntity));
|
||||||
@@ -216,6 +190,50 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
|
|||||||
the defining entity */
|
the defining entity */
|
||||||
ret->orig = NULL;
|
ret->orig = NULL;
|
||||||
ret->owner = 0;
|
ret->owner = 0;
|
||||||
|
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* xmlAddEntity : register a new entity for an entities table.
|
||||||
|
*/
|
||||||
|
static xmlEntityPtr
|
||||||
|
xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
|
||||||
|
const xmlChar *ExternalID, const xmlChar *SystemID,
|
||||||
|
const xmlChar *content) {
|
||||||
|
xmlDictPtr dict = NULL;
|
||||||
|
xmlEntitiesTablePtr table = NULL;
|
||||||
|
xmlEntityPtr ret;
|
||||||
|
|
||||||
|
if (name == NULL)
|
||||||
|
return(NULL);
|
||||||
|
if (dtd == NULL)
|
||||||
|
return(NULL);
|
||||||
|
if (dtd->doc != NULL)
|
||||||
|
dict = dtd->doc->dict;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case XML_INTERNAL_GENERAL_ENTITY:
|
||||||
|
case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
|
||||||
|
case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
|
||||||
|
if (dtd->entities == NULL)
|
||||||
|
dtd->entities = xmlHashCreateDict(0, dict);
|
||||||
|
table = dtd->entities;
|
||||||
|
break;
|
||||||
|
case XML_INTERNAL_PARAMETER_ENTITY:
|
||||||
|
case XML_EXTERNAL_PARAMETER_ENTITY:
|
||||||
|
if (dtd->pentities == NULL)
|
||||||
|
dtd->pentities = xmlHashCreateDict(0, dict);
|
||||||
|
table = dtd->pentities;
|
||||||
|
break;
|
||||||
|
case XML_INTERNAL_PREDEFINED_ENTITY:
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
if (table == NULL)
|
||||||
|
return(NULL);
|
||||||
|
ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content);
|
||||||
|
if (ret == NULL)
|
||||||
|
return(NULL);
|
||||||
ret->doc = dtd->doc;
|
ret->doc = dtd->doc;
|
||||||
|
|
||||||
if (xmlHashAddEntry(table, name, ret)) {
|
if (xmlHashAddEntry(table, name, ret)) {
|
||||||
@@ -362,6 +380,44 @@ xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type,
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xmlNewEntity:
|
||||||
|
* @doc: the document
|
||||||
|
* @name: the entity name
|
||||||
|
* @type: the entity type XML_xxx_yyy_ENTITY
|
||||||
|
* @ExternalID: the entity external ID if available
|
||||||
|
* @SystemID: the entity system ID if available
|
||||||
|
* @content: the entity content
|
||||||
|
*
|
||||||
|
* Create a new entity, this differs from xmlAddDocEntity() that if
|
||||||
|
* the document is NULL or has no internal subset defined, then an
|
||||||
|
* unlinked entity structure will be returned, it is then the responsability
|
||||||
|
* of the caller to link it to the document later or free it when not needed
|
||||||
|
* anymore.
|
||||||
|
*
|
||||||
|
* Returns a pointer to the entity or NULL in case of error
|
||||||
|
*/
|
||||||
|
xmlEntityPtr
|
||||||
|
xmlNewEntity(xmlDocPtr doc, const xmlChar *name, int type,
|
||||||
|
const xmlChar *ExternalID, const xmlChar *SystemID,
|
||||||
|
const xmlChar *content) {
|
||||||
|
xmlEntityPtr ret;
|
||||||
|
xmlDictPtr dict;
|
||||||
|
|
||||||
|
if ((doc != NULL) && (doc->intSubset != NULL)) {
|
||||||
|
return(xmlAddDocEntity(doc, name, type, ExternalID, SystemID, content));
|
||||||
|
}
|
||||||
|
if (doc != NULL)
|
||||||
|
dict = doc->dict;
|
||||||
|
else
|
||||||
|
dict = NULL;
|
||||||
|
ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content);
|
||||||
|
if (ret == NULL)
|
||||||
|
return(NULL);
|
||||||
|
ret->doc = doc;
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlGetEntityFromTable:
|
* xmlGetEntityFromTable:
|
||||||
* @table: an entity table
|
* @table: an entity table
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ struct _xmlEntity {
|
|||||||
const xmlChar *URI; /* the full URI as computed */
|
const xmlChar *URI; /* the full URI as computed */
|
||||||
int owner; /* does the entity own the childrens */
|
int owner; /* does the entity own the childrens */
|
||||||
int checked; /* was the entity content checked */
|
int checked; /* was the entity content checked */
|
||||||
|
/* this is also used to count entites
|
||||||
|
* references done from that entity */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -75,6 +77,14 @@ typedef xmlEntitiesTable *xmlEntitiesTablePtr;
|
|||||||
XMLPUBFUN void XMLCALL
|
XMLPUBFUN void XMLCALL
|
||||||
xmlInitializePredefinedEntities (void);
|
xmlInitializePredefinedEntities (void);
|
||||||
#endif /* LIBXML_LEGACY_ENABLED */
|
#endif /* LIBXML_LEGACY_ENABLED */
|
||||||
|
|
||||||
|
XMLPUBFUN xmlEntityPtr XMLCALL
|
||||||
|
xmlNewEntity (xmlDocPtr doc,
|
||||||
|
const xmlChar *name,
|
||||||
|
int type,
|
||||||
|
const xmlChar *ExternalID,
|
||||||
|
const xmlChar *SystemID,
|
||||||
|
const xmlChar *content);
|
||||||
XMLPUBFUN xmlEntityPtr XMLCALL
|
XMLPUBFUN xmlEntityPtr XMLCALL
|
||||||
xmlAddDocEntity (xmlDocPtr doc,
|
xmlAddDocEntity (xmlDocPtr doc,
|
||||||
const xmlChar *name,
|
const xmlChar *name,
|
||||||
|
|||||||
@@ -4392,7 +4392,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
|
|||||||
|
|
||||||
initializeLibxml2();
|
initializeLibxml2();
|
||||||
|
|
||||||
|
|
||||||
for (a = 1; a < argc;a++) {
|
for (a = 1; a < argc;a++) {
|
||||||
if (!strcmp(argv[a], "-v"))
|
if (!strcmp(argv[a], "-v"))
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
|
|||||||
14
runxmlconf.c
14
runxmlconf.c
@@ -446,22 +446,27 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur) {
|
xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur, int level) {
|
||||||
xmlChar *profile;
|
xmlChar *profile;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int tests = 0;
|
int tests = 0;
|
||||||
|
int output = 0;
|
||||||
|
|
||||||
|
if (level == 1) {
|
||||||
profile = xmlGetProp(cur, BAD_CAST "PROFILE");
|
profile = xmlGetProp(cur, BAD_CAST "PROFILE");
|
||||||
if (profile != NULL) {
|
if (profile != NULL) {
|
||||||
|
output = 1;
|
||||||
|
level++;
|
||||||
printf("Test cases: %s\n", (char *) profile);
|
printf("Test cases: %s\n", (char *) profile);
|
||||||
xmlFree(profile);
|
xmlFree(profile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
cur = cur->children;
|
cur = cur->children;
|
||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
/* look only at elements we ignore everything else */
|
/* look only at elements we ignore everything else */
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
if (xmlStrEqual(cur->name, BAD_CAST "TESTCASES")) {
|
if (xmlStrEqual(cur->name, BAD_CAST "TESTCASES")) {
|
||||||
ret += xmlconfTestCases(doc, cur);
|
ret += xmlconfTestCases(doc, cur, level);
|
||||||
} else if (xmlStrEqual(cur->name, BAD_CAST "TEST")) {
|
} else if (xmlStrEqual(cur->name, BAD_CAST "TEST")) {
|
||||||
if (xmlconfTestItem(doc, cur) >= 0)
|
if (xmlconfTestItem(doc, cur) >= 0)
|
||||||
ret++;
|
ret++;
|
||||||
@@ -472,8 +477,10 @@ xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur) {
|
|||||||
}
|
}
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
if (output == 1) {
|
||||||
if (tests > 0)
|
if (tests > 0)
|
||||||
printf("Test cases: %d tests\n", tests);
|
printf("Test cases: %d tests\n", tests);
|
||||||
|
}
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,7 +500,7 @@ xmlconfTestSuite(xmlDocPtr doc, xmlNodePtr cur) {
|
|||||||
/* look only at elements we ignore everything else */
|
/* look only at elements we ignore everything else */
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
if (xmlStrEqual(cur->name, BAD_CAST "TESTCASES")) {
|
if (xmlStrEqual(cur->name, BAD_CAST "TESTCASES")) {
|
||||||
ret += xmlconfTestCases(doc, cur);
|
ret += xmlconfTestCases(doc, cur, 1);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unhandled element %s\n", (char *)cur->name);
|
fprintf(stderr, "Unhandled element %s\n", (char *)cur->name);
|
||||||
}
|
}
|
||||||
@@ -584,6 +591,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
printf("Total %d tests, %d errors, %d leaks\n",
|
printf("Total %d tests, %d errors, %d leaks\n",
|
||||||
nb_tests, nb_errors, nb_leaks);
|
nb_tests, nb_errors, nb_leaks);
|
||||||
|
printf("See %s for detailed output\n", LOGFILE);
|
||||||
}
|
}
|
||||||
xmlXPathFreeContext(ctxtXPath);
|
xmlXPathFreeContext(ctxtXPath);
|
||||||
xmlCleanupParser();
|
xmlCleanupParser();
|
||||||
|
|||||||
16
xmlreader.c
16
xmlreader.c
@@ -1847,17 +1847,22 @@ xmlTextReaderNextTree(xmlTextReaderPtr reader)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reader->state != XML_TEXTREADER_BACKTRACK) {
|
if (reader->state != XML_TEXTREADER_BACKTRACK) {
|
||||||
if (reader->node->children != 0) {
|
/* Here removed traversal to child, because we want to skip the subtree,
|
||||||
reader->node = reader->node->children;
|
replace with traversal to sibling to skip subtree */
|
||||||
reader->depth++;
|
if (reader->node->next != 0) {
|
||||||
|
reader->node = reader->node->next;// Move to sibling if present,skipping sub-tree
|
||||||
|
//reader->depth++;
|
||||||
reader->state = XML_TEXTREADER_START;
|
reader->state = XML_TEXTREADER_START;
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if reader->node->next is NULL mean no subtree for current node,
|
||||||
|
so need to move to sibling of parent node if present */
|
||||||
if ((reader->node->type == XML_ELEMENT_NODE) ||
|
if ((reader->node->type == XML_ELEMENT_NODE) ||
|
||||||
(reader->node->type == XML_ATTRIBUTE_NODE)) {
|
(reader->node->type == XML_ATTRIBUTE_NODE)) {
|
||||||
reader->state = XML_TEXTREADER_BACKTRACK;
|
reader->state = XML_TEXTREADER_BACKTRACK;
|
||||||
return(1);
|
xmlTextReaderRead(reader);// This will move to parent if present
|
||||||
|
//return(xmlTextReaderReadTree(reader));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1876,7 +1881,8 @@ xmlTextReaderNextTree(xmlTextReaderPtr reader)
|
|||||||
reader->node = reader->node->parent;
|
reader->node = reader->node->parent;
|
||||||
reader->depth--;
|
reader->depth--;
|
||||||
reader->state = XML_TEXTREADER_BACKTRACK;
|
reader->state = XML_TEXTREADER_BACKTRACK;
|
||||||
return(1);
|
xmlTextReaderNextTree(reader); //Repeat process to move to sibling of parent node if present
|
||||||
|
//return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader->state = XML_TEXTREADER_END;
|
reader->state = XML_TEXTREADER_END;
|
||||||
|
|||||||
Reference in New Issue
Block a user