Commit 8fb28892 authored by Armando I. Rivera's avatar Armando I. Rivera

Switched MXML module from dynamically linked to statically linked

parent 6be12e93
/* config.h. Generated from config.h.in by configure. */
/*
* Configuration file for Mini-XML, a small XML file parsing library.
*
* Copyright 2003-2017 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
* law. Distribution and use rights are outlined in the file "COPYING"
* which should have been included with this file. If this file is
* missing or damaged, see the license at:
*
* https://michaelrsweet.github.io/mxml
*/
/*
* Include necessary headers...
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
/*
* Version number...
*/
#define MXML_VERSION "Mini-XML v2.12"
/*
* Inline function support...
*/
#define inline
/*
* Long long support...
*/
#define HAVE_LONG_LONG 1
/*
* Do we have <zlib.h>?
*/
#define HAVE_ZLIB_H 1
/*
* Do we have the *printf() functions?
*/
#define HAVE_SNPRINTF 1
#define HAVE_VASPRINTF 1
#define HAVE_VSNPRINTF 1
/*
* Do we have the strXXX() functions?
*/
#define HAVE_STRDUP 1
/* #undef HAVE_STRLCAT */
/* #undef HAVE_STRLCPY */
/*
* Do we have threading support?
*/
#define HAVE_PTHREAD_H 1
/*
* Define prototypes for string functions as needed...
*/
# ifndef HAVE_STRDUP
extern char *_mxml_strdup(const char *);
# define strdup _mxml_strdup
# endif /* !HAVE_STRDUP */
# ifndef HAVE_STRLCAT
extern size_t _mxml_strlcat(char *, const char *, size_t);
# define strlcat _mxml_strlcat
# endif /* !HAVE_STRLCAT */
# ifndef HAVE_STRLCPY
extern size_t _mxml_strlcpy(char *, const char *, size_t);
# define strlcpy _mxml_strlcpy
# endif /* !HAVE_STRLCPY */
extern char *_mxml_strdupf(const char *, ...);
extern char *_mxml_vstrdupf(const char *, va_list);
# ifndef HAVE_SNPRINTF
extern int _mxml_snprintf(char *, size_t, const char *, ...);
# define snprintf _mxml_snprintf
# endif /* !HAVE_SNPRINTF */
# ifndef HAVE_VSNPRINTF
extern int _mxml_vsnprintf(char *, size_t, const char *, va_list);
# define vsnprintf _mxml_vsnprintf
# endif /* !HAVE_VSNPRINTF */
......@@ -30,8 +30,8 @@ GNU Library General Public License (LGPL) with the following exceptions:
This is the interface.c file for the ScriptBasic module xml
DWLIBS:-lmxml
UXLIBS:-lmxml
DWLIBS:
UXLIBS:
*/
......@@ -49,7 +49,7 @@ declare sub ::NewDoc alias "NewDoc" lib "mxml"
declare sub ::FreeDoc alias "FreeDoc" lib "mxml"
*/
#include "mxml_src/mxml.h"
#include "mxml.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......
/*
* Attribute support code for Mini-XML, a small XML file parsing library.
*
* Copyright 2003-2017 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
* law. Distribution and use rights are outlined in the file "COPYING"
* which should have been included with this file. If this file is
* missing or damaged, see the license at:
*
* https://michaelrsweet.github.io/mxml
*/
/*
* Include necessary headers...
*/
#include "config.h"
#include "mxml.h"
/*
* Local functions...
*/
static int mxml_set_attr(mxml_node_t *node, const char *name,
char *value);
/*
* 'mxmlElementDeleteAttr()' - Delete an attribute.
*
* @since Mini-XML 2.4@
*/
void
mxmlElementDeleteAttr(mxml_node_t *node,/* I - Element */
const char *name)/* I - Attribute name */
{
int i; /* Looping var */
mxml_attr_t *attr; /* Cirrent attribute */
#ifdef DEBUG
fprintf(stderr, "mxmlElementDeleteAttr(node=%p, name=\"%s\")\n",
node, name ? name : "(null)");
#endif /* DEBUG */
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT || !name)
return;
/*
* Look for the attribute...
*/
for (i = node->value.element.num_attrs, attr = node->value.element.attrs;
i > 0;
i --, attr ++)
{
#ifdef DEBUG
printf(" %s=\"%s\"\n", attr->name, attr->value);
#endif /* DEBUG */
if (!strcmp(attr->name, name))
{
/*
* Delete this attribute...
*/
free(attr->name);
free(attr->value);
i --;
if (i > 0)
memmove(attr, attr + 1, i * sizeof(mxml_attr_t));
node->value.element.num_attrs --;
if (node->value.element.num_attrs == 0)
free(node->value.element.attrs);
return;
}
}
}
/*
* 'mxmlElementGetAttr()' - Get an attribute.
*
* This function returns @code NULL@ if the node is not an element or the
* named attribute does not exist.
*/
const char * /* O - Attribute value or @code NULL@ */
mxmlElementGetAttr(mxml_node_t *node, /* I - Element node */
const char *name) /* I - Name of attribute */
{
int i; /* Looping var */
mxml_attr_t *attr; /* Cirrent attribute */
#ifdef DEBUG
fprintf(stderr, "mxmlElementGetAttr(node=%p, name=\"%s\")\n",
node, name ? name : "(null)");
#endif /* DEBUG */
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT || !name)
return (NULL);
/*
* Look for the attribute...
*/
for (i = node->value.element.num_attrs, attr = node->value.element.attrs;
i > 0;
i --, attr ++)
{
#ifdef DEBUG
printf(" %s=\"%s\"\n", attr->name, attr->value);
#endif /* DEBUG */
if (!strcmp(attr->name, name))
{
#ifdef DEBUG
printf(" Returning \"%s\"!\n", attr->value);
#endif /* DEBUG */
return (attr->value);
}
}
/*
* Didn't find attribute, so return NULL...
*/
#ifdef DEBUG
puts(" Returning NULL!\n");
#endif /* DEBUG */
return (NULL);
}
/*
* 'mxmlElementGetAttrByIndex()' - Get an element attribute by index.
*
* The index ("idx") is 0-based. @code NULL@ is returned if the specified index
* is out of range.
*
* @since Mini-XML 2.11@
*/
const char * /* O - Attribute value */
mxmlElementGetAttrByIndex(
mxml_node_t *node, /* I - Node */
int idx, /* I - Attribute index, starting at 0 */
const char **name) /* O - Attribute name */
{
if (!node || node->type != MXML_ELEMENT || idx < 0 || idx >= node->value.element.num_attrs)
return (NULL);
if (name)
*name = node->value.element.attrs[idx].name;
return (node->value.element.attrs[idx].value);
}
/*
* 'mxmlElementGetAttrCount()' - Get the number of element attributes.
*
* @since Mini-XML 2.11@
*/
int /* O - Number of attributes */
mxmlElementGetAttrCount(
mxml_node_t *node) /* I - Node */
{
if (node && node->type == MXML_ELEMENT)
return (node->value.element.num_attrs);
else
return (0);
}
/*
* 'mxmlElementSetAttr()' - Set an attribute.
*
* If the named attribute already exists, the value of the attribute
* is replaced by the new string value. The string value is copied
* into the element node. This function does nothing if the node is
* not an element.
*/
void
mxmlElementSetAttr(mxml_node_t *node, /* I - Element node */
const char *name, /* I - Name of attribute */
const char *value) /* I - Attribute value */
{
char *valuec; /* Copy of value */
#ifdef DEBUG
fprintf(stderr, "mxmlElementSetAttr(node=%p, name=\"%s\", value=\"%s\")\n",
node, name ? name : "(null)", value ? value : "(null)");
#endif /* DEBUG */
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT || !name)
return;
if (value)
valuec = strdup(value);
else
valuec = NULL;
if (mxml_set_attr(node, name, valuec))
free(valuec);
}
/*
* 'mxmlElementSetAttrf()' - Set an attribute with a formatted value.
*
* If the named attribute already exists, the value of the attribute
* is replaced by the new formatted string. The formatted string value is
* copied into the element node. This function does nothing if the node
* is not an element.
*
* @since Mini-XML 2.3@
*/
void
mxmlElementSetAttrf(mxml_node_t *node, /* I - Element node */
const char *name, /* I - Name of attribute */
const char *format,/* I - Printf-style attribute value */
...) /* I - Additional arguments as needed */
{
va_list ap; /* Argument pointer */
char *value; /* Value */
#ifdef DEBUG
fprintf(stderr,
"mxmlElementSetAttrf(node=%p, name=\"%s\", format=\"%s\", ...)\n",
node, name ? name : "(null)", format ? format : "(null)");
#endif /* DEBUG */
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT || !name || !format)
return;
/*
* Format the value...
*/
va_start(ap, format);
value = _mxml_vstrdupf(format, ap);
va_end(ap);
if (!value)
mxml_error("Unable to allocate memory for attribute '%s' in element %s!",
name, node->value.element.name);
else if (mxml_set_attr(node, name, value))
free(value);
}
/*
* 'mxml_set_attr()' - Set or add an attribute name/value pair.
*/
static int /* O - 0 on success, -1 on failure */
mxml_set_attr(mxml_node_t *node, /* I - Element node */
const char *name, /* I - Attribute name */
char *value) /* I - Attribute value */
{
int i; /* Looping var */
mxml_attr_t *attr; /* New attribute */
/*
* Look for the attribute...
*/
for (i = node->value.element.num_attrs, attr = node->value.element.attrs;
i > 0;
i --, attr ++)
if (!strcmp(attr->name, name))
{
/*
* Free the old value as needed...
*/
if (attr->value)
free(attr->value);
attr->value = value;
return (0);
}
/*
* Add a new attribute...
*/
if (node->value.element.num_attrs == 0)
attr = malloc(sizeof(mxml_attr_t));
else
attr = realloc(node->value.element.attrs,
(node->value.element.num_attrs + 1) * sizeof(mxml_attr_t));
if (!attr)
{
mxml_error("Unable to allocate memory for attribute '%s' in element %s!",
name, node->value.element.name);
return (-1);
}
node->value.element.attrs = attr;
attr += node->value.element.num_attrs;
if ((attr->name = strdup(name)) == NULL)
{
mxml_error("Unable to allocate memory for attribute '%s' in element %s!",
name, node->value.element.name);
return (-1);
}
attr->value = value;
node->value.element.num_attrs ++;
return (0);
}
This diff is collapsed.
This diff is collapsed.
/*
* Node get functions for Mini-XML, a small XML file parsing library.
*
* Copyright 2014-2018 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
* law. Distribution and use rights are outlined in the file "COPYING"
* which should have been included with this file. If this file is
* missing or damaged, see the license at:
*
* https://michaelrsweet.github.io/mxml
*/
/*
* Include necessary headers...
*/
#include "config.h"
#include "mxml.h"
/*
* 'mxmlGetCDATA()' - Get the value for a CDATA node.
*
* @code NULL@ is returned if the node is not a CDATA element.
*
* @since Mini-XML 2.7@
*/
const char * /* O - CDATA value or @code NULL@ */
mxmlGetCDATA(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT ||
strncmp(node->value.element.name, "![CDATA[", 8))
return (NULL);
/*
* Return the text following the CDATA declaration...
*/
return (node->value.element.name + 8);
}
/*
* 'mxmlGetCustom()' - Get the value for a custom node.
*
* @code NULL@ is returned if the node (or its first child) is not a custom
* value node.
*
* @since Mini-XML 2.7@
*/
const void * /* O - Custom value or @code NULL@ */
mxmlGetCustom(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the integer value...
*/
if (node->type == MXML_CUSTOM)
return (node->value.custom.data);
else if (node->type == MXML_ELEMENT &&
node->child &&
node->child->type == MXML_CUSTOM)
return (node->child->value.custom.data);
else
return (NULL);
}
/*
* 'mxmlGetElement()' - Get the name for an element node.
*
* @code NULL@ is returned if the node is not an element node.
*
* @since Mini-XML 2.7@
*/
const char * /* O - Element name or @code NULL@ */
mxmlGetElement(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT)
return (NULL);
/*
* Return the element name...
*/
return (node->value.element.name);
}
/*
* 'mxmlGetFirstChild()' - Get the first child of an element node.
*
* @code NULL@ is returned if the node is not an element node or if the node
* has no children.
*
* @since Mini-XML 2.7@
*/
mxml_node_t * /* O - First child or @code NULL@ */
mxmlGetFirstChild(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT)
return (NULL);
/*
* Return the first child node...
*/
return (node->child);
}
/*
* 'mxmlGetInteger()' - Get the integer value from the specified node or its
* first child.
*
* 0 is returned if the node (or its first child) is not an integer value node.
*
* @since Mini-XML 2.7@
*/
int /* O - Integer value or 0 */
mxmlGetInteger(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (0);
/*
* Return the integer value...
*/
if (node->type == MXML_INTEGER)
return (node->value.integer);
else if (node->type == MXML_ELEMENT &&
node->child &&
node->child->type == MXML_INTEGER)
return (node->child->value.integer);
else
return (0);
}
/*
* 'mxmlGetLastChild()' - Get the last child of an element node.
*
* @code NULL@ is returned if the node is not an element node or if the node
* has no children.
*
* @since Mini-XML 2.7@
*/
mxml_node_t * /* O - Last child or @code NULL@ */
mxmlGetLastChild(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT)
return (NULL);
/*
* Return the node type...
*/
return (node->last_child);
}
/*
* 'mxmlGetNextSibling()' - Get the next node for the current parent.
*
* @code NULL@ is returned if this is the last child for the current parent.
*
* @since Mini-XML 2.7@
*/
mxml_node_t *
mxmlGetNextSibling(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the node type...
*/
return (node->next);
}
/*
* 'mxmlGetOpaque()' - Get an opaque string value for a node or its first child.
*
* @code NULL@ is returned if the node (or its first child) is not an opaque
* value node.
*
* @since Mini-XML 2.7@
*/
const char * /* O - Opaque string or @code NULL@ */
mxmlGetOpaque(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the integer value...
*/
if (node->type == MXML_OPAQUE)
return (node->value.opaque);
else if (node->type == MXML_ELEMENT &&
node->child &&
node->child->type == MXML_OPAQUE)
return (node->child->value.opaque);
else
return (NULL);
}
/*
* 'mxmlGetParent()' - Get the parent node.
*
* @code NULL@ is returned for a root node.
*
* @since Mini-XML 2.7@
*/
mxml_node_t * /* O - Parent node or @code NULL@ */
mxmlGetParent(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);