From 9ccd55b01720862b096560378e0487528597b95f Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 29 Apr 2004 20:48:52 +0000 Subject: [PATCH] Start fixing class handling. --- mxmldoc.c | 99 ++++++++++++++++++++++++++++++++++++++++++++---- testfile.cxx | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 194 insertions(+), 10 deletions(-) diff --git a/mxmldoc.c b/mxmldoc.c index aafe657..c43627b 100644 --- a/mxmldoc.c +++ b/mxmldoc.c @@ -1,5 +1,6 @@ +/*#define DEBUG 2*/ /* - * "$Id: mxmldoc.c,v 1.26 2004/04/06 01:47:20 mike Exp $" + * "$Id: mxmldoc.c,v 1.27 2004/04/29 20:48:52 mike Exp $" * * Documentation generator using mini-XML, a small XML-like file parsing * library. @@ -172,9 +173,10 @@ main(int argc, /* I - Number of command-line args */ if (!doc) { - fprintf(stderr, "Unable to read the XML documentation file \"%s\"!\n", + fprintf(stderr, "mxmldoc: Unable to read the XML documentation file \"%s\"!\n", argv[1]); - return (1); + doc = mxmlNewElement(NULL, "?xml"); + mxmlElementSetAttr(doc, "version", "1.0"); } } else @@ -374,6 +376,11 @@ scan_file(const char *filename, /* I - Filename */ #endif /* DEBUG > 1 */ +#ifdef DEBUG + fprintf(stderr, "scan_file(filename=\"%s\", fp=%p, tree=%p)\n", filename, + fp, tree); +#endif // DEBUG + /* * Initialize the finite state machine... */ @@ -967,6 +974,7 @@ scan_file(const char *filename, /* I - Filename */ case STATE_CXX_COMMENT : /* Inside a C++ comment */ if (ch == '\n') { + state = STATE_NONE; *bufptr = '\0'; if (comment->child != comment->last_child) @@ -1487,7 +1495,8 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ *arg, /* Current argument */ *description, /* Description of function/var */ *type; /* Type for argument */ - const char *name; /* Name of function/type */ + const char *name, /* Name of function/type */ + *cname; /* Class name */ char prefix; /* Prefix character */ @@ -1559,9 +1568,9 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ scut = mxmlFindElement(scut, doc, "class", 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, @@ -1577,7 +1586,7 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ puts("

Definition

"); puts("
");
 
-      printf("struct %s\n{\n", name);
+      printf("class %s\n{\n", name);
       for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL,
                         	 MXML_DESCEND_FIRST);
 	   arg;
@@ -1590,6 +1599,50 @@ write_documentation(mxml_node_t *doc)	/* I - XML documentation */
 	printf(" %s;\n", mxmlElementGetAttr(arg, "name"));
       }
 
+      for (function = mxmlFindElement(scut, scut, "function", NULL, NULL,
+                                      MXML_DESCEND_FIRST);
+	   function;
+	   function = mxmlFindElement(function, scut, "function", NULL, NULL,
+                                      MXML_NO_DESCEND))
+      {
+        name = mxmlElementGetAttr(function, "name");
+
+        printf("  ");
+
+	arg = mxmlFindElement(function, function, "returnvalue", NULL,
+                              NULL, MXML_DESCEND_FIRST);
+
+	if (arg)
+	{
+	  if (arg->child->value.text.string)
+	    write_element(doc, mxmlFindElement(arg, arg, "type", NULL,
+                                               NULL, MXML_DESCEND_FIRST));
+	}
+	else
+	  fputs("void ", stdout);
+
+	printf("%s", cname, name, name);
+
+	for (arg = mxmlFindElement(function, function, "argument", NULL, NULL,
+                        	   MXML_DESCEND_FIRST), prefix = '(';
+	     arg;
+	     arg = mxmlFindElement(arg, function, "argument", NULL, NULL,
+                        	   MXML_NO_DESCEND), prefix = ',')
+	{
+	  type = mxmlFindElement(arg, arg, "type", NULL, NULL,
+	                	 MXML_DESCEND_FIRST);
+
+	  printf("%c", prefix);
+	  write_element(doc, type);
+	  printf("%s%s", type->child ? " " : "", mxmlElementGetAttr(arg, "name"));
+	}
+
+	if (prefix == '(')
+	  puts("(void);");
+	else
+	  puts(");");
+      }
+
       puts("};\n
"); puts("

Members

"); @@ -1613,7 +1666,37 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ puts(""); } + for (function = mxmlFindElement(scut, scut, "function", NULL, NULL, + MXML_DESCEND_FIRST); + function; + function = mxmlFindElement(function, scut, "function", NULL, NULL, + MXML_NO_DESCEND)) + { + name = mxmlElementGetAttr(function, "name"); + + printf("%s()", + cname, name, name); + + description = mxmlFindElement(function, function, "description", NULL, + NULL, MXML_DESCEND_FIRST); + if (description) + write_element(NULL, description); + + arg = mxmlFindElement(function, function, "returnvalue", NULL, + NULL, MXML_DESCEND_FIRST); + + if (arg) + { + fputs("\nReturns: ", stdout); + write_element(NULL, mxmlFindElement(arg, arg, "description", NULL, + NULL, MXML_DESCEND_FIRST)); + } + + puts(""); + } + puts("

"); + } } @@ -2222,5 +2305,5 @@ ws_cb(mxml_node_t *node, /* I - Element node */ /* - * End of "$Id: mxmldoc.c,v 1.26 2004/04/06 01:47:20 mike Exp $". + * End of "$Id: mxmldoc.c,v 1.27 2004/04/29 20:48:52 mike Exp $". */ diff --git a/testfile.cxx b/testfile.cxx index 27ba0fd..feaf4fc 100644 --- a/testfile.cxx +++ b/testfile.cxx @@ -1,5 +1,5 @@ // -// "$Id: testfile.cxx,v 1.1 2004/04/29 12:38:39 mike Exp $" +// "$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. // @@ -65,6 +65,107 @@ foo_float_function(int one, /* I - Integer */ } +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.1 2004/04/29 12:38:39 mike Exp $". +// End of "$Id: testfile.cxx,v 1.2 2004/04/29 20:48:52 mike Exp $". //