From 7de19b18af34fad356937fc46386eb0b7c72a5a9 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 3 Jun 2003 20:40:01 +0000 Subject: [PATCH] Fix mxmlWalkNext(). Add changelog file. --- .cvsignore | 2 ++ CHANGES | 12 ++++++++++++ README | 4 +++- mxml-search.c | 46 ++++++++++++++++++++++++++++++++++------------ testmxml.c | 26 +++++++++++++++++++++++--- 5 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 CHANGES diff --git a/.cvsignore b/.cvsignore index 6cbf549..6b75a6a 100644 --- a/.cvsignore +++ b/.cvsignore @@ -4,3 +4,5 @@ config.status Makefile libmxml.a testmxml +*.bck +*.bak diff --git a/CHANGES b/CHANGES new file mode 100644 index 0000000..5c0f359 --- /dev/null +++ b/CHANGES @@ -0,0 +1,12 @@ +README - 06/03/2003 +------------------- + + +CHANGES IN Mini-XML 0.91 + + - mxmlWalkNext() would go into an infinite loop. + + +CHANGES IN Mini-XML 0.9 + + - Initial public release. diff --git a/README b/README index 681cdc2..eef2b03 100644 --- a/README +++ b/README @@ -4,7 +4,9 @@ README - 06/03/2003 INTRODUCTION - This README file describes the Mini-XML library version 0.9. + This README file describes the Mini-XML library version + 0.91. + Mini-XML is a small XML parsing library that you can use to read XML and XML-like data files in your application without requiring large non-standard libraries. Mini-XML only diff --git a/mxml-search.c b/mxml-search.c index 8a813a2..0a545df 100644 --- a/mxml-search.c +++ b/mxml-search.c @@ -1,5 +1,5 @@ /* - * "$Id: mxml-search.c,v 1.1 2003/06/03 19:46:30 mike Exp $" + * "$Id: mxml-search.c,v 1.2 2003/06/03 20:40:01 mike Exp $" * * Search/navigation functions for mini-XML, a small XML-like file * parsing library. @@ -21,6 +21,7 @@ * mxmlFindElement() - Find the named element. * mxmlWalkNext() - Walk to the next logical node in the tree. * mxmlWalkPrev() - Walk to the previous logical node in the tree. + * mxml_walk_next() - Walk to the next logical node in the tree. */ /* @@ -30,6 +31,14 @@ #include "mxml.h" +/* + * Local functions... + */ + +mxml_node_t *mxml_walk_next(mxml_node_t *node, mxml_node_t *top, + int descend); + + /* * 'mxmlFindElement()' - Find the named element. */ @@ -79,16 +88,7 @@ mxml_node_t * /* O - Next node or NULL */ mxmlWalkNext(mxml_node_t *node, /* I - Current node */ mxml_node_t *top) /* I - Top node */ { - if (!node) - return (NULL); - else if (node->child) - return (node->child); - else if (node->next) - return (node->next); - else if (node->parent != top) - return (mxmlWalkNext(node->parent, top)); - else - return (NULL); + return (mxml_walk_next(node, top, 1)); } @@ -112,5 +112,27 @@ mxmlWalkPrev(mxml_node_t *node, /* I - Current node */ /* - * End of "$Id: mxml-search.c,v 1.1 2003/06/03 19:46:30 mike Exp $". + * 'mxml_walk_next()' - Walk to the next logical node in the tree. + */ + +mxml_node_t * /* O - Next node or NULL */ +mxml_walk_next(mxml_node_t *node, /* I - Current node */ + mxml_node_t *top, /* I - Top node */ + int descend) /* I - 1 = descend, 0 = don't */ +{ + if (!node) + return (NULL); + else if (node->child && descend) + return (node->child); + else if (node->next) + return (node->next); + else if (node->parent != top) + return (mxml_walk_next(node->parent, top, 0)); + else + return (NULL); +} + + +/* + * End of "$Id: mxml-search.c,v 1.2 2003/06/03 20:40:01 mike Exp $". */ diff --git a/testmxml.c b/testmxml.c index 56cf7eb..673fac5 100644 --- a/testmxml.c +++ b/testmxml.c @@ -1,5 +1,5 @@ /* - * "$Id: testmxml.c,v 1.2 2003/06/03 20:24:28 mike Exp $" + * "$Id: testmxml.c,v 1.3 2003/06/03 20:40:01 mike Exp $" * * Test program for mini-XML, a small XML-like file parsing library. * @@ -44,7 +44,8 @@ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line args */ { FILE *fp; /* File to read */ - mxml_node_t *tree; /* XML tree */ + mxml_node_t *tree, /* XML tree */ + *node; /* Node which should be in test.xml */ /* @@ -81,6 +82,25 @@ main(int argc, /* I - Number of command-line args */ return (1); } + /* + * Verify that mxmlFindElement() and indirectly mxmlWalkNext() work + * properly... + */ + + if ((node = mxmlFindElement(tree, tree, "choice")) == NULL) + { + fputs("Unable to find first element in XML tree!\n", stderr); + mxmlDelete(tree); + return (1); + } + + if ((node = mxmlFindElement(node, tree, "choice")) == NULL) + { + fputs("Unable to find second element in XML tree!\n", stderr); + mxmlDelete(tree); + return (1); + } + /* * Print the XML tree... */ @@ -127,5 +147,5 @@ type_cb(mxml_node_t *node) /* I - Element node */ /* - * End of "$Id: testmxml.c,v 1.2 2003/06/03 20:24:28 mike Exp $". + * End of "$Id: testmxml.c,v 1.3 2003/06/03 20:40:01 mike Exp $". */