Fix mxmldoc handling of comments, now getting quite usable documentation.

Add additional tests to testmxml.

Bump to v1.0.
web
Michael R Sweet 22 years ago
parent 70040fe9d2
commit 0cc4b9e665
  1. 8
      CHANGES
  2. 21
      documentation.html
  3. 47
      mxml.xml
  4. 155
      mxmldoc.c
  5. 177
      testmxml.c

@ -1,12 +1,14 @@
README - 06/07/2003
README - 06/14/2003
-------------------
CHANGES IN Mini-XML 0.94
CHANGES IN Mini-XML 1.0
- The mxmldoc program now handles function arguments,
structures, unions, enumerations, classes, and
typedefs properly. Finally some documentation...
typedefs properly.
- Documentation provided via mxmldoc and more in-line
comments in the code.
CHANGES IN Mini-XML 0.93

@ -58,7 +58,7 @@
</ul>
<hr noshade/>
<h2><a name="mxmlAdd">mxmlAdd()</a></h2>
<p>Local functions...</p>
<p>Add a node to a tree.</p>
<h3>Syntax</h3>
<pre>
void
@ -165,7 +165,7 @@ mxmlFindElement(
<p>Element node or NULL</p>
<hr noshade/>
<h2><a name="mxmlLoadFile">mxmlLoadFile()</a></h2>
<p>mxml_node_t *Top nodeFILE *File to read frommxml_type_tCallback functionNew nodemxml_node_t *Create a new element node.mxml_node_t *Parent nodeconst char *Name of elementNew nodemxml_node_t *Create a new integer node.mxml_node_t *Parent nodeintInteger valueNew nodemxml_node_t *Create a new opaque string.mxml_node_t *Parent nodeconst char *Opaque stringNew nodemxml_node_t *Create a new real number node.mxml_node_t *Parent nodedoubleReal number valueNew nodemxml_node_t *Create a new text fragment node.mxml_node_t *Parent nodeintLeading whitespace?const char *StringRemove a node from its parent.mxml_node_t *Node to remove0 on success, -1 on errorintSave an XML tree to a file.mxml_node_t *Node to writeFILE *File to write tointWhitespace callbackNext node or NULLmxml_node_t *Walk to the next logical node in the tree.mxml_node_t *Current nodemxml_node_t *Top nodeintDescend into tree?Previous node or NULLmxml_node_t *Walk to the previous logical node in the tree.mxml_node_t *Current nodemxml_node_t *Top nodeintDescend into tree?Data types...char *Attribute namechar *Attribute valuestruct mxml_attr_sstruct mxml_value_smxml_node_t *First child nodemxml_node_t *Last child nodemxml_node_t *Next node under same parentmxml_node_t *Parent nodemxml_node_t *Previous node under same parentmxml_type_tNode typemxml_value_tNode valuechar *Fragment stringintLeading whitespace?struct mxml_text_sNode TypeXML element with attributesInteger valueOpaque stringReal valueText fragmentAttribute ValueElement ValueText ValueNode ValueNodeC++ support...Prototypes...C++ support...End of &quot;$Id: documentation.html,v 1.3 2003/06/07 21:27:05 mike Exp $&quot;.enum mxml_type_emxml_attr_t *Attributeschar *Name of elementintNumber of attributesunion mxml_value_umxml_element_tElementintInteger numberchar *Opaque stringdoubleReal numbermxml_text_tText fragmentmxml_node_t *Current nodemxml_node_t *Parent nodeNode typeconst char *String to writeFile to write toint(*cb)(mxml_node_t *int) intWhere valueCurrent column</p>
<p>Load a file into an XML node tree.</p>
<h3>Syntax</h3>
<pre>
mxml_node_t *
@ -183,7 +183,7 @@ mxmlLoadFile(
<tr><td><tt>(*cb)(mxml_node_t *)</tt></td><td>Callback function</td></tr>
</tbody></table></p>
<h3>Returns</h3>
<p>Local functions...</p>
<p>First node</p>
<hr noshade/>
<h2><a name="mxmlNewElement">mxmlNewElement()</a></h2>
<p>Create a new element node.</p>
@ -370,7 +370,7 @@ mxmlWalkPrev(
</ul>
<hr noshade/>
<h2><a name="mxml_attr_s">mxml_attr_s</a></h2>
<p>Data types...</p>
<p>Attribute Value</p>
<h3>Definition</h3>
<pre>
struct mxml_attr_s
@ -388,7 +388,7 @@ struct mxml_attr_s
</tbody></table></p>
<hr noshade/>
<h2><a name="mxml_node_s">mxml_node_s</a></h2>
<p>mxml_node_t *First child nodemxml_node_t *Last child nodemxml_node_t *Next node under same parentmxml_node_t *Parent nodemxml_node_t *Previous node under same parentmxml_type_tNode typemxml_value_tNode valuechar *Fragment stringintLeading whitespace?struct mxml_text_sNode TypeXML element with attributesInteger valueOpaque stringReal valueText fragmentAttribute ValueElement ValueText ValueNode ValueNodeC++ support...Prototypes...C++ support...End of &quot;$Id: documentation.html,v 1.3 2003/06/07 21:27:05 mike Exp $&quot;.enum mxml_type_emxml_attr_t *Attributeschar *Name of elementintNumber of attributesunion mxml_value_umxml_element_tElementintInteger numberchar *Opaque stringdoubleReal numbermxml_text_tText fragmentmxml_node_t *Current nodemxml_node_t *Parent nodeNode typeconst char *String to writeFile to write toint(*cb)(mxml_node_t *int) intWhere valueCurrent column</p>
<p>Node</p>
<h3>Definition</h3>
<pre>
struct mxml_node_s
@ -416,7 +416,7 @@ struct mxml_node_s
</tbody></table></p>
<hr noshade/>
<h2><a name="mxml_text_s">mxml_text_s</a></h2>
<p>char *Fragment stringintLeading whitespace?struct mxml_text_sNode TypeXML element with attributesInteger valueOpaque stringReal valueText fragmentAttribute ValueElement ValueText ValueNode ValueNodeC++ support...Prototypes...C++ support...End of &quot;$Id: documentation.html,v 1.3 2003/06/07 21:27:05 mike Exp $&quot;.enum mxml_type_emxml_attr_t *Attributeschar *Name of elementintNumber of attributesunion mxml_value_umxml_element_tElementintInteger numberchar *Opaque stringdoubleReal numbermxml_text_tText fragmentmxml_node_t *Current nodemxml_node_t *Parent nodeNode typeconst char *String to writeFile to write toint(*cb)(mxml_node_t *int) intWhere valueCurrent column</p>
<p>Text Value</p>
<h3>Definition</h3>
<pre>
struct mxml_text_s
@ -434,7 +434,7 @@ struct mxml_text_s
</tbody></table></p>
<hr noshade/>
<h2><a name="mxml_value_s">mxml_value_s</a></h2>
<p>mxml_attr_t *Attributeschar *Name of elementintNumber of attributesunion mxml_value_umxml_element_tElementintInteger numberchar *Opaque stringdoubleReal numbermxml_text_tText fragmentmxml_node_t *Current nodemxml_node_t *Parent nodeNode typeconst char *String to writeFile to write toint(*cb)(mxml_node_t *int) intWhere valueCurrent column</p>
<p>Element Value</p>
<h3>Definition</h3>
<pre>
struct mxml_value_s
@ -462,30 +462,35 @@ struct mxml_value_s
</ul>
<hr noshade/>
<h2><a name="mxml_attr_t">mxml_attr_t</a></h2>
<p>Attribute Value</p>
<h3>Definition</h3>
<pre>
typedef struct mxml_attr_s mxml_attr_t;
</pre>
<hr noshade/>
<h2><a name="mxml_element_t">mxml_element_t</a></h2>
<p>Element Value</p>
<h3>Definition</h3>
<pre>
typedef struct mxml_value_s mxml_element_t;
</pre>
<hr noshade/>
<h2><a name="mxml_text_t">mxml_text_t</a></h2>
<p>Text Value</p>
<h3>Definition</h3>
<pre>
typedef struct mxml_text_s mxml_text_t;
</pre>
<hr noshade/>
<h2><a name="mxml_type_t">mxml_type_t</a></h2>
<p>Node Type</p>
<h3>Definition</h3>
<pre>
typedef enum mxml_type_e mxml_type_t;
</pre>
<hr noshade/>
<h2><a name="mxml_value_t">mxml_value_t</a></h2>
<p>Node Value</p>
<h3>Definition</h3>
<pre>
typedef union mxml_value_u mxml_value_t;
@ -496,7 +501,7 @@ typedef union mxml_value_u mxml_value_t;
</ul>
<hr noshade/>
<h2><a name="mxml_value_u">mxml_value_u</a></h2>
<p>mxml_element_tElementintInteger numberchar *Opaque stringdoubleReal numbermxml_text_tText fragmentmxml_node_t *Current nodemxml_node_t *Parent nodeNode typeconst char *String to writeFile to write toint(*cb)(mxml_node_t *int) intWhere valueCurrent column</p>
<p>Node Value</p>
<h3>Definition</h3>
<pre>
struct mxml_value_u

@ -1,6 +1,5 @@
<?xml version="1.0"?>
<variable name="fp"><type>FILE *</type><description>File to write to</description><description>Callback function</description></variable>
<function name="mxmlAdd"><description>Local functions...</description><argument
<function name="mxmlAdd"><description>Add a node to a tree.</description><argument
name="parent" direction="I"><type>mxml_node_t *</type><description>Parent node</description></argument>
<argument name="where" direction="I"><type>int</type><description>Where to add</description></argument>
<argument name="child" direction="I"><type>mxml_node_t *</type><description>Child node for where</description></argument>
@ -30,9 +29,10 @@ direction="I"><type>mxml_node_t *</type><description>Current node</description><
<argument name="value" direction="I"><type>const char *</type><description>Attribute value, or NULL for any</description></argument>
<argument name="descend" direction="I"><type>int</type><description>Descend into tree?</description></argument>
</function>
<function name="mxmlLoadFile"><returnvalue><description>Local functions...</description><type>mxml_node_t
<function name="mxmlLoadFile"><returnvalue><description>First node</description><type>mxml_node_t
*</type></returnvalue>
<description/><argument name="top" direction="I"><type>mxml_node_t *</type><description>Top node</description></argument>
<description>Load a file into an XML node tree.</description><argument
name="top" direction="I"><type>mxml_node_t *</type><description>Top node</description></argument>
<argument name="fp" direction="I"><type>FILE *</type><description>File to read from</description></argument>
<argument name="(*cb)(mxml_node_t *)" direction="I"><type>mxml_type_t</type><description>Callback function</description></argument>
</function>
@ -90,14 +90,16 @@ name="node" direction="I"><type>mxml_node_t *</type><description>Current node</d
<argument name="top" direction="I"><type>mxml_node_t *</type><description>Top node</description></argument>
<argument name="descend" direction="I"><type>int</type><description>Descend into tree?</description></argument>
</function>
<struct name="mxml_attr_s"><description>Data types...</description><variable
<struct name="mxml_attr_s"><description>Attribute Value</description><variable
name="name"><type>char *</type><description>Attribute name</description></variable>
<variable name="value"><type>char *</type><description>Attribute value</description></variable>
</struct>
<typedef name="mxml_attr_t"><type>struct mxml_attr_s</type></typedef>
<typedef name="mxml_element_t"><type>struct mxml_value_s</type></typedef>
<struct name="mxml_node_s"><description/><variable name="child"><type>mxml_node_t
*</type><description>First child node</description></variable>
<typedef name="mxml_attr_t"><description>Attribute Value</description><type>struct
mxml_attr_s</type></typedef>
<typedef name="mxml_element_t"><description>Element Value</description><type>struct
mxml_value_s</type></typedef>
<struct name="mxml_node_s"><description>Node</description><variable
name="child"><type>mxml_node_t *</type><description>First child node</description></variable>
<variable name="last_child"><type>mxml_node_t *</type><description>Last child node</description></variable>
<variable name="next"><type>mxml_node_t *</type><description>Next node under same parent</description></variable>
<variable name="parent"><type>mxml_node_t *</type><description>Parent node</description></variable>
@ -105,31 +107,32 @@ name="name"><type>char *</type><description>Attribute name</description></variab
<variable name="type"><type>mxml_type_t</type><description>Node type</description></variable>
<variable name="value"><type>mxml_value_t</type><description>Node value</description></variable>
</struct>
<struct name="mxml_text_s"><description/><variable name="string"><type>char
*</type><description>Fragment string</description></variable>
<struct name="mxml_text_s"><description>Text Value</description><variable
name="string"><type>char *</type><description>Fragment string</description></variable>
<variable name="whitespace"><type>int</type><description>Leading whitespace?</description></variable>
</struct>
<typedef name="mxml_text_t"><type>struct mxml_text_s</type></typedef>
<typedef name="mxml_text_t"><description>Text Value</description><type>struct
mxml_text_s</type></typedef>
<enumeration name="mxml_type_e"><description>Node Type</description><constant
name="MXML_ELEMENT"><description>XML element with attributes</description></constant>
<constant name="MXML_INTEGER"><description>Integer value</description></constant>
<constant name="MXML_OPAQUE"><description>Opaque string</description></constant>
<constant name="MXML_REAL"><description>Real value</description></constant>
<constant name="MXML_TEXT"><description>Text fragment</description><description>Attribute Value</description><description>Element Value</description><description>Text Value</description><description>Node Value</description><description>Node</description><description>C++ support...</description><description>Prototypes...</description><description>C++ support...</description><description>End of &quot;$Id: mxml.xml,v 1.3 2003/06/07 21:27:05 mike Exp $&quot;.</description></constant>
<constant name="MXML_TEXT"><description>Text fragment</description></constant>
</enumeration>
<typedef name="mxml_type_t"><type>enum mxml_type_e</type></typedef>
<struct name="mxml_value_s"><description/><variable name="attrs"><type>mxml_attr_t
*</type><description>Attributes</description></variable>
<typedef name="mxml_type_t"><description>Node Type</description><type>enum
mxml_type_e</type></typedef>
<struct name="mxml_value_s"><description>Element Value</description><variable
name="attrs"><type>mxml_attr_t *</type><description>Attributes</description></variable>
<variable name="name"><type>char *</type><description>Name of element</description></variable>
<variable name="num_attrs"><type>int</type><description>Number of attributes</description></variable>
</struct>
<typedef name="mxml_value_t"><type>union mxml_value_u</type></typedef>
<union name="mxml_value_u"><description/><variable name="element"><type>mxml_element_t</type><description>Element</description></variable>
<typedef name="mxml_value_t"><description>Node Value</description><type>union
mxml_value_u</type></typedef>
<union name="mxml_value_u"><description>Node Value</description><variable
name="element"><type>mxml_element_t</type><description>Element</description></variable>
<variable name="integer"><type>int</type><description>Integer number</description></variable>
<variable name="opaque"><type>char *</type><description>Opaque string</description></variable>
<variable name="real"><type>double</type><description>Real number</description></variable>
<variable name="text"><type>mxml_text_t</type><description>Text fragment</description></variable>
</union><variable name="node"><type>mxml_node_t *</type><description>Current node</description></variable>
<variable name="parent"><type>mxml_node_t *</type><description>Parent node</description><description>Node type</description></variable>
<variable name="s"><type>const char *</type><description>String to write</description><description>File to write to</description></variable>
<variable name="ws"><type>int(*cb)(mxml_node_t *int) int</type><description>Where value</description><description>Current column</description></variable>
</union>

@ -1,5 +1,5 @@
/*
* "$Id: mxmldoc.c,v 1.10 2003/06/07 21:27:05 mike Exp $"
* "$Id: mxmldoc.c,v 1.11 2003/06/14 22:14:17 mike Exp $"
*
* Documentation generator using mini-XML, a small XML-like file parsing
* library.
@ -18,6 +18,16 @@
*
* Contents:
*
* main() - Main entry for test program.
* add_variable() - Add a variable or argument.
* scan_file() - Scan a source file.
* sort_node() - Insert a node sorted into a tree.
* update_comment() - Update a comment node.
* write_documentation() - Write HTML documentation.
* write_element() - Write an elements text nodes.
* write_string() - Write a string, quoting XHTML special chars
* as needed...
* ws_cb() - Whitespace callback for saving.
*/
/*
@ -465,7 +475,28 @@ scan_file(const char *filename, /* I - Filename */
type = NULL;
}
if (typedefnode)
{
/*
* Copy comment for typedef as well as class/struct/union...
*/
mxmlNewText(comment, 0,
comment->last_child->value.text.string);
description = mxmlNewElement(typedefnode, "description");
#ifdef DEBUG
fputs(" duplicating comment for typedef...\n", stderr);
#endif /* DEBUG */
update_comment(typedefnode, comment->last_child);
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
comment->last_child);
}
description = mxmlNewElement(structclass, "description");
#ifdef DEBUG
fprintf(stderr, " adding comment to %s...\n",
structclass->value.element.name);
#endif /* DEBUG */
update_comment(structclass, comment->last_child);
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
comment->last_child);
@ -522,7 +553,27 @@ scan_file(const char *filename, /* I - Filename */
type = NULL;
}
if (typedefnode)
{
/*
* Copy comment for typedef as well as class/struct/union...
*/
mxmlNewText(comment, 0,
comment->last_child->value.text.string);
description = mxmlNewElement(typedefnode, "description");
#ifdef DEBUG
fputs(" duplicating comment for typedef...\n", stderr);
#endif /* DEBUG */
update_comment(typedefnode, comment->last_child);
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
comment->last_child);
}
description = mxmlNewElement(enumeration, "description");
#ifdef DEBUG
fputs(" adding comment to enumeration...\n", stderr);
#endif /* DEBUG */
update_comment(enumeration, comment->last_child);
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
comment->last_child);
@ -544,6 +595,7 @@ scan_file(const char *filename, /* I - Filename */
#endif /* DEBUG */
enumeration = NULL;
constant = NULL;
if (braces > 0)
braces --;
@ -649,17 +701,38 @@ scan_file(const char *filename, /* I - Filename */
*bufptr = '\0';
if (comment->child != comment->last_child)
{
#ifdef DEBUG
fprintf(stderr, " removing comment %p, last comment %p...\n",
comment->child, comment->last_child);
#endif /* DEBUG */
mxmlDelete(comment->child);
#ifdef DEBUG
fprintf(stderr, " new comment %p, last comment %p...\n",
comment->child, comment->last_child);
#endif /* DEBUG */
}
#ifdef DEBUG
fprintf(stderr, " processing comment, variable=%p, constant=%p, tree=\"%s\"\n",
variable, constant, tree->value.element.name);
#endif /* DEBUG */
if (variable)
{
description = mxmlNewElement(variable, "description");
#ifdef DEBUG
fputs(" adding comment to variable...\n", stderr);
#endif /* DEBUG */
update_comment(variable,
mxmlNewText(description, 0, buffer));
}
else if (constant)
{
description = mxmlNewElement(constant, "description");
#ifdef DEBUG
fputs(" adding comment to constant...\n", stderr);
#endif /* DEBUG */
update_comment(constant,
mxmlNewText(description, 0, buffer));
}
@ -668,12 +741,24 @@ scan_file(const char *filename, /* I - Filename */
NULL, NULL, MXML_DESCEND_FIRST))
{
description = mxmlNewElement(tree, "description");
#ifdef DEBUG
fputs(" adding comment to parent...\n", stderr);
#endif /* DEBUG */
update_comment(tree,
mxmlNewText(description, 0, buffer));
}
else
{
#ifdef DEBUG
fprintf(stderr, " before adding comment, child=%p, last_child=%p\n",
comment->child, comment->last_child);
#endif /* DEBUG */
mxmlNewText(comment, 0, buffer);
#ifdef DEBUG
fprintf(stderr, " after adding comment, child=%p, last_child=%p\n",
comment->child, comment->last_child);
#endif /* DEBUG */
}
#ifdef DEBUG
fprintf(stderr, "C comment: <<< %s >>>\n", buffer);
#endif /* DEBUG */
@ -706,17 +791,33 @@ scan_file(const char *filename, /* I - Filename */
*bufptr = '\0';
if (comment->child != comment->last_child)
{
#ifdef DEBUG
fprintf(stderr, " removing comment %p, last comment %p...\n",
comment->child, comment->last_child);
#endif /* DEBUG */
mxmlDelete(comment->child);
#ifdef DEBUG
fprintf(stderr, " new comment %p, last comment %p...\n",
comment->child, comment->last_child);
#endif /* DEBUG */
}
if (variable)
{
description = mxmlNewElement(variable, "description");
#ifdef DEBUG
fputs(" adding comment to variable...\n", stderr);
#endif /* DEBUG */
update_comment(variable,
mxmlNewText(description, 0, buffer));
}
else if (constant)
{
description = mxmlNewElement(constant, "description");
#ifdef DEBUG
fputs(" adding comment to constant...\n", stderr);
#endif /* DEBUG */
update_comment(constant,
mxmlNewText(description, 0, buffer));
}
@ -725,6 +826,9 @@ scan_file(const char *filename, /* I - Filename */
NULL, NULL, MXML_DESCEND_FIRST))
{
description = mxmlNewElement(tree, "description");
#ifdef DEBUG
fputs(" adding comment to parent...\n", stderr);
#endif /* DEBUG */
update_comment(tree,
mxmlNewText(description, 0, buffer));
}
@ -755,17 +859,33 @@ scan_file(const char *filename, /* I - Filename */
*bufptr = '\0';
if (comment->child != comment->last_child)
{
#ifdef DEBUG
fprintf(stderr, " removing comment %p, last comment %p...\n",
comment->child, comment->last_child);
#endif /* DEBUG */
mxmlDelete(comment->child);
#ifdef DEBUG
fprintf(stderr, " new comment %p, last comment %p...\n",
comment->child, comment->last_child);
#endif /* DEBUG */
}
if (variable)
{
description = mxmlNewElement(variable, "description");
#ifdef DEBUG
fputs(" adding comment to variable...\n", stderr);
#endif /* DEBUG */
update_comment(variable,
mxmlNewText(description, 0, buffer));
}
else if (constant)
{
description = mxmlNewElement(constant, "description");
#ifdef DEBUG
fputs(" adding comment to constant...\n", stderr);
#endif /* DEBUG */
update_comment(constant,
mxmlNewText(description, 0, buffer));
}
@ -774,6 +894,9 @@ scan_file(const char *filename, /* I - Filename */
NULL, NULL, MXML_DESCEND_FIRST))
{
description = mxmlNewElement(tree, "description");
#ifdef DEBUG
fputs(" adding comment to parent...\n", stderr);
#endif /* DEBUG */
update_comment(tree,
mxmlNewText(description, 0, buffer));
}
@ -858,12 +981,24 @@ scan_file(const char *filename, /* I - Filename */
function = mxmlNewElement(MXML_NO_PARENT, "function");
mxmlElementSetAttr(function, "name", buffer);
#ifdef DEBUG
fprintf(stderr, "function: %s\n", buffer);
fprintf(stderr, " child = (%p) %s\n",
comment->child, comment->child->value.text.string);
fprintf(stderr, " last_child = (%p) %s\n",
comment->last_child,
comment->last_child->value.text.string);
#endif /* DEBUG */
if (!type->last_child ||
strcmp(type->last_child->value.text.string, "void"))
{
returnvalue = mxmlNewElement(function, "returnvalue");
description = mxmlNewElement(returnvalue, "description");
#ifdef DEBUG
fputs(" adding comment to returnvalue...\n", stderr);
#endif /* DEBUG */
update_comment(returnvalue, comment->last_child);
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
comment->last_child);
@ -874,6 +1009,9 @@ scan_file(const char *filename, /* I - Filename */
mxmlDelete(type);
description = mxmlNewElement(function, "description");
#ifdef DEBUG
fputs(" adding comment to function...\n", stderr);
#endif /* DEBUG */
update_comment(function, comment->last_child);
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT,
comment->last_child);
@ -937,7 +1075,7 @@ scan_file(const char *filename, /* I - Filename */
type = NULL;
typedefnode = NULL;
}
else
else if (!parens)
{
/*
* Variable definition...
@ -1080,6 +1218,11 @@ update_comment(mxml_node_t *parent, /* I - Parent node */
char *ptr; /* Pointer into comment */
#ifdef DEBUG
fprintf(stderr, "update_comment(parent=%p, comment=%p)\n",
parent, comment);
#endif /* DEBUG */
/*
* Range check the input...
*/
@ -1157,6 +1300,10 @@ update_comment(mxml_node_t *parent, /* I - Parent node */
*ptr = '\0';
for (; ptr > comment->value.text.string && isspace(*ptr); ptr --)
*ptr = '\0';
#ifdef DEBUG
fprintf(stderr, " updated comment = %s\n", comment->value.text.string);
#endif /* DEBUG */
}
@ -1779,5 +1926,5 @@ ws_cb(mxml_node_t *node, /* I - Element node */
/*
* End of "$Id: mxmldoc.c,v 1.10 2003/06/07 21:27:05 mike Exp $".
* End of "$Id: mxmldoc.c,v 1.11 2003/06/14 22:14:17 mike Exp $".
*/

@ -1,5 +1,5 @@
/*
* "$Id: testmxml.c,v 1.7 2003/06/04 21:19:00 mike Exp $"
* "$Id: testmxml.c,v 1.8 2003/06/14 22:14:17 mike Exp $"
*
* Test program for mini-XML, a small XML-like file parsing library.
*
@ -46,9 +46,17 @@ int /* O - Exit status */
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 */
*node; /* Node which should be in test.xml */
FILE *fp; /* File to read */
mxml_node_t *tree, /* XML tree */
*node; /* Node which should be in test.xml */
static const char *types[] = /* Strings for node types */
{
"MXML_ELEMENT",
"MXML_INTEGER",
"MXML_OPAQUE",
"MXML_REAL",
"MXML_TEXT"
};
/*
@ -61,6 +69,165 @@ main(int argc, /* I - Number of command-line args */
return (1);
}
/*
* Test the basic functionality...
*/
tree = mxmlNewElement(MXML_NO_PARENT, "element");
if (!tree)
{
fputs("ERROR: No parent node in basic test!\n", stderr);
return (1);
}
if (tree->type != MXML_ELEMENT)
{
fprintf(stderr, "ERROR: Parent has type %s (%d), expected MXML_ELEMENT!\n",
tree->type < MXML_ELEMENT || tree->type > MXML_TEXT ?
"UNKNOWN" : types[tree->type], tree->type);
mxmlDelete(tree);
return (1);
}
if (strcmp(tree->value.element.name, "element"))
{
fprintf(stderr, "ERROR: Parent value is \"%s\", expected \"element\"!\n",
tree->value.element.name);
mxmlDelete(tree);
return (1);
}
mxmlNewInteger(tree, 123);
mxmlNewOpaque(tree, "opaque");
mxmlNewReal(tree, 123.4f);
mxmlNewText(tree, 1, "text");
node = tree->child;
if (!node)
{
fputs("ERROR: No first child node in basic test!\n", stderr);
mxmlDelete(tree);
return (1);
}
if (node->type != MXML_INTEGER)
{
fprintf(stderr, "ERROR: First child has type %s (%d), expected MXML_INTEGER!\n",
node->type < MXML_ELEMENT || node->type > MXML_TEXT ?
"UNKNOWN" : types[node->type], node->type);
mxmlDelete(tree);
return (1);
}
if (node->value.integer != 123)
{
fprintf(stderr, "ERROR: First child value is %d, expected 123!\n",
node->value.integer);
mxmlDelete(tree);
return (1);
}
node = node->next;
if (!node)
{
fputs("ERROR: No second child node in basic test!\n", stderr);
mxmlDelete(tree);
return (1);
}
if (node->type != MXML_OPAQUE)
{
fprintf(stderr, "ERROR: Second child has type %s (%d), expected MXML_OPAQUE!\n",
node->type < MXML_ELEMENT || node->type > MXML_TEXT ?
"UNKNOWN" : types[node->type], node->type);
mxmlDelete(tree);
return (1);
}
if (!node->value.opaque || strcmp(node->value.opaque, "opaque"))
{
fprintf(stderr, "ERROR: Second child value is \"%s\", expected \"opaque\"!\n",
node->value.opaque ? node->value.opaque : "(null)");
mxmlDelete(tree);
return (1);
}
node = node->next;
if (!node)
{
fputs("ERROR: No third child node in basic test!\n", stderr);
mxmlDelete(tree);
return (1);
}
if (node->type != MXML_REAL)
{
fprintf(stderr, "ERROR: Third child has type %s (%d), expected MXML_REAL!\n",
node->type < MXML_ELEMENT || node->type > MXML_TEXT ?
"UNKNOWN" : types[node->type], node->type);
mxmlDelete(tree);
return (1);
}
if (node->value.real != 123.4f)
{
fprintf(stderr, "ERROR: Third child value is %f, expected 123.4!\n",
node->value.real);
mxmlDelete(tree);
return (1);
}
node = node->next;
if (!node)
{
fputs("ERROR: No fourth child node in basic test!\n", stderr);
mxmlDelete(tree);
return (1);
}
if (node->type != MXML_TEXT)
{
fprintf(stderr, "ERROR: Fourth child has type %s (%d), expected MXML_TEXT!\n",
node->type < MXML_ELEMENT || node->type > MXML_TEXT ?
"UNKNOWN" : types[node->type], node->type);
mxmlDelete(tree);
return (1);
}
if (!node->value.text.whitespace ||
!node->value.text.string || strcmp(node->value.text.string, "text"))
{
fprintf(stderr, "ERROR: Fourth child value is %d,\"%s\", expected 1,\"text\"!\n",
node->value.text.whitespace,
node->value.text.string ? node->value.text.string : "(null)");
mxmlDelete(tree);
return (1);
}
mxmlDelete(tree->child);
mxmlDelete(tree->child);
mxmlDelete(tree->child);
mxmlDelete(tree->child);
if (tree->child)
{
fputs("ERROR: Child pointer not NULL after deleting all children!\n", stderr);
return (1);
}
if (tree->last_child)
{
fputs("ERROR: Last child pointer not NULL after deleting all children!\n", stderr);
return (1);
}
mxmlDelete(tree);
/*
* Open the file...
*/
@ -212,5 +379,5 @@ whitespace_cb(mxml_node_t *node, /* I - Element node */
/*
* End of "$Id: testmxml.c,v 1.7 2003/06/04 21:19:00 mike Exp $".
* End of "$Id: testmxml.c,v 1.8 2003/06/14 22:14:17 mike Exp $".
*/

Loading…
Cancel
Save