2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// Node set functions for Mini-XML, a small XML file parsing library.
|
|
|
|
|
//
|
|
|
|
|
// https://www.msweet.org/mxml
|
|
|
|
|
//
|
|
|
|
|
// Copyright © 2003-2024 by Michael R Sweet.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
// information.
|
|
|
|
|
//
|
|
|
|
|
|
2019-01-05 01:02:48 +00:00
|
|
|
|
#include "mxml-private.h"
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2024-03-02 23:47:57 +00:00
|
|
|
|
// 'mxmlSetCDATA()' - Set the data for a CDATA node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the value string for a CDATA node. The node is not
|
|
|
|
|
// changed if it (or its first child) is not a CDATA node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +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
|
|
|
|
{
|
2024-03-02 23:47:57 +00:00
|
|
|
|
char *s; // New element name
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2024-03-02 23:47:57 +00:00
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_CDATA)
|
2011-12-09 23:49:00 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_CDATA)
|
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
else if (!data)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
if (data == node->value.cdata)
|
2021-10-26 19:11:00 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Don't change the value...
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
}
|
2019-01-09 16:53:07 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Allocate the new value, free any old element value, and set the new value...
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(data)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.cdata);
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node->value.cdata = s;
|
|
|
|
|
|
|
|
|
|
return (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetCDATAf()' - Set the data for a CDATA to a formatted string.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the formatted string value of a CDATA node. The node is
|
|
|
|
|
// not changed if it (or its first child) is not a CDATA node.
|
|
|
|
|
//
|
2024-03-02 23:47:57 +00:00
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetCDATAf(mxml_node_t *node, // I - Node
|
|
|
|
|
const char *format, // I - `printf`-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
|
|
|
|
{
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
char *s; // Temporary string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_CDATA)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
|
|
|
|
if (!node || node->type != MXML_TYPE_CDATA)
|
|
|
|
|
return (false);
|
|
|
|
|
else if (!format)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Format the new string, free any old string value, and set the new value...
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(buffer)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.cdata);
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node->value.cdata = s;
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetComment()' - Set a comment to a literal string.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the string value of a comment node.
|
|
|
|
|
//
|
2024-03-02 23:47:57 +00:00
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetComment(mxml_node_t *node, // I - Node
|
|
|
|
|
const char *comment) // I - Literal string
|
|
|
|
|
{
|
|
|
|
|
char *s; // New string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_COMMENT)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
|
|
|
|
if (!node || node->type != MXML_TYPE_COMMENT)
|
|
|
|
|
return (false);
|
|
|
|
|
else if (!comment)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
if (comment == node->value.comment)
|
|
|
|
|
return (true);
|
|
|
|
|
|
|
|
|
|
// Free any old string value and set the new value...
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(comment)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.comment);
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node->value.comment = s;
|
|
|
|
|
|
|
|
|
|
return (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetCommentf()' - Set a comment to a formatted string.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the formatted string value of a comment node.
|
|
|
|
|
//
|
2024-03-02 23:47:57 +00:00
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetCommentf(mxml_node_t *node, // I - Node
|
|
|
|
|
const char *format, // I - `printf`-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
|
|
|
|
{
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
char *s; // Temporary string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_COMMENT)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
|
|
|
|
if (!node || node->type != MXML_TYPE_COMMENT)
|
|
|
|
|
return (false);
|
|
|
|
|
else if (!format)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Format the new string, free any old string value, and set the new value...
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(buffer)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.comment);
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node->value.comment = s;
|
|
|
|
|
|
|
|
|
|
return (true);
|
2004-10-28 02:58:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetCustom()' - Set the data and destructor of a custom data node.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the data pointer `data` and destructor callback
|
|
|
|
|
// `destroy_cb` of a custom data node. The node is not changed if it (or its
|
|
|
|
|
// first child) is not a custom node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2011-01-01 23:42:17 +00:00
|
|
|
|
mxmlSetCustom(
|
2024-03-19 01:46:14 +00:00
|
|
|
|
mxml_node_t *node, // I - Node to set
|
|
|
|
|
void *data, // I - New data pointer
|
|
|
|
|
mxml_custfree_cb_t free_cb, // I - Free callback function
|
|
|
|
|
void *free_cbdata) // I - Free callback data
|
2005-08-05 14:17:19 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_CUSTOM)
|
2011-12-09 23:49:00 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_CUSTOM)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
if (data == node->value.custom.data)
|
2024-03-19 01:46:14 +00:00
|
|
|
|
goto set_free_callback;
|
2019-01-09 16:53:07 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Free any old element value and set the new value...
|
2024-03-19 01:46:14 +00:00
|
|
|
|
if (node->value.custom.data && node->value.custom.free_cb)
|
|
|
|
|
(node->value.custom.free_cb)(node->value.custom.free_cbdata, node->value.custom.data);
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
2024-03-19 01:46:14 +00:00
|
|
|
|
node->value.custom.data = data;
|
|
|
|
|
|
|
|
|
|
set_free_callback:
|
|
|
|
|
|
|
|
|
|
node->value.custom.free_cb = free_cb;
|
|
|
|
|
node->value.custom.free_cbdata = free_cbdata;
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// 'mxmlSetDeclaration()' - Set a declaration to a literal string.
|
|
|
|
|
//
|
|
|
|
|
// This function sets the string value of a declaration node.
|
2024-03-02 23:47:57 +00:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetDeclaration(
|
|
|
|
|
mxml_node_t *node, // I - Node
|
|
|
|
|
const char *declaration) // I - Literal string
|
|
|
|
|
{
|
|
|
|
|
char *s; // New string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_DECLARATION)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
|
|
|
|
if (!node || node->type != MXML_TYPE_DECLARATION)
|
|
|
|
|
return (false);
|
|
|
|
|
else if (!declaration)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
if (declaration == node->value.declaration)
|
|
|
|
|
return (true);
|
|
|
|
|
|
|
|
|
|
// Free any old string value and set the new value...
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(declaration)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.declaration);
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node->value.declaration = s;
|
|
|
|
|
|
|
|
|
|
return (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// 'mxmlSetDeclarationf()' - Set a declaration to a formatted string.
|
|
|
|
|
//
|
|
|
|
|
// This function sets the formatted string value of a declaration node.
|
2024-03-02 23:47:57 +00:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetDeclarationf(mxml_node_t *node, // I - Node
|
|
|
|
|
const char *format, // I - `printf`-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
|
|
|
|
{
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
char *s; // Temporary string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
2024-04-21 20:58:53 +00:00
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_DECLARATION)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-04-21 20:58:53 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_DECLARATION)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
|
|
|
|
else if (!format)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Format the new string, free any old string value, and set the new value...
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(buffer)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.declaration);
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node->value.declaration = s;
|
|
|
|
|
|
|
|
|
|
return (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// 'mxmlSetDirective()' - Set a processing instruction to a literal string.
|
|
|
|
|
//
|
|
|
|
|
// This function sets the string value of a processing instruction node.
|
2024-03-02 23:47:57 +00:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetDirective(mxml_node_t *node, // I - Node
|
|
|
|
|
const char *directive)// I - Literal string
|
|
|
|
|
{
|
|
|
|
|
char *s; // New string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_DIRECTIVE)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
|
|
|
|
if (!node || node->type != MXML_TYPE_DIRECTIVE)
|
|
|
|
|
return (false);
|
|
|
|
|
else if (!directive)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
if (directive == node->value.directive)
|
|
|
|
|
return (true);
|
|
|
|
|
|
|
|
|
|
// Free any old string value and set the new value...
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(directive)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.directive);
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node->value.directive = s;
|
|
|
|
|
|
|
|
|
|
return (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// 'mxmlSetDirectivef()' - Set a processing instruction to a formatted string.
|
|
|
|
|
//
|
|
|
|
|
// This function sets the formatted string value of a processing instruction
|
|
|
|
|
// node.
|
2024-03-02 23:47:57 +00:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetDirectivef(mxml_node_t *node, // I - Node
|
|
|
|
|
const char *format, // I - `printf`-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
|
|
|
|
{
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
char *s; // Temporary string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_DIRECTIVE)
|
|
|
|
|
node = node->child;
|
|
|
|
|
|
|
|
|
|
if (!node || node->type != MXML_TYPE_DIRECTIVE)
|
|
|
|
|
return (false);
|
|
|
|
|
else if (!format)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Format the new string, free any old string value, and set the new value...
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(buffer)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.directive);
|
2024-03-02 23:47:57 +00:00
|
|
|
|
node->value.directive = s;
|
|
|
|
|
|
|
|
|
|
return (true);
|
2005-08-05 14:17:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetElement()' - Set the name of an element node.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the name of an element node. The node is not changed if
|
|
|
|
|
// it is not an element node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlSetElement(mxml_node_t *node, // I - Node to set
|
|
|
|
|
const char *name) // I - New name string
|
2003-09-28 21:09:04 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
char *s; // New name string
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
|
|
|
|
if (!node || node->type != MXML_TYPE_ELEMENT)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
else if (!name)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
if (name == node->value.element.name)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Free any old element value and set the new value...
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(name)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(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
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetInteger()' - Set the value of an integer node.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the value of an integer node. The node is not changed if
|
|
|
|
|
// it (or its first child) is not an integer node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlSetInteger(mxml_node_t *node, // I - Node to set
|
2024-03-02 23:47:57 +00:00
|
|
|
|
long integer) // I - Integer value
|
2003-09-28 21:09:04 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_INTEGER)
|
2011-12-09 23:49:00 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_INTEGER)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Set the new value and return...
|
2003-09-28 21:09:04 +00:00
|
|
|
|
node->value.integer = integer;
|
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetOpaque()' - Set the value of an opaque node.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the string value of an opaque node. The node is not
|
|
|
|
|
// changed if it (or its first child) is not an opaque node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlSetOpaque(mxml_node_t *node, // I - Node to set
|
|
|
|
|
const char *opaque) // I - Opaque string
|
2003-09-28 21:09:04 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
char *s; // New opaque string
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_OPAQUE)
|
2011-12-09 23:49:00 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_OPAQUE)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
else if (!opaque)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2019-01-09 16:53:07 +00:00
|
|
|
|
if (node->value.opaque == opaque)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Free any old opaque value and set the new value...
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(opaque)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.opaque);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
node->value.opaque = s;
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetOpaquef()' - Set the value of an opaque string node to a formatted string.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the formatted string value of an opaque node. The node is
|
|
|
|
|
// not changed if it (or its first child) is not an opaque node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlSetOpaquef(mxml_node_t *node, // I - Node to set
|
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
2017-04-24 14:42:03 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
char *s; // Temporary string
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_OPAQUE)
|
2017-04-24 14:42:03 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_OPAQUE)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
else if (!format)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +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);
|
2024-02-27 20:04:27 +00:00
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
va_end(ap);
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(buffer)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(node->value.opaque);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
node->value.opaque = s;
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2017-04-24 14:42:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// 'mxmlSetReal()' - Set the value of a real value node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the value of a real value node. The node is not changed
|
|
|
|
|
// if it (or its first child) is not a real value node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlSetReal(mxml_node_t *node, // I - Node to set
|
|
|
|
|
double real) // I - Real number value
|
2003-09-28 21:09:04 +00:00
|
|
|
|
{
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// Range check input...
|
2024-02-27 20:04:27 +00:00
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_REAL)
|
2011-12-09 23:49:00 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_REAL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Set the new value and return...
|
2003-09-28 21:09:04 +00:00
|
|
|
|
node->value.real = real;
|
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetText()' - Set the value of a text node.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the string and whitespace values of a text node. The node
|
|
|
|
|
// is not changed if it (or its first child) is not a text node.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlSetText(mxml_node_t *node, // I - Node to set
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool whitespace, // I - `true` = leading whitespace, `false` = no whitespace
|
2024-02-27 20:04:27 +00:00
|
|
|
|
const char *string) // I - String
|
2003-09-28 21:09:04 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
char *s; // New string
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_TEXT)
|
2011-12-09 23:49:00 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_TEXT)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
else if (!string)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
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;
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Free any old string value and set the new value...
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(string)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(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
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetTextf()' - Set the value of a text node to a formatted string.
|
|
|
|
|
//
|
2024-03-17 02:20:24 +00:00
|
|
|
|
// This function sets the formatted string and whitespace values of a text node.
|
2024-02-27 20:04:27 +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
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlSetTextf(mxml_node_t *node, // I - Node to set
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool whitespace, // I - `true` = leading whitespace, `false` = no whitespace
|
2024-02-27 20:04:27 +00:00
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
2003-09-28 21:09:04 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
char *s; // Temporary string
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_TEXT)
|
2011-12-09 23:49:00 +00:00
|
|
|
|
node = node->child;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
if (!node || node->type != MXML_TYPE_TEXT)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
else if (!format)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
// Free any old string value and set the new value...
|
2019-01-09 16:53:07 +00:00
|
|
|
|
va_start(ap, format);
|
2024-02-27 20:04:27 +00:00
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
2019-01-09 16:53:07 +00:00
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
if ((s = _mxml_strcopy(buffer)) == NULL)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2021-10-26 19:11:00 +00:00
|
|
|
|
|
2024-03-07 19:06:50 +00:00
|
|
|
|
_mxml_strfree(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
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2003-09-28 21:09:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetUserData()' - Set the user data pointer for a node.
|
|
|
|
|
//
|
2011-01-01 23:42:17 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlSetUserData(mxml_node_t *node, // I - Node to set
|
|
|
|
|
void *data) // I - User data pointer
|
2011-01-01 23:42:17 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2011-01-01 23:42:17 +00:00
|
|
|
|
if (!node)
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (false);
|
2011-01-01 23:42:17 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Set the user data pointer and return...
|
2011-01-01 23:42:17 +00:00
|
|
|
|
node->user_data = data;
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (true);
|
2011-01-01 23:42:17 +00:00
|
|
|
|
}
|