From c00d7f55a2e9a5bd53cacdfc09cbdfb5a4ec91bf Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sat, 1 May 2004 04:30:43 +0000 Subject: [PATCH] Fix C++ class/struct handling. Move and separate test files for mxmldoc. --- CHANGES | 4 +- dotest.sh | 5 -- mxmldoc.c | 57 ++++++++-------- test/class.cxx | 50 ++++++++++++++ test/dotest.sh | 12 ++++ test/enum.cxx | 7 ++ test/function.cxx | 37 ++++++++++ test/struct.cxx | 48 +++++++++++++ testfile.cxx | 171 ---------------------------------------------- 9 files changed, 187 insertions(+), 204 deletions(-) delete mode 100644 dotest.sh create mode 100644 test/class.cxx create mode 100755 test/dotest.sh create mode 100644 test/enum.cxx create mode 100644 test/function.cxx create mode 100644 test/struct.cxx delete mode 100644 testfile.cxx diff --git a/CHANGES b/CHANGES index 88ec833..9ee9d07 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -README - 04/29/2004 +README - 04/30/2004 ------------------- CHANGES IN Mini-XML 2.0 @@ -9,6 +9,8 @@ CHANGES IN Mini-XML 2.0 between the destination path and install path. This caused problems when building and installing with MingW. + - The mxmldoc utility is now capable of documenting C++ + structures and classes. CHANGES IN Mini-XML 1.3 diff --git a/dotest.sh b/dotest.sh deleted file mode 100644 index c9d9cd7..0000000 --- a/dotest.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -rm -f testfile.xml -valgrind --logfile-fd=3 --leak-check=yes ./mxmldoc testfile.xml testfile.cxx >testfile.html 2>testfile.log 3>testfile.valgrind - diff --git a/mxmldoc.c b/mxmldoc.c index 4e3fc68..6552ecc 100644 --- a/mxmldoc.c +++ b/mxmldoc.c @@ -1,6 +1,5 @@ -#define DEBUG 2 /* - * "$Id: mxmldoc.c,v 1.29 2004/04/30 03:40:05 mike Exp $" + * "$Id: mxmldoc.c,v 1.30 2004/05/01 04:30:42 mike Exp $" * * Documentation generator using mini-XML, a small XML-like file parsing * library. @@ -386,21 +385,22 @@ scan_file(const char *filename, /* I - Filename */ * Initialize the finite state machine... */ - state = STATE_NONE; - braces = 0; - parens = 0; - bufptr = buffer; - - comment = mxmlNewElement(MXML_NO_PARENT, "temp"); - constant = NULL; - enumeration = NULL; - function = NULL; - variable = NULL; - returnvalue = NULL; - type = NULL; - description = NULL; - typedefnode = NULL; - structclass = NULL; + state = STATE_NONE; + braces = 0; + parens = 0; + bufptr = buffer; + + comment = mxmlNewElement(MXML_NO_PARENT, "temp"); + constant = NULL; + enumeration = NULL; + function = NULL; + variable = NULL; + returnvalue = NULL; + type = NULL; + description = NULL; + typedefnode = NULL; + structclass = NULL; + fstructclass = NULL; /* * Read until end-of-file... @@ -474,6 +474,8 @@ scan_file(const char *filename, /* I - Filename */ } else sort_node(tree, function); + + function = NULL; } else if (type && type->child && ((!strcmp(type->child->value.text.string, "typedef") && @@ -713,6 +715,7 @@ scan_file(const char *filename, /* I - Filename */ { mxmlDelete(function); function = NULL; + variable = NULL; } if (type) @@ -1645,9 +1648,9 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ if (arg) { - if (arg->child->value.text.string) - write_element(doc, mxmlFindElement(arg, arg, "type", NULL, - NULL, MXML_DESCEND_FIRST)); + write_element(doc, mxmlFindElement(arg, arg, "type", NULL, + NULL, MXML_DESCEND_FIRST)); + putchar(' '); } else if (strcmp(cname, name) && strcmp(cname, name + 1)) fputs("void ", stdout); @@ -1947,9 +1950,9 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ scut = mxmlFindElement(scut, doc, "struct", NULL, NULL, MXML_NO_DESCEND)) { - name = mxmlElementGetAttr(scut, "name"); + cname = mxmlElementGetAttr(scut, "name"); puts(""); - printf("

%s

\n", name, name); + printf("

%s

\n", cname, cname); puts("
"); description = mxmlFindElement(scut, scut, "description", NULL, @@ -1965,7 +1968,7 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ puts("

Definition

"); puts("
");
 
-      printf("struct %s\n{\n", name);
+      printf("struct %s\n{\n", cname);
       for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL,
                         	 MXML_DESCEND_FIRST);
 	   arg;
@@ -1993,9 +1996,9 @@ write_documentation(mxml_node_t *doc)	/* I - XML documentation */
 
 	if (arg)
 	{
-	  if (arg->child->value.text.string)
-	    write_element(doc, mxmlFindElement(arg, arg, "type", NULL,
-                                               NULL, MXML_DESCEND_FIRST));
+	  write_element(doc, mxmlFindElement(arg, arg, "type", NULL,
+                                             NULL, MXML_DESCEND_FIRST));
+	  putchar(' ');
 	}
 	else if (strcmp(cname, name) && strcmp(cname, name + 1))
 	  fputs("void ", stdout);
@@ -2409,5 +2412,5 @@ ws_cb(mxml_node_t *node,		/* I - Element node */
 
 
 /*
- * End of "$Id: mxmldoc.c,v 1.29 2004/04/30 03:40:05 mike Exp $".
+ * End of "$Id: mxmldoc.c,v 1.30 2004/05/01 04:30:42 mike Exp $".
  */
diff --git a/test/class.cxx b/test/class.cxx
new file mode 100644
index 0000000..e245cf9
--- /dev/null
+++ b/test/class.cxx
@@ -0,0 +1,50 @@
+class foo_c			// Foo class
+{
+  float	foo;				/* Real number */
+  int	bar;				/* Integer */
+
+  public:
+
+  foo_c(float f, int b);
+  ~foo_c();
+
+  // 'get_bar()' - Get the value of bar.
+  int // O - Value of bar
+  get_bar()
+  {
+    return (bar);
+  }
+
+  // 'get_foo()' - Get the value of foo.
+  float // O - Value of foo
+  get_foo()
+  {
+    return (foo);
+  }
+
+  // 'set_bar()' - Set the value of bar.
+  void
+  set_bar(int b) // I - Value of bar
+  {
+    bar = b;
+  }
+
+  // 'set_foo()' - Set the value of foo.
+  void
+  set_foo(float f) // I - Value of foo
+  {
+    foo = f;
+  }
+}
+
+// 'foo_c::foo_c()' - Create a foo_c class.
+foo_c::foo_c(float f, int b)
+{
+  foo = f;
+  bar = b;
+}
+
+// 'foo_c::~foo_c()' - Destroy a foo_c class.
+foo_c::~foo_c()
+{
+}
diff --git a/test/dotest.sh b/test/dotest.sh
new file mode 100755
index 0000000..2d94b15
--- /dev/null
+++ b/test/dotest.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+if test $# -gt 0; then
+	files=$*
+else
+	files=*.cxx
+fi
+
+rm -f test.xml
+valgrind --logfile-fd=3 --leak-check=yes ../mxmldoc test.xml \
+	$files >test.html 2>test.log 3>test.valgrind
+
diff --git a/test/enum.cxx b/test/enum.cxx
new file mode 100644
index 0000000..ce80148
--- /dev/null
+++ b/test/enum.cxx
@@ -0,0 +1,7 @@
+typedef enum foo_enum_e			/* Sample enumeration type */
+{
+  FOO_ONE,				/* One fish */
+  FOO_TWO,				/* Two fish */
+  FOO_RED,				/* Red fish */
+  FOO_BLUE				/* Blue fish */
+} foo_enum_t;
diff --git a/test/function.cxx b/test/function.cxx
new file mode 100644
index 0000000..3f13fd4
--- /dev/null
+++ b/test/function.cxx
@@ -0,0 +1,37 @@
+/*
+ * 'foo_void_function()' - Do foo with bar.
+ */
+
+void
+foo_void_function(int        one,	/* I - Integer */
+                  float      *two,	/* O - Real number */
+                  const char *three)	/* I - String */
+{
+  if (one)
+  {
+    puts("Hello, World!");
+  }
+  else
+    puts(three);
+
+  *two = 2.0f;
+}
+
+
+/*
+ * 'foo_float_function()' - Do foo with bar.
+ */
+
+float					/* O - Real number */
+foo_float_function(int        one,	/* I - Integer */
+                   const char *two)	/* I - String */
+{
+  if (one)
+  {
+    puts("Hello, World!");
+  }
+  else
+    puts(two);
+
+  return (2.0f);
+}
diff --git a/test/struct.cxx b/test/struct.cxx
new file mode 100644
index 0000000..f325d00
--- /dev/null
+++ b/test/struct.cxx
@@ -0,0 +1,48 @@
+typedef struct foo_s			/* Foo structure */
+{
+  float	foo;				/* Real number */
+  int	bar;				/* Integer */
+
+  foo_s(float f, int b);
+  ~foo_s();
+
+  // 'get_bar()' - Get the value of bar.
+  int // O - Value of bar
+  get_bar()
+  {
+    return (bar);
+  }
+
+  // 'get_foo()' - Get the value of foo.
+  float // O - Value of foo
+  get_foo()
+  {
+    return (foo);
+  }
+
+  // 'set_bar()' - Set the value of bar.
+  void
+  set_bar(int b) // I - Value of bar
+  {
+    bar = b;
+  }
+
+  // 'set_foo()' - Set the value of foo.
+  void
+  set_foo(float f) // I - Value of foo
+  {
+    foo = f;
+  }
+} foo_t;
+
+// 'foo_s::foo_s()' - Create a foo_s structure.
+foo_s::foo_s(float f, int b)
+{
+  foo = f;
+  bar = b;
+}
+
+// 'foo_s::~foo_s()' - Destroy a foo_s structure.
+foo_s::~foo_s()
+{
+}
diff --git a/testfile.cxx b/testfile.cxx
deleted file mode 100644
index feaf4fc..0000000
--- a/testfile.cxx
+++ /dev/null
@@ -1,171 +0,0 @@
-//
-// "$Id: testfile.cxx,v 1.2 2004/04/29 20:48:52 mike Exp $"
-//
-// Mxmldoc test file for mini-XML, a small XML-like file parsing library.
-//
-// Copyright 2003-2004 by Michael Sweet.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-
-
-typedef enum foo_enum_e			/* Sample enumeration type */
-{
-  FOO_ONE,				/* One fish */
-  FOO_TWO,				/* Two fish */
-  FOO_RED,				/* Red fish */
-  FOO_BLUE				/* Blue fish */
-} foo_enum_t;
-
-
-/*
- * 'foo_void_function()' - Do foo with bar.
- */
-
-void
-foo_void_function(int        one,	/* I - Integer */
-                  float      *two,	/* O - Real number */
-                  const char *three)	/* I - String */
-{
-  if (one)
-  {
-    puts("Hello, World!");
-  }
-  else
-    puts(three);
-
-  *two = 2.0f;
-}
-
-
-/*
- * 'foo_float_function()' - Do foo with bar.
- */
-
-float					/* O - Real number */
-foo_float_function(int        one,	/* I - Integer */
-                   const char *two)	/* I - String */
-{
-  if (one)
-  {
-    puts("Hello, World!");
-  }
-  else
-    puts(two);
-
-  return (2.0f);
-}
-
-
-typedef struct foo_s			/* Foo structure */
-{
-  float	foo;				/* Real number */
-  int	bar;				/* Integer */
-
-  foo_s(float f, int b);
-  ~foo_s();
-
-  // 'get_bar()' - Get the value of bar.
-  int // O - Value of bar
-  get_bar()
-  {
-    return (bar);
-  }
-
-  // 'get_foo()' - Get the value of foo.
-  float // O - Value of foo
-  get_foo()
-  {
-    return (foo);
-  }
-
-  // 'set_bar()' - Set the value of bar.
-  void
-  set_bar(int b) // I - Value of bar
-  {
-    bar = b;
-  }
-
-  // 'set_foo()' - Set the value of foo.
-  void
-  set_foo(float f) // I - Value of foo
-  {
-    foo = f;
-  }
-} foo_t;
-
-// 'foo_s::foo_s()' - Create a foo_s structure.
-foo_s::foo_s(float f, int b)
-{
-  foo = f;
-  bar = b;
-}
-
-// 'foo_s::~foo_s()' - Destroy a foo_s structure.
-foo_s::~foo_s()
-{
-}
-
-
-class foo_c			// Foo class
-{
-  float	foo;				/* Real number */
-  int	bar;				/* Integer */
-
-  public:
-
-  foo_c(float f, int b);
-  ~foo_c();
-
-  // 'get_bar()' - Get the value of bar.
-  int // O - Value of bar
-  get_bar()
-  {
-    return (bar);
-  }
-
-  // 'get_foo()' - Get the value of foo.
-  float // O - Value of foo
-  get_foo()
-  {
-    return (foo);
-  }
-
-  // 'set_bar()' - Set the value of bar.
-  void
-  set_bar(int b) // I - Value of bar
-  {
-    bar = b;
-  }
-
-  // 'set_foo()' - Set the value of foo.
-  void
-  set_foo(float f) // I - Value of foo
-  {
-    foo = f;
-  }
-}
-
-// 'foo_c::foo_c()' - Create a foo_c class.
-foo_c::foo_c(float f, int b)
-{
-  foo = f;
-  bar = b;
-}
-
-// 'foo_c::~foo_c()' - Destroy a foo_c class.
-foo_c::~foo_c()
-{
-}
-
-//
-// End of "$Id: testfile.cxx,v 1.2 2004/04/29 20:48:52 mike Exp $".
-//