From 1d1c545e64419ea39c7dd77c17231ee4d6d50891 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 4 Jun 2003 23:20:31 +0000 Subject: [PATCH] Fix whitespace handling. Partially working mxmldoc! --- mxml-file.c | 12 ++++++------ mxmldoc.c | 54 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/mxml-file.c b/mxml-file.c index 108d309..e99f516 100644 --- a/mxml-file.c +++ b/mxml-file.c @@ -1,5 +1,5 @@ /* - * "$Id: mxml-file.c,v 1.8 2003/06/04 21:18:59 mike Exp $" + * "$Id: mxml-file.c,v 1.9 2003/06/04 23:20:31 mike Exp $" * * File loading code for mini-XML, a small XML-like file parsing library. * @@ -280,7 +280,7 @@ mxmlLoadFile(mxml_node_t *top, /* I - Top node */ parent = node; - if (cb) + if (cb && parent) type = (*cb)(parent); } else if (buffer[0] == '/') @@ -313,7 +313,7 @@ mxmlLoadFile(mxml_node_t *top, /* I - Top node */ parent = parent->parent; - if (cb) + if (cb && parent) type = (*cb)(parent); } else @@ -360,7 +360,7 @@ mxmlLoadFile(mxml_node_t *top, /* I - Top node */ parent = node; - if (cb) + if (cb && parent) type = (*cb)(parent); } } @@ -979,7 +979,7 @@ mxml_write_ws(mxml_node_t *node, /* I - Current node */ int ch; /* Whitespace character */ - if (cb && (ch = (*cb)(node, MXML_WS_BEFORE_OPEN)) != 0) + if (cb && (ch = (*cb)(node, ws)) != 0) { if (putc(ch, fp) < 0) return (-1); @@ -999,5 +999,5 @@ mxml_write_ws(mxml_node_t *node, /* I - Current node */ /* - * End of "$Id: mxml-file.c,v 1.8 2003/06/04 21:18:59 mike Exp $". + * End of "$Id: mxml-file.c,v 1.9 2003/06/04 23:20:31 mike Exp $". */ diff --git a/mxmldoc.c b/mxmldoc.c index b75946a..4c3afc2 100644 --- a/mxmldoc.c +++ b/mxmldoc.c @@ -1,5 +1,5 @@ /* - * "$Id: mxmldoc.c,v 1.4 2003/06/04 21:19:00 mike Exp $" + * "$Id: mxmldoc.c,v 1.5 2003/06/04 23:20:31 mike Exp $" * * Documentation generator using mini-XML, a small XML-like file parsing * library. @@ -18,7 +18,6 @@ * * Contents: * - * main() - Main entry for documentation generator. */ /* @@ -97,6 +96,7 @@ static int scan_file(const char *filename, FILE *fp, mxml_node_t *doc); static void sort_node(mxml_node_t *tree, mxml_node_t *func); +static int ws_cb(mxml_node_t *node, int where); /* @@ -149,9 +149,8 @@ main(int argc, /* I - Number of command-line args */ * Create an empty XML documentation file... */ - doc = mxmlNewElement(NULL, "namespace"); - - mxmlElementSetAttr(doc, "name", "std"); + doc = mxmlNewElement(NULL, "?xml"); + mxmlElementSetAttr(doc, "version", "1.0"); } /* @@ -185,7 +184,7 @@ main(int argc, /* I - Number of command-line args */ * Write over the existing XML file... */ - if (mxmlSaveFile(doc, fp, MXML_NO_CALLBACK)) + if (mxmlSaveFile(doc, fp, ws_cb)) { fprintf(stderr, "Unable to write the XML documentation file \"%s\": %s!\n", argv[1], strerror(errno)); @@ -318,6 +317,8 @@ scan_file(const char *filename, /* I - Filename */ case '{' : braces ++; + function = NULL; + variable = NULL; break; case '}' : @@ -394,7 +395,8 @@ scan_file(const char *filename, /* I - Filename */ else ungetc(ch, fp); } - else if (ch == '\n' && bufptr < (buffer + sizeof(buffer) - 1)) + else if (ch == '\n' && bufptr > buffer && + bufptr < (buffer + sizeof(buffer) - 1)) *bufptr++ = ch; else if (!isspace(ch)) break; @@ -617,5 +619,41 @@ sort_node(mxml_node_t *tree, /* I - Tree to sort into */ /* - * End of "$Id: mxmldoc.c,v 1.4 2003/06/04 21:19:00 mike Exp $". + * 'ws_cb()' - Whitespace callback for saving. + */ + +static int /* O - Whitespace char or 0 for none */ +ws_cb(mxml_node_t *node, /* I - Element node */ + int where) /* I - Where value */ +{ + const char *name; /* Name of element */ + + + name = node->value.element.name; + + if (!strcmp(name, "namespace") || !strcmp(name, "enumeration") || + !strcmp(name, "typedef") || !strcmp(name, "function") || + !strcmp(name, "variable") || !strcmp(name, "struct") || + !strcmp(name, "class")) + { + if (where < MXML_WS_AFTER_OPEN) + return ('\n'); + } + else if (!strcmp(name, "constant") || !strcmp(name, "argument") || + !strcmp(name, "returnvalue")) + { + if (where <= MXML_WS_AFTER_OPEN) + return ('\n'); + } + else if (where == MXML_WS_AFTER_CLOSE) + return ('\n'); + else if (where == MXML_WS_BEFORE_OPEN && strcmp(name, "?xml")) + return ('\t'); + + return (0); +} + + +/* + * End of "$Id: mxmldoc.c,v 1.5 2003/06/04 23:20:31 mike Exp $". */