1
0
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:
Daniel Veillard
2008-08-25 14:53:31 +00:00
parent f4f4e4853a
commit aa6de47ebf
7 changed files with 484 additions and 397 deletions

View File

@@ -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>
* include/libxml/entities.h entities.c SAX2.c parser.c: rework

View File

@@ -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
xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
xmlCreateEntity(xmlDictPtr dict, 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 = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
if (ret == NULL) {
xmlEntitiesErrMemory("xmlAddEntity:: malloc failed");
xmlEntitiesErrMemory("xmlCreateEntity: malloc failed");
return(NULL);
}
memset(ret, 0, sizeof(xmlEntity));
@@ -216,6 +190,50 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
the defining entity */
ret->orig = NULL;
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;
if (xmlHashAddEntry(table, name, ret)) {
@@ -362,6 +380,44 @@ xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type,
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:
* @table: an entity table

View File

@@ -57,6 +57,8 @@ struct _xmlEntity {
const xmlChar *URI; /* the full URI as computed */
int owner; /* does the entity own the childrens */
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
xmlInitializePredefinedEntities (void);
#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
xmlAddDocEntity (xmlDocPtr doc,
const xmlChar *name,

View File

@@ -3600,7 +3600,7 @@ load_xpath_expr (xmlDocPtr parent_doc, const char* filename) {
xpath = xmlXPathEvalExpression(expr, ctx);
if(xpath == NULL) {
fprintf(stderr,"Error: unable to evaluate xpath expression\n");
xmlFree(expr);
xmlFree(expr);
xmlXPathFreeContext(ctx);
xmlFreeDoc(doc);
return(NULL);
@@ -4392,7 +4392,6 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
initializeLibxml2();
for (a = 1; a < argc;a++) {
if (!strcmp(argv[a], "-v"))
verbose = 1;

View File

@@ -446,22 +446,27 @@ error:
}
static int
xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur) {
xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur, int level) {
xmlChar *profile;
int ret = 0;
int tests = 0;
int output = 0;
if (level == 1) {
profile = xmlGetProp(cur, BAD_CAST "PROFILE");
if (profile != NULL) {
output = 1;
level++;
printf("Test cases: %s\n", (char *) profile);
xmlFree(profile);
}
}
cur = cur->children;
while (cur != NULL) {
/* look only at elements we ignore everything else */
if (cur->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(cur->name, BAD_CAST "TESTCASES")) {
ret += xmlconfTestCases(doc, cur);
ret += xmlconfTestCases(doc, cur, level);
} else if (xmlStrEqual(cur->name, BAD_CAST "TEST")) {
if (xmlconfTestItem(doc, cur) >= 0)
ret++;
@@ -472,8 +477,10 @@ xmlconfTestCases(xmlDocPtr doc, xmlNodePtr cur) {
}
cur = cur->next;
}
if (output == 1) {
if (tests > 0)
printf("Test cases: %d tests\n", tests);
}
return(ret);
}
@@ -493,7 +500,7 @@ xmlconfTestSuite(xmlDocPtr doc, xmlNodePtr cur) {
/* look only at elements we ignore everything else */
if (cur->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(cur->name, BAD_CAST "TESTCASES")) {
ret += xmlconfTestCases(doc, cur);
ret += xmlconfTestCases(doc, cur, 1);
} else {
fprintf(stderr, "Unhandled element %s\n", (char *)cur->name);
}
@@ -584,6 +591,7 @@ main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
ret = 1;
printf("Total %d tests, %d errors, %d leaks\n",
nb_tests, nb_errors, nb_leaks);
printf("See %s for detailed output\n", LOGFILE);
}
xmlXPathFreeContext(ctxtXPath);
xmlCleanupParser();

View File

@@ -1847,17 +1847,22 @@ xmlTextReaderNextTree(xmlTextReaderPtr reader)
}
if (reader->state != XML_TEXTREADER_BACKTRACK) {
if (reader->node->children != 0) {
reader->node = reader->node->children;
reader->depth++;
/* Here removed traversal to child, because we want to skip the subtree,
replace with traversal to sibling to skip subtree */
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;
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) ||
(reader->node->type == XML_ATTRIBUTE_NODE)) {
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->depth--;
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;