2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
2017-03-22 18:51:16 +00:00
|
|
|
|
* Node set functions for Mini-XML, a small XML file parsing library.
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*
|
2019-01-05 01:44:51 +00:00
|
|
|
|
* https://www.msweet.org/mxml
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*
|
2021-10-26 17:44:00 +00:00
|
|
|
|
* Copyright © 2003-2021 by Michael R Sweet.
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*
|
2019-01-05 01:44:51 +00:00
|
|
|
|
* Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
* information.
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Include necessary headers...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
2019-01-05 01:02:48 +00:00
|
|
|
|
#include "mxml-private.h"
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
|
2004-10-28 02:58:01 +00:00
|
|
|
|
/*
|
2011-01-01 23:42:17 +00:00
|
|
|
|
* 'mxmlSetCDATA()' - Set the element name of a CDATA node.
|
2004-10-28 02:58:01 +00:00
|
|
|
|
*
|
2011-12-09 23:49:00 +00:00
|
|
|
|
* The node is not changed if it (or its first child) is not a CDATA element node.
|
2005-10-13 18:27:00 +00:00
|
|
|
|
*
|
2011-01-01 23:42:17 +00:00
|
|
|
|
* @since Mini-XML 2.3@
|
2004-10-28 02:58:01 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
2011-01-01 23:42:17 +00:00
|
|
|
|
mxmlSetCDATA(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
const char *data) /* I - New data string */
|
2004-10-28 02:58:01 +00:00
|
|
|
|
{
|
2021-10-26 19:11:00 +00:00
|
|
|
|
char *s; /* New element name */
|
|
|
|
|
|
|
|
|
|
|
2004-10-28 02:58:01 +00:00
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-09 23:49:00 +00:00
|
|
|
|
if (node && node->type == MXML_ELEMENT &&
|
|
|
|
|
strncmp(node->value.element.name, "![CDATA[", 8) &&
|
|
|
|
|
node->child && node->child->type == MXML_ELEMENT &&
|
|
|
|
|
!strncmp(node->child->value.element.name, "![CDATA[", 8))
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if (!node || node->type != MXML_ELEMENT ||
|
2011-01-01 23:42:17 +00:00
|
|
|
|
strncmp(node->value.element.name, "![CDATA[", 8))
|
2021-10-26 19:11:00 +00:00
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
else if (!data)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("NULL string not allowed.");
|
2004-10-28 02:58:01 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
if (data == (node->value.element.name + 8))
|
2021-10-26 19:11:00 +00:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Don't change the value...
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
return (0);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
2019-01-09 16:53:07 +00:00
|
|
|
|
|
2004-10-28 02:58:01 +00:00
|
|
|
|
/*
|
2019-01-09 16:53:07 +00:00
|
|
|
|
* Allocate the new value, free any old element value, and set the new value...
|
2004-10-28 02:58:01 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if ((s = _mxml_strdupf("![CDATA[%s", data)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Unable to allocate memory for CDATA.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 17:44:00 +00:00
|
|
|
|
free(node->value.element.name);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
node->value.element.name = s;
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-08-05 14:17:19 +00:00
|
|
|
|
/*
|
2011-01-01 23:42:17 +00:00
|
|
|
|
* 'mxmlSetCustom()' - Set the data and destructor of a custom data node.
|
2005-08-05 14:17:19 +00:00
|
|
|
|
*
|
2011-12-09 23:49:00 +00:00
|
|
|
|
* The node is not changed if it (or its first child) is not a custom node.
|
2005-10-13 18:27:00 +00:00
|
|
|
|
*
|
2011-01-01 23:42:17 +00:00
|
|
|
|
* @since Mini-XML 2.1@
|
2005-08-05 14:17:19 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
2011-01-01 23:42:17 +00:00
|
|
|
|
mxmlSetCustom(
|
|
|
|
|
mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
void *data, /* I - New data pointer */
|
|
|
|
|
mxml_custom_destroy_cb_t destroy) /* I - New destructor function */
|
2005-08-05 14:17:19 +00:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-09 23:49:00 +00:00
|
|
|
|
if (node && node->type == MXML_ELEMENT &&
|
|
|
|
|
node->child && node->child->type == MXML_CUSTOM)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
2011-01-01 23:42:17 +00:00
|
|
|
|
if (!node || node->type != MXML_CUSTOM)
|
2021-10-26 19:11:00 +00:00
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
2005-08-05 14:17:19 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
if (data == node->value.custom.data)
|
|
|
|
|
{
|
|
|
|
|
node->value.custom.destroy = destroy;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-05 14:17:19 +00:00
|
|
|
|
/*
|
|
|
|
|
* Free any old element value and set the new value...
|
|
|
|
|
*/
|
|
|
|
|
|
2011-01-01 23:42:17 +00:00
|
|
|
|
if (node->value.custom.data && node->value.custom.destroy)
|
|
|
|
|
(*(node->value.custom.destroy))(node->value.custom.data);
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
2011-01-01 23:42:17 +00:00
|
|
|
|
node->value.custom.data = data;
|
|
|
|
|
node->value.custom.destroy = destroy;
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* 'mxmlSetElement()' - Set the name of an element node.
|
|
|
|
|
*
|
|
|
|
|
* The node is not changed if it is not an element node.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
|
|
|
|
mxmlSetElement(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
const char *name) /* I - New name string */
|
|
|
|
|
{
|
2021-10-26 19:11:00 +00:00
|
|
|
|
char *s; /* New name string */
|
|
|
|
|
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if (!node || node->type != MXML_ELEMENT)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
2003-09-28 21:09:04 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
|
|
|
|
else if (!name)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("NULL string not allowed.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
if (name == node->value.element.name)
|
|
|
|
|
return (0);
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* Free any old element value and set the new value...
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if ((s = strdup(name)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Unable to allocate memory for element name.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.element.name);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
node->value.element.name = s;
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 'mxmlSetInteger()' - Set the value of an integer node.
|
|
|
|
|
*
|
2011-12-09 23:49:00 +00:00
|
|
|
|
* The node is not changed if it (or its first child) is not an integer node.
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
|
|
|
|
mxmlSetInteger(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
int integer) /* I - Integer value */
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-09 23:49:00 +00:00
|
|
|
|
if (node && node->type == MXML_ELEMENT &&
|
|
|
|
|
node->child && node->child->type == MXML_INTEGER)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
if (!node || node->type != MXML_INTEGER)
|
2021-10-26 19:11:00 +00:00
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
2003-09-28 21:09:04 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set the new value and return...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
node->value.integer = integer;
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 'mxmlSetOpaque()' - Set the value of an opaque node.
|
|
|
|
|
*
|
2011-12-09 23:49:00 +00:00
|
|
|
|
* The node is not changed if it (or its first child) is not an opaque node.
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
|
|
|
|
mxmlSetOpaque(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
const char *opaque) /* I - Opaque string */
|
|
|
|
|
{
|
2021-10-26 19:11:00 +00:00
|
|
|
|
char *s; /* New opaque string */
|
|
|
|
|
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-09 23:49:00 +00:00
|
|
|
|
if (node && node->type == MXML_ELEMENT &&
|
|
|
|
|
node->child && node->child->type == MXML_OPAQUE)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if (!node || node->type != MXML_OPAQUE)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
2003-09-28 21:09:04 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
|
|
|
|
else if (!opaque)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("NULL string not allowed.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
if (node->value.opaque == opaque)
|
|
|
|
|
return (0);
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* Free any old opaque value and set the new value...
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if ((s = strdup(opaque)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Unable to allocate memory for opaque string.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.opaque);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
node->value.opaque = s;
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-04-24 14:42:03 +00:00
|
|
|
|
/*
|
|
|
|
|
* 'mxmlSetOpaquef()' - Set the value of an opaque string node to a formatted string.
|
|
|
|
|
*
|
|
|
|
|
* The node is not changed if it (or its first child) is not an opaque node.
|
|
|
|
|
*
|
|
|
|
|
* @since Mini-XML 2.11@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
|
|
|
|
mxmlSetOpaquef(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
const char *format, /* I - Printf-style format string */
|
|
|
|
|
...) /* I - Additional arguments as needed */
|
|
|
|
|
{
|
|
|
|
|
va_list ap; /* Pointer to arguments */
|
2019-01-09 16:53:07 +00:00
|
|
|
|
char *s; /* Temporary string */
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (node && node->type == MXML_ELEMENT &&
|
|
|
|
|
node->child && node->child->type == MXML_OPAQUE)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if (!node || node->type != MXML_OPAQUE)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
2017-04-24 14:42:03 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
|
|
|
|
else if (!format)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("NULL string not allowed.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2019-01-09 16:53:07 +00:00
|
|
|
|
* Format the new string, free any old string value, and set the new value...
|
2017-04-24 14:42:03 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
va_start(ap, format);
|
2019-02-06 12:50:10 +00:00
|
|
|
|
s = _mxml_vstrdupf(format, ap);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
va_end(ap);
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if (!s)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Unable to allocate memory for opaque string.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.opaque);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
node->value.opaque = s;
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* 'mxmlSetReal()' - Set the value of a real number node.
|
|
|
|
|
*
|
2011-12-09 23:49:00 +00:00
|
|
|
|
* The node is not changed if it (or its first child) is not a real number node.
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
|
|
|
|
mxmlSetReal(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
double real) /* I - Real number value */
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-09 23:49:00 +00:00
|
|
|
|
if (node && node->type == MXML_ELEMENT &&
|
|
|
|
|
node->child && node->child->type == MXML_REAL)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
if (!node || node->type != MXML_REAL)
|
2021-10-26 19:11:00 +00:00
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
2003-09-28 21:09:04 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set the new value and return...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
node->value.real = real;
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 'mxmlSetText()' - Set the value of a text node.
|
|
|
|
|
*
|
2011-12-09 23:49:00 +00:00
|
|
|
|
* The node is not changed if it (or its first child) is not a text node.
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
|
|
|
|
mxmlSetText(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
int whitespace, /* I - 1 = leading whitespace, 0 = no whitespace */
|
|
|
|
|
const char *string) /* I - String */
|
|
|
|
|
{
|
2021-10-26 19:11:00 +00:00
|
|
|
|
char *s; /* New string */
|
|
|
|
|
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-09 23:49:00 +00:00
|
|
|
|
if (node && node->type == MXML_ELEMENT &&
|
|
|
|
|
node->child && node->child->type == MXML_TEXT)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if (!node || node->type != MXML_TEXT)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
2003-09-28 21:09:04 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
|
|
|
|
else if (!string)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("NULL string not allowed.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
if (string == node->value.text.string)
|
|
|
|
|
{
|
|
|
|
|
node->value.text.whitespace = whitespace;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* Free any old string value and set the new value...
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if ((s = strdup(string)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Unable to allocate memory for text string.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.text.string);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
node->value.text.whitespace = whitespace;
|
2021-10-26 19:11:00 +00:00
|
|
|
|
node->value.text.string = s;
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 'mxmlSetTextf()' - Set the value of a text node to a formatted string.
|
|
|
|
|
*
|
2011-12-09 23:49:00 +00:00
|
|
|
|
* The node is not changed if it (or its first child) is not a text node.
|
2003-09-28 21:09:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
|
|
|
|
mxmlSetTextf(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
int whitespace, /* I - 1 = leading whitespace, 0 = no whitespace */
|
|
|
|
|
const char *format, /* I - Printf-style format string */
|
|
|
|
|
...) /* I - Additional arguments as needed */
|
|
|
|
|
{
|
|
|
|
|
va_list ap; /* Pointer to arguments */
|
2019-01-09 16:53:07 +00:00
|
|
|
|
char *s; /* Temporary string */
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-09 23:49:00 +00:00
|
|
|
|
if (node && node->type == MXML_ELEMENT &&
|
|
|
|
|
node->child && node->child->type == MXML_TEXT)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if (!node || node->type != MXML_TEXT)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Wrong node type.");
|
2003-09-28 21:09:04 +00:00
|
|
|
|
return (-1);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
|
|
|
|
else if (!format)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("NULL string not allowed.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Free any old string value and set the new value...
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
va_start(ap, format);
|
2019-02-06 12:50:10 +00:00
|
|
|
|
s = _mxml_vstrdupf(format, ap);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2021-10-26 19:11:00 +00:00
|
|
|
|
if (!s)
|
|
|
|
|
{
|
|
|
|
|
mxml_error("Unable to allocate memory for text string.");
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.text.string);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
node->value.text.whitespace = whitespace;
|
2019-01-09 16:53:07 +00:00
|
|
|
|
node->value.text.string = s;
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-01-01 23:42:17 +00:00
|
|
|
|
/*
|
|
|
|
|
* 'mxmlSetUserData()' - Set the user data pointer for a node.
|
|
|
|
|
*
|
|
|
|
|
* @since Mini-XML 2.7@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int /* O - 0 on success, -1 on failure */
|
|
|
|
|
mxmlSetUserData(mxml_node_t *node, /* I - Node to set */
|
|
|
|
|
void *data) /* I - User data pointer */
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Range check input...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set the user data pointer and return...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
node->user_data = data;
|
|
|
|
|
return (0);
|
|
|
|
|
}
|