diff --git a/CHANGES b/CHANGES index 559f928..661dc09 100644 --- a/CHANGES +++ b/CHANGES @@ -1,9 +1,13 @@ -README - 05/16/2004 +README - 06/01/2004 ------------------- CHANGES IN Mini-XML 2.0 - New programmers manual. + - Added optimizations to mxmldoc, mxmlSaveFile(), and + mxmlIndexNew() (STR #2) + - mxmlEntityAddCallback() now returns an integer status + (STR #2) - Added UTF-16 support (input only; all output is UTF-8) - Added index functions to build a searchable index of XML nodes. diff --git a/doc/reference.html b/doc/reference.html index f39d325..3757cb4 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -191,7 +191,7 @@ mxmlElementSetAttr(

Add a callback to convert entities to Unicode.

Syntax

-void
+int
 mxmlEntityAddCallback(
     int (*cb)(const char *name));
 
@@ -202,7 +202,7 @@ mxmlEntityAddCallback( (*cb)(const char *name)Callback function to add

Returns

-

Nothing.

+

0 on success, -1 on failure

mxmlEntityGetName()


@@ -1215,8 +1215,7 @@ union mxml_value_u

num_callbacks

-
-

Definition

+

Definition

 static int num_callbacks = 1;
 
diff --git a/doc/relnotes.html b/doc/relnotes.html index b28957d..bb35b2c 100644 --- a/doc/relnotes.html +++ b/doc/relnotes.html @@ -9,6 +9,12 @@
  • New programmers manual.
  • +
  • Added optimizations to mxmldoc, mxmlSaveFile(), and + mxmlIndexNew() (STR #2)
  • + +
  • mxmlEntityAddCallback() now returns an integer + status (STR #2)
  • +
  • Added UTF-16 support (input only; all output is UTF-8)
  • diff --git a/mxml-attr.c b/mxml-attr.c index 519f92d..0a50138 100644 --- a/mxml-attr.c +++ b/mxml-attr.c @@ -1,5 +1,5 @@ /* - * "$Id: mxml-attr.c,v 1.8 2004/05/02 16:04:40 mike Exp $" + * "$Id: mxml-attr.c,v 1.9 2004/06/01 20:19:34 mike Exp $" * * Attribute support code for Mini-XML, a small XML-like file parsing library. * @@ -117,10 +117,15 @@ mxmlElementSetAttr(mxml_node_t *node, /* I - Element node */ * Replace the attribute value and return... */ - free(attr->value); + if (attr->value) + free(attr->value); if (value) - attr->value = strdup(value); + { + if ((attr->value = strdup(value)) == NULL) + mxml_error("Unable to allocate memory for attribute '%s' in element %s!", + name, node->value.element.name); + } else attr->value = NULL; @@ -172,5 +177,5 @@ mxmlElementSetAttr(mxml_node_t *node, /* I - Element node */ /* - * End of "$Id: mxml-attr.c,v 1.8 2004/05/02 16:04:40 mike Exp $". + * End of "$Id: mxml-attr.c,v 1.9 2004/06/01 20:19:34 mike Exp $". */ diff --git a/mxml-entity.c b/mxml-entity.c index bfd9657..fe1bb82 100644 --- a/mxml-entity.c +++ b/mxml-entity.c @@ -1,5 +1,5 @@ /* - * "$Id: mxml-entity.c,v 1.4 2004/05/16 05:25:38 mike Exp $" + * "$Id: mxml-entity.c,v 1.5 2004/06/01 20:19:34 mike Exp $" * * Character entity support code for Mini-XML, a small XML-like * file parsing library. @@ -58,7 +58,7 @@ static int (*callbacks[100])(const char *name) = * 'mxmlEntityAddCallback()' - Add a callback to convert entities to Unicode. */ -void +int /* O - 0 on success, -1 on failure */ mxmlEntityAddCallback(int (*cb)(const char *name)) /* I - Callback function to add */ { @@ -66,6 +66,14 @@ mxmlEntityAddCallback(int (*cb)(const char *name)) { callbacks[num_callbacks] = cb; num_callbacks ++; + + return (0); + } + else + { + mxml_error("Unable to add entity callback!"); + + return (-1); } } @@ -451,5 +459,5 @@ default_callback(const char *name) /* I - Entity name */ /* - * End of "$Id: mxml-entity.c,v 1.4 2004/05/16 05:25:38 mike Exp $". + * End of "$Id: mxml-entity.c,v 1.5 2004/06/01 20:19:34 mike Exp $". */ diff --git a/mxml-file.c b/mxml-file.c index 338edcf..279bba2 100644 --- a/mxml-file.c +++ b/mxml-file.c @@ -1,5 +1,5 @@ /* - * "$Id: mxml-file.c,v 1.31 2004/05/16 21:54:47 mike Exp $" + * "$Id: mxml-file.c,v 1.32 2004/06/01 20:19:34 mike Exp $" * * File loading code for Mini-XML, a small XML-like file parsing library. * @@ -601,18 +601,24 @@ static int /* O - 0 on success, -1 on failure */ mxml_file_putc(int ch, /* I - Character to write */ void *p) /* I - Pointer to file */ { + char buffer[4], /* Buffer for character */ + *bufptr; /* Pointer into buffer */ + int buflen; /* Number of bytes to write */ + + if (ch < 128) - return (putc(ch, (FILE *)p)); - else if (ch < 2048) + return (putc(ch, (FILE *)p) == EOF ? -1 : 0); + + bufptr = buffer; + + if (ch < 2048) { /* * Two-byte UTF-8 character... */ - if (putc(0xc0 | (ch >> 6), (FILE *)p) < 0) - return (-1); - else - return (putc(0x80 | (ch & 0x3f), (FILE *)p)); + *bufptr++ = 0xc0 | (ch >> 6); + *bufptr++ = 0x80 | (ch & 0x3f); } else if (ch < 65536) { @@ -620,12 +626,9 @@ mxml_file_putc(int ch, /* I - Character to write */ * Three-byte UTF-8 character... */ - if (putc(0xe0 | (ch >> 12), (FILE *)p) < 0) - return (-1); - else if (putc(0x80 | ((ch >> 6) & 0x3f), (FILE *)p) < 0) - return (-1); - else - return (putc(0x80 | (ch & 0x3f), (FILE *)p)); + *bufptr++ = 0xe0 | (ch >> 12); + *bufptr++ = 0x80 | ((ch >> 6) & 0x3f); + *bufptr++ = 0x80 | (ch & 0x3f); } else { @@ -633,15 +636,15 @@ mxml_file_putc(int ch, /* I - Character to write */ * Four-byte UTF-8 character... */ - if (putc(0xf0 | (ch >> 18), (FILE *)p) < 0) - return (-1); - else if (putc(0x80 | ((ch >> 12) & 0x3f), (FILE *)p) < 0) - return (-1); - else if (putc(0x80 | ((ch >> 6) & 0x3f), (FILE *)p) < 0) - return (-1); - else - return (putc(0x80 | (ch & 0x3f), (FILE *)p)); + *bufptr++ = 0xf0 | (ch >> 18); + *bufptr++ = 0x80 | ((ch >> 12) & 0x3f); + *bufptr++ = 0x80 | ((ch >> 6) & 0x3f); + *bufptr++ = 0x80 | (ch & 0x3f); } + + buflen = bufptr - buffer; + + return (fwrite(buffer, 1, buflen, (FILE *)p) < buflen ? -1 : 0); } @@ -1633,6 +1636,7 @@ mxml_write_node(mxml_node_t *node, /* I - Node to write */ width; /* Width of attr + value */ mxml_attr_t *attr; /* Current attribute */ char s[255]; /* Temporary string */ + int slen; /* Length of temporary string */ while (node != NULL) @@ -1779,11 +1783,11 @@ mxml_write_node(mxml_node_t *node, /* I - Node to write */ col ++; } - sprintf(s, "%d", node->value.integer); + slen = snprintf(s, sizeof(s), "%d", node->value.integer); if (mxml_write_string(s, p, putc_cb) < 0) return (-1); - col += strlen(s); + col += slen; break; case MXML_OPAQUE : @@ -1809,11 +1813,11 @@ mxml_write_node(mxml_node_t *node, /* I - Node to write */ col ++; } - sprintf(s, "%f", node->value.real); + slen = snprintf(s, sizeof(s), "%f", node->value.real); if (mxml_write_string(s, p, putc_cb) < 0) return (-1); - col += strlen(s); + col += slen; break; case MXML_TEXT : @@ -1932,5 +1936,5 @@ mxml_write_ws(mxml_node_t *node, /* I - Current node */ /* - * End of "$Id: mxml-file.c,v 1.31 2004/05/16 21:54:47 mike Exp $". + * End of "$Id: mxml-file.c,v 1.32 2004/06/01 20:19:34 mike Exp $". */ diff --git a/mxml-index.c b/mxml-index.c index 494d73c..086f779 100644 --- a/mxml-index.c +++ b/mxml-index.c @@ -1,5 +1,5 @@ /* - * "$Id: mxml-index.c,v 1.4 2004/05/16 18:25:20 mike Exp $" + * "$Id: mxml-index.c,v 1.5 2004/06/01 20:19:34 mike Exp $" * * Index support code for Mini-XML, a small XML-like file parsing library. * @@ -581,64 +581,69 @@ index_sort(mxml_index_t *ind, /* I - Index to sort */ /* - * Sort the pivot in the current partition... + * Loop until we have sorted all the way to the right... */ - pivot = ind->nodes[left]; - - for (templ = left, tempr = right; templ < tempr;) + do { /* - * Move left while left node <= pivot node... + * Sort the pivot in the current partition... */ - while ((templ < right) && - index_compare(ind, ind->nodes[templ], pivot) <= 0) - templ ++; + pivot = ind->nodes[left]; - /* - * Move right while right node > pivot node... - */ + for (templ = left, tempr = right; templ < tempr;) + { + /* + * Move left while left node <= pivot node... + */ + + while ((templ < right) && + index_compare(ind, ind->nodes[templ], pivot) <= 0) + templ ++; + + /* + * Move right while right node > pivot node... + */ - while ((tempr > left) && - index_compare(ind, ind->nodes[tempr], pivot) > 0) - tempr --; + while ((tempr > left) && + index_compare(ind, ind->nodes[tempr], pivot) > 0) + tempr --; + + /* + * Swap nodes if needed... + */ + + if (templ < tempr) + { + temp = ind->nodes[templ]; + ind->nodes[templ] = ind->nodes[tempr]; + ind->nodes[tempr] = temp; + } + } /* - * Swap nodes if needed... + * When we get here, the right (tempr) node is the new position for the + * pivot node... */ - if (templ < tempr) + if (index_compare(ind, pivot, ind->nodes[tempr]) > 0) { - temp = ind->nodes[templ]; - ind->nodes[templ] = ind->nodes[tempr]; - ind->nodes[tempr] = temp; + ind->nodes[left] = ind->nodes[tempr]; + ind->nodes[tempr] = pivot; } - } - /* - * When we get here, the right (tempr) node is the new position for the - * pivot node... - */ + /* + * Recursively sort the left partition as needed... + */ - if (index_compare(ind, pivot, ind->nodes[tempr]) > 0) - { - ind->nodes[left] = ind->nodes[tempr]; - ind->nodes[tempr] = pivot; + if (left < (tempr - 1)) + index_sort(ind, left, tempr - 1); } - - /* - * Recursively sort the left and right partitions as needed... - */ - - if (left < (tempr - 1)) - index_sort(ind, left, tempr - 1); - - if (right > (tempr + 1)) - index_sort(ind, tempr + 1, right); + while (right > (left = tempr + 1)); } /* - * End of "$Id: mxml-index.c,v 1.4 2004/05/16 18:25:20 mike Exp $". + * End of "$Id: mxml-index.c,v 1.5 2004/06/01 20:19:34 mike Exp $". */ diff --git a/mxml-private.c b/mxml-private.c index c9d01ef..3f793c3 100644 --- a/mxml-private.c +++ b/mxml-private.c @@ -1,5 +1,5 @@ /* - * "$Id: mxml-private.c,v 1.4 2004/05/02 16:04:40 mike Exp $" + * "$Id: mxml-private.c,v 1.5 2004/06/01 20:19:34 mike Exp $" * * Private functions for Mini-XML, a small XML-like file parsing library. * @@ -74,11 +74,7 @@ mxml_error(const char *format, /* I - Printf-style format string */ if (mxml_error_cb) (*mxml_error_cb)(s); else - { - fputs("mxml: ", stderr); - fputs(s, stderr); - putc('\n', stderr); - } + fprintf(stderr, "mxml: %s\n", s); /* * Free the string... @@ -128,5 +124,5 @@ mxml_real_cb(mxml_node_t *node) /* I - Current node */ /* - * End of "$Id: mxml-private.c,v 1.4 2004/05/02 16:04:40 mike Exp $". + * End of "$Id: mxml-private.c,v 1.5 2004/06/01 20:19:34 mike Exp $". */ diff --git a/mxml.h b/mxml.h index 0e7ab27..84163d4 100644 --- a/mxml.h +++ b/mxml.h @@ -1,5 +1,5 @@ /* - * "$Id: mxml.h,v 1.20 2004/05/16 05:25:38 mike Exp $" + * "$Id: mxml.h,v 1.21 2004/06/01 20:19:34 mike Exp $" * * Header file for Mini-XML, a small XML-like file parsing library. * @@ -146,7 +146,7 @@ extern void mxmlDelete(mxml_node_t *node); extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name); extern void mxmlElementSetAttr(mxml_node_t *node, const char *name, const char *value); -extern void mxmlEntityAddCallback(int (*cb)(const char *name)); +extern int mxmlEntityAddCallback(int (*cb)(const char *name)); extern const char *mxmlEntityGetName(int val); extern int mxmlEntityGetValue(const char *name); extern void mxmlEntityRemoveCallback(int (*cb)(const char *name)); @@ -225,5 +225,5 @@ extern mxml_type_t mxml_real_cb(mxml_node_t *node); /* - * End of "$Id: mxml.h,v 1.20 2004/05/16 05:25:38 mike Exp $". + * End of "$Id: mxml.h,v 1.21 2004/06/01 20:19:34 mike Exp $". */ diff --git a/mxml.xml b/mxml.xml index a19c082..8e53752 100644 --- a/mxml.xml +++ b/mxml.xml @@ -75,6 +75,10 @@ not an element. + + int + 0 on success, -1 on failure + Add a callback to convert entities to Unicode. int diff --git a/mxmldoc.c b/mxmldoc.c index 2759509..235ab26 100644 --- a/mxmldoc.c +++ b/mxmldoc.c @@ -1,5 +1,5 @@ /* - * "$Id: mxmldoc.c,v 1.36 2004/05/02 22:02:36 mike Exp $" + * "$Id: mxmldoc.c,v 1.37 2004/06/01 20:19:34 mike Exp $" * * Documentation generator using Mini-XML, a small XML-like file parsing * library. @@ -1779,19 +1779,18 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ */ puts(""); - puts(""); - puts(""); - puts("\tDocumentation"); - puts("\t"); - puts("\t"); - puts(""); - puts(""); - + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" + "\n" + "\n" + "\tDocumentation\n" + "\t\n" + "\t\n" + "\n" + ""); /* * Table of contents... @@ -1821,9 +1820,9 @@ write_documentation(mxml_node_t *doc) /* I - XML documentation */ if (mxmlFindElement(doc, doc, "class", NULL, NULL, MXML_DESCEND_FIRST)) { - puts(""); - puts("

    Classes

    "); - puts("