From a57b72a55663aa2b3d73c16719c389c269313c53 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 19 Mar 2008 21:09:21 +0000 Subject: [PATCH] Fixes for enum typedefs (still working on comments...) --- CHANGES | 8 ++++- mxmldoc.c | 92 +++++++++++++++++++++++++++++++++++++------------- test/dotest.sh | 6 ++-- 3 files changed, 80 insertions(+), 26 deletions(-) diff --git a/CHANGES b/CHANGES index 956d5c5..0afe64a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,12 @@ -CHANGES - 2008-01-28 +CHANGES - 2008-03-18 -------------------- +CHANGES IN Mini-XML 2.5.1 + + - The mxmldoc program now handles "typedef enum name {} name" + correctly. + + CHANGES IN Mini-XML 2.5 - The mxmldoc program now makes greater use of CSS and diff --git a/mxmldoc.c b/mxmldoc.c index 5a92a78..d62ecb0 100644 --- a/mxmldoc.c +++ b/mxmldoc.c @@ -1,3 +1,4 @@ +/*#define DEBUG 1*/ /* * "$Id$" * @@ -1206,7 +1207,9 @@ scan_file(const char *filename, /* I - Filename */ if (structclass) scope = NULL; - enumeration = NULL; + if (!typedefnode) + enumeration = NULL; + constant = NULL; structclass = NULL; @@ -1261,10 +1264,11 @@ scan_file(const char *filename, /* I - Filename */ case ';' : #ifdef DEBUG fputs("Identifier: <<<< ; >>>\n", stderr); - fprintf(stderr, " function=%p, type=%p\n", function, type); + fprintf(stderr, " enumeration=%p, function=%p, type=%p, type->child=%p, typedefnode=%p\n", + enumeration, function, type, type ? type->child : NULL, typedefnode); #endif /* DEBUG */ - if (function) + if (function) { if (!strcmp(tree->value.element.name, "class")) { @@ -1283,7 +1287,7 @@ scan_file(const char *filename, /* I - Filename */ if (type) { /* - * See if we have a function typedef... + * See if we have a typedef... */ if (type->child && @@ -1306,23 +1310,56 @@ scan_file(const char *filename, /* I - Filename */ break; } - if (node) - { - mxmlElementSetAttr(typedefnode, "name", - node->value.text.string); - sort_node(tree, typedefnode); + if (!node) + node = type->last_child; +#ifdef DEBUG + fprintf(stderr, " ADDING TYPEDEF FOR %p(%s)...\n", + node, node->value.text.string); +#endif /* DEBUG */ + + mxmlElementSetAttr(typedefnode, "name", + node->value.text.string); + sort_node(tree, typedefnode); + + if (type->child != node) mxmlDelete(type->child); - mxmlDelete(node); - if (type->child) - type->child->value.text.whitespace = 0; + mxmlDelete(node); - mxmlAdd(typedefnode, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, - type); - type = NULL; - break; - } + if (type->child) + type->child->value.text.whitespace = 0; + + mxmlAdd(typedefnode, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, + type); + type = NULL; + break; + } + else if (typedefnode && enumeration) + { + /* + * Add enum typedef... + */ + + node = type->child; + +#ifdef DEBUG + fprintf(stderr, " ADDING TYPEDEF FOR %p(%s)...\n", + node, node->value.text.string); +#endif /* DEBUG */ + + mxmlElementSetAttr(typedefnode, "name", + node->value.text.string); + sort_node(tree, typedefnode); + mxmlDelete(type); + + type = mxmlNewElement(typedefnode, "type"); + mxmlNewText(type, 0, "enum"); + mxmlNewText(type, 1, + mxmlElementGetAttr(enumeration, "name")); + enumeration = NULL; + type = NULL; + break; } mxmlDelete(type); @@ -1438,8 +1475,11 @@ scan_file(const char *filename, /* I - Filename */ if (comment->child != comment->last_child) { #ifdef DEBUG - fprintf(stderr, " removing comment %p, last comment %p...\n", - comment->child, comment->last_child); + fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n", + comment->child, + comment->child ? comment->child->value.text.string : "", + comment->last_child, + comment->last_child ? comment->last_child->value.text.string : ""); #endif /* DEBUG */ mxmlDelete(comment->child); #ifdef DEBUG @@ -1605,8 +1645,11 @@ scan_file(const char *filename, /* I - Filename */ if (comment->child != comment->last_child) { #ifdef DEBUG - fprintf(stderr, " removing comment %p, last comment %p...\n", - comment->child, comment->last_child); + fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n", + comment->child, + comment->child ? comment->child->value.text.string : "", + comment->last_child, + comment->last_child ? comment->last_child->value.text.string : ""); #endif /* DEBUG */ mxmlDelete(comment->child); #ifdef DEBUG @@ -1756,8 +1799,11 @@ scan_file(const char *filename, /* I - Filename */ if (comment->child != comment->last_child) { #ifdef DEBUG - fprintf(stderr, " removing comment %p, last comment %p...\n", - comment->child, comment->last_child); + fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n", + comment->child, + comment->child ? comment->child->value.text.string : "", + comment->last_child, + comment->last_child ? comment->last_child->value.text.string : ""); #endif /* DEBUG */ mxmlDelete(comment->child); #ifdef DEBUG diff --git a/test/dotest.sh b/test/dotest.sh index 4584f1d..5443ffe 100755 --- a/test/dotest.sh +++ b/test/dotest.sh @@ -14,7 +14,7 @@ while test $# -gt 0; do -v) mode="valgrind" ;; *.h | *.c | *.cxx) files="$files $arg" ;; *) - echo "Usage: ./dotest.sh [-g] [-v] [files]" + echo "Usage: ./dotest.sh [-f] [-g] [-v] [files]" exit 1 ;; esac @@ -28,7 +28,9 @@ rm -f test.xml case "$mode" in gdb) - echo "run $framed test.xml $files >test.html 2>test.log" >.gdbcmds + echo "break malloc_error_break" >.gdbcmds + echo "set env DYLD_INSERT_LIBRARIES /usr/lib/libgmalloc.dylib" >>.gdbcmds + echo "run $framed test.xml $files >test.html 2>test.log" >>.gdbcmds gdb -x .gdbcmds ../mxmldoc-static ;;