2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// Node support code 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-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// Local functions...
|
|
|
|
|
//
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2016-06-11 20:51:49 +00:00
|
|
|
|
static void mxml_free(mxml_node_t *node);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
static mxml_node_t *mxml_new(mxml_node_t *parent, mxml_type_t type);
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlAdd()' - Add a node to a tree.
|
|
|
|
|
//
|
|
|
|
|
// Adds the specified node to the parent. If the child argument is not
|
|
|
|
|
// `NULL`, puts the new node before or after the specified child depending
|
|
|
|
|
// on the value of the where argument. If the child argument is `NULL`,
|
|
|
|
|
// puts the new node at the beginning of the child list (`MXML_ADD_BEFORE`)
|
|
|
|
|
// or at the end of the child list (`MXML_ADD_AFTER`). The constant
|
|
|
|
|
// `MXML_ADD_TO_PARENT` can be used to specify a `NULL` child pointer.
|
|
|
|
|
//
|
2003-06-04 17:37:23 +00:00
|
|
|
|
|
|
|
|
|
void
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlAdd(mxml_node_t *parent, // I - Parent node
|
|
|
|
|
int where, // I - Where to add, `MXML_ADD_BEFORE` or `MXML_ADD_AFTER`
|
|
|
|
|
mxml_node_t *child, // I - Child node for where or `MXML_ADD_TO_PARENT`
|
|
|
|
|
mxml_node_t *node) // I - Node to add
|
2003-06-04 17:37:23 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlAdd(parent=%p, where=%d, child=%p, node=%p)\n", parent, where, child, node);
|
2003-06-04 21:19:00 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2003-06-04 21:19:00 +00:00
|
|
|
|
if (!parent || !node)
|
2003-06-04 17:37:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Remove the node from any existing parent...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
if (node->parent)
|
|
|
|
|
mxmlRemove(node);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Reset pointers...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
node->parent = parent;
|
|
|
|
|
|
|
|
|
|
switch (where)
|
|
|
|
|
{
|
|
|
|
|
case MXML_ADD_BEFORE :
|
|
|
|
|
if (!child || child == parent->child || child->parent != parent)
|
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Insert as first node under parent...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
node->next = parent->child;
|
|
|
|
|
|
|
|
|
|
if (parent->child)
|
|
|
|
|
parent->child->prev = node;
|
|
|
|
|
else
|
|
|
|
|
parent->last_child = node;
|
|
|
|
|
|
|
|
|
|
parent->child = node;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Insert node before this child...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
node->next = child;
|
|
|
|
|
node->prev = child->prev;
|
|
|
|
|
|
|
|
|
|
if (child->prev)
|
|
|
|
|
child->prev->next = node;
|
|
|
|
|
else
|
|
|
|
|
parent->child = node;
|
|
|
|
|
|
|
|
|
|
child->prev = node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MXML_ADD_AFTER :
|
|
|
|
|
if (!child || child == parent->last_child || child->parent != parent)
|
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Insert as last node under parent...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
node->parent = parent;
|
|
|
|
|
node->prev = parent->last_child;
|
|
|
|
|
|
|
|
|
|
if (parent->last_child)
|
|
|
|
|
parent->last_child->next = node;
|
|
|
|
|
else
|
|
|
|
|
parent->child = node;
|
|
|
|
|
|
|
|
|
|
parent->last_child = node;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Insert node after this child...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
node->prev = child;
|
|
|
|
|
node->next = child->next;
|
|
|
|
|
|
|
|
|
|
if (child->next)
|
|
|
|
|
child->next->prev = node;
|
|
|
|
|
else
|
|
|
|
|
parent->last_child = node;
|
|
|
|
|
|
|
|
|
|
child->next = node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlDelete()' - Delete a node and all of its children.
|
|
|
|
|
//
|
|
|
|
|
// If the specified node has a parent, this function first removes the
|
|
|
|
|
// node from its parent using the @link mxmlRemove@ function.
|
|
|
|
|
//
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
void
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlDelete(mxml_node_t *node) // I - Node to delete
|
2003-06-03 19:46:29 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *current, // Current node
|
|
|
|
|
*next; // Next node
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2003-06-05 03:06:20 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlDelete(node=%p)\n", node);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2003-06-03 19:46:29 +00:00
|
|
|
|
if (!node)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Remove the node from its parent, if any...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
mxmlRemove(node);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Delete children...
|
2016-06-11 20:51:49 +00:00
|
|
|
|
for (current = node->child; current; current = next)
|
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Get the next node...
|
2016-06-11 20:51:49 +00:00
|
|
|
|
if ((next = current->child) != NULL)
|
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Free parent nodes after child nodes have been freed...
|
2016-06-11 20:51:49 +00:00
|
|
|
|
current->child = NULL;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2016-06-11 20:51:49 +00:00
|
|
|
|
if ((next = current->next) == NULL)
|
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Next node is the parent, which we'll free as needed...
|
2017-03-29 22:18:22 +00:00
|
|
|
|
if ((next = current->parent) == node)
|
2016-06-11 20:51:49 +00:00
|
|
|
|
next = NULL;
|
|
|
|
|
}
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Free child...
|
2016-06-11 20:51:49 +00:00
|
|
|
|
mxml_free(current);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Then free the memory used by the parent node...
|
2016-06-11 20:51:49 +00:00
|
|
|
|
mxml_free(node);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlGetRefCount()' - Get the current reference (use) count for a node.
|
|
|
|
|
//
|
|
|
|
|
// The initial reference count of new nodes is 1. Use the @link mxmlRetain@
|
|
|
|
|
// and @link mxmlRelease@ functions to increment and decrement a node's
|
|
|
|
|
// reference count.
|
|
|
|
|
//
|
2011-01-03 02:03:29 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
size_t // O - Reference count
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlGetRefCount(mxml_node_t *node) // I - Node
|
2011-01-03 02:03:29 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2011-01-03 02:03:29 +00:00
|
|
|
|
if (!node)
|
|
|
|
|
return (0);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Return the reference count...
|
2011-01-03 02:03:29 +00:00
|
|
|
|
return (node->ref_count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewCDATA()' - Create a new CDATA node.
|
|
|
|
|
//
|
|
|
|
|
// The new CDATA node is added to the end of the specified parent's child
|
|
|
|
|
// list. The constant `MXML_NO_PARENT` can be used to specify that the new
|
|
|
|
|
// CDATA node has no parent. The data string must be nul-terminated and
|
|
|
|
|
// is copied into the new node. CDATA nodes currently use the
|
|
|
|
|
// `MXML_TYPE_ELEMENT` type.
|
|
|
|
|
//
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewCDATA(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *data) // I - Data string
|
|
|
|
|
{
|
|
|
|
|
mxml_node_t *node; // New node
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewCDATA(parent=%p, data=\"%s\")\n", parent, data ? data : "(null)");
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2005-08-05 14:17:19 +00:00
|
|
|
|
if (!data)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the name value...
|
2024-03-02 23:47:57 +00:00
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_CDATA)) != NULL)
|
2024-02-27 20:04:27 +00:00
|
|
|
|
{
|
2024-03-02 23:47:57 +00:00
|
|
|
|
if ((node->value.cdata = strdup(data)) == NULL)
|
2024-02-27 20:04:27 +00:00
|
|
|
|
{
|
2024-03-06 19:45:10 +00:00
|
|
|
|
_mxml_error("Unable to allocate memory for CDATA.");
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlDelete(node);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
2024-03-02 23:47:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewCDATAf()' - Create a new formatted CDATA node.
|
|
|
|
|
//
|
|
|
|
|
// The new CDATA node is added to the end of the specified parent's
|
|
|
|
|
// child list. The constant `MXML_NO_PARENT` can be used to specify that
|
|
|
|
|
// the new opaque string node has no parent. The format string must be
|
|
|
|
|
// nul-terminated and is formatted into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewCDATAf(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional args as needed
|
|
|
|
|
{
|
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MXML_DEBUG("mxmlNewCDATAf(parent=%p, format=\"%s\", ...)\n", parent, format ? format : "(null)");
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (!format)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Create the node and set the text value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_CDATA)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
node->value.cdata = strdup(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewComment()' - Create a new comment node.
|
|
|
|
|
//
|
|
|
|
|
// The new comment node is added to the end of the specified parent's child
|
|
|
|
|
// list. The constant `MXML_NO_PARENT` can be used to specify that the new
|
|
|
|
|
// comment node has no parent. The comment string must be nul-terminated and
|
|
|
|
|
// is copied into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewComment(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *comment) // I - Comment string
|
|
|
|
|
{
|
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MXML_DEBUG("mxmlNewComment(parent=%p, comment=\"%s\")\n", parent, comment ? comment : "(null)");
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (!comment)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Create the node and set the name value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_COMMENT)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if ((node->value.comment = strdup(comment)) == NULL)
|
|
|
|
|
{
|
2024-03-06 19:45:10 +00:00
|
|
|
|
_mxml_error("Unable to allocate memory for comment.");
|
2024-03-02 23:47:57 +00:00
|
|
|
|
mxmlDelete(node);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewCommentf()' - Create a new formatted comment string node.
|
|
|
|
|
//
|
|
|
|
|
// The new comment string node is added to the end of the specified parent's
|
|
|
|
|
// child list. The constant `MXML_NO_PARENT` can be used to specify that
|
|
|
|
|
// the new opaque string node has no parent. The format string must be
|
|
|
|
|
// nul-terminated and is formatted into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewCommentf(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional args as needed
|
|
|
|
|
{
|
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewCommentf(parent=%p, format=\"%s\", ...)\n", parent, format ? format : "(null)");
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (!format)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Create the node and set the text value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_COMMENT)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
node->value.comment = strdup(buffer);
|
2024-02-27 20:04:27 +00:00
|
|
|
|
}
|
2005-08-05 14:17:19 +00:00
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewCustom()' - Create a new custom data node.
|
|
|
|
|
//
|
|
|
|
|
// The new custom node is added to the end of the specified parent's child
|
|
|
|
|
// list. The constant `MXML_NO_PARENT` can be used to specify that the new
|
|
|
|
|
// element node has no parent. `NULL` can be passed when the data in the
|
|
|
|
|
// node is not dynamically allocated or is separately managed.
|
|
|
|
|
//
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t * // O - New node
|
2007-04-23 21:48:03 +00:00
|
|
|
|
mxmlNewCustom(
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
void *data, // I - Pointer to data
|
|
|
|
|
mxml_custom_destroy_cb_t destroy) // I - Function to destroy data
|
2004-10-28 02:58:01 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewCustom(parent=%p, data=%p, destroy=%p)\n", parent, data, destroy);
|
2004-10-28 02:58:01 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_CUSTOM)) != NULL)
|
2004-10-28 02:58:01 +00:00
|
|
|
|
{
|
|
|
|
|
node->value.custom.data = data;
|
|
|
|
|
node->value.custom.destroy = destroy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewDeclaration()' - Create a new declaraction node.
|
|
|
|
|
//
|
|
|
|
|
// The new declaration node is added to the end of the specified parent's child
|
|
|
|
|
// list. The constant `MXML_NO_PARENT` can be used to specify that the new
|
|
|
|
|
// declaration node has no parent. The declaration string must be nul-
|
|
|
|
|
// terminated and is copied into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewDeclaration(
|
|
|
|
|
mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *declaration) // I - Declaration string
|
|
|
|
|
{
|
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MXML_DEBUG("mxmlNewDeclaration(parent=%p, declaration=\"%s\")\n", parent, declaration ? declaration : "(null)");
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (!declaration)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Create the node and set the name value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_DECLARATION)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if ((node->value.declaration = strdup(declaration)) == NULL)
|
|
|
|
|
{
|
2024-03-06 19:45:10 +00:00
|
|
|
|
_mxml_error("Unable to allocate memory for declaration.");
|
2024-03-02 23:47:57 +00:00
|
|
|
|
mxmlDelete(node);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewDeclarationf()' - Create a new formatted declaration node.
|
|
|
|
|
//
|
|
|
|
|
// The new declaration node is added to the end of the specified parent's
|
|
|
|
|
// child list. The constant `MXML_NO_PARENT` can be used to specify that
|
|
|
|
|
// the new opaque string node has no parent. The format string must be
|
|
|
|
|
// nul-terminated and is formatted into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewDeclarationf(
|
|
|
|
|
mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional args as needed
|
|
|
|
|
{
|
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MXML_DEBUG("mxmlNewDeclarationf(parent=%p, format=\"%s\", ...)\n", parent, format ? format : "(null)");
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (!format)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Create the node and set the text value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_DECLARATION)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
node->value.declaration = strdup(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewDirective()' - Create a new processing instruction node.
|
|
|
|
|
//
|
|
|
|
|
// The new processing instruction node is added to the end of the specified
|
|
|
|
|
// parent's child list. The constant `MXML_NO_PARENT` can be used to specify
|
|
|
|
|
// that the new processing instruction node has no parent. The data string must
|
|
|
|
|
// be nul-terminated and is copied into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewDirective(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *directive)// I - Directive string
|
|
|
|
|
{
|
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MXML_DEBUG("mxmlNewDirective(parent=%p, directive=\"%s\")\n", parent, directive ? directive : "(null)");
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (!directive)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Create the node and set the name value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_DIRECTIVE)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
if ((node->value.directive = strdup(directive)) == NULL)
|
|
|
|
|
{
|
2024-03-06 19:45:10 +00:00
|
|
|
|
_mxml_error("Unable to allocate memory for processing instruction.");
|
2024-03-02 23:47:57 +00:00
|
|
|
|
mxmlDelete(node);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewDirectivef()' - Create a new formatted processing instruction node.
|
|
|
|
|
//
|
|
|
|
|
// The new processing instruction node is added to the end of the specified parent's
|
|
|
|
|
// child list. The constant `MXML_NO_PARENT` can be used to specify that
|
|
|
|
|
// the new opaque string node has no parent. The format string must be
|
|
|
|
|
// nul-terminated and is formatted into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewDirectivef(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional args as needed
|
|
|
|
|
{
|
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MXML_DEBUG("mxmlNewDirectivef(parent=%p, format=\"%s\", ...)\n", parent, format ? format : "(null)");
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (!format)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Create the node and set the text value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_DIRECTIVE)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
node->value.directive = strdup(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewElement()' - Create a new element node.
|
|
|
|
|
//
|
|
|
|
|
// The new element node is added to the end of the specified parent's child
|
|
|
|
|
// list. The constant `MXML_NO_PARENT` can be used to specify that the new
|
|
|
|
|
// element node has no parent.
|
|
|
|
|
//
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewElement(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *name) // I - Name of element
|
2003-06-03 19:46:29 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewElement(parent=%p, name=\"%s\")\n", parent, name ? name : "(null)");
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2003-06-03 19:46:29 +00:00
|
|
|
|
if (!name)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the element name...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_ELEMENT)) != NULL)
|
2003-06-03 19:46:29 +00:00
|
|
|
|
node->value.element.name = strdup(name);
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewInteger()' - Create a new integer node.
|
|
|
|
|
//
|
|
|
|
|
// The new integer node is added to the end of the specified parent's child
|
|
|
|
|
// list. The constant `MXML_NO_PARENT` can be used to specify that the new
|
|
|
|
|
// integer node has no parent.
|
|
|
|
|
//
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewInteger(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
2024-03-02 23:47:57 +00:00
|
|
|
|
long integer) // I - Integer value
|
2003-06-03 19:46:29 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewInteger(parent=%p, integer=%ld)\n", parent, integer);
|
2003-12-03 03:59:04 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the element name...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_INTEGER)) != NULL)
|
2003-06-03 19:46:29 +00:00
|
|
|
|
node->value.integer = integer;
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewOpaque()' - Create a new opaque string.
|
|
|
|
|
//
|
|
|
|
|
// The new opaque string node is added to the end of the specified parent's
|
|
|
|
|
// child list. The constant `MXML_NO_PARENT` can be used to specify that
|
|
|
|
|
// the new opaque string node has no parent. The opaque string must be nul-
|
|
|
|
|
// terminated and is copied into the new node.
|
|
|
|
|
//
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewOpaque(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *opaque) // I - Opaque string
|
2003-06-03 19:46:29 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2003-12-03 03:59:04 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewOpaque(parent=%p, opaque=\"%s\")\n", parent, opaque ? opaque : "(null)");
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2005-05-14 12:34:29 +00:00
|
|
|
|
if (!opaque)
|
2003-06-03 19:46:29 +00:00
|
|
|
|
return (NULL);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the element name...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_OPAQUE)) != NULL)
|
2003-06-03 19:46:29 +00:00
|
|
|
|
node->value.opaque = strdup(opaque);
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewOpaquef()' - Create a new formatted opaque string node.
|
|
|
|
|
//
|
|
|
|
|
// The new opaque string node is added to the end of the specified parent's
|
|
|
|
|
// child list. The constant `MXML_NO_PARENT` can be used to specify that
|
|
|
|
|
// the new opaque string node has no parent. The format string must be
|
|
|
|
|
// nul-terminated and is formatted into the new node.
|
|
|
|
|
//
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewOpaquef(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional args as needed
|
2017-04-24 14:42:03 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewOpaquef(parent=%p, format=\"%s\", ...)\n", parent, format ? format : "(null)");
|
2017-04-24 14:42:03 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2017-04-24 14:42:03 +00:00
|
|
|
|
if (!format)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the text value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_OPAQUE)) != NULL)
|
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);
|
2017-04-24 14:42:03 +00:00
|
|
|
|
va_end(ap);
|
2024-02-27 20:04:27 +00:00
|
|
|
|
|
|
|
|
|
node->value.opaque = strdup(buffer);
|
2017-04-24 14:42:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewReal()' - Create a new real number node.
|
|
|
|
|
//
|
|
|
|
|
// The new real number node is added to the end of the specified parent's
|
|
|
|
|
// child list. The constant `MXML_NO_PARENT` can be used to specify that
|
|
|
|
|
// the new real number node has no parent.
|
|
|
|
|
//
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewReal(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
|
|
|
|
double real) // I - Real number value
|
2003-06-03 19:46:29 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2003-12-03 03:59:04 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewReal(parent=%p, real=%g)\n", parent, real);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the element name...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_REAL)) != NULL)
|
2003-06-03 19:46:29 +00:00
|
|
|
|
node->value.real = real;
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewText()' - Create a new text fragment node.
|
|
|
|
|
//
|
|
|
|
|
// The new text node is added to the end of the specified parent's child
|
|
|
|
|
// list. The constant `MXML_NO_PARENT` can be used to specify that the new
|
|
|
|
|
// text node has no parent. The whitespace parameter is used to specify
|
|
|
|
|
// whether leading whitespace is present before the node. The text
|
|
|
|
|
// string must be nul-terminated and is copied into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewText(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
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-06-03 19:46:29 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewText(parent=%p, whitespace=%s, string=\"%s\")\n", parent, whitespace ? "true" : "false", string ? string : "(null)");
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2005-05-14 12:34:29 +00:00
|
|
|
|
if (!string)
|
2003-06-03 19:46:29 +00:00
|
|
|
|
return (NULL);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the text value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_TEXT)) != NULL)
|
2003-06-03 19:46:29 +00:00
|
|
|
|
{
|
|
|
|
|
node->value.text.whitespace = whitespace;
|
|
|
|
|
node->value.text.string = strdup(string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewTextf()' - Create a new formatted text fragment node.
|
|
|
|
|
//
|
|
|
|
|
// The new text node is added to the end of the specified parent's child
|
|
|
|
|
// list. The constant `MXML_NO_PARENT` can be used to specify that the new
|
|
|
|
|
// text node has no parent. The whitespace parameter is used to specify
|
|
|
|
|
// whether leading whitespace is present before the node. The format
|
|
|
|
|
// string must be nul-terminated and is formatted into the new node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
mxml_node_t * // O - New node
|
|
|
|
|
mxmlNewTextf(mxml_node_t *parent, // I - Parent node or `MXML_NO_PARENT`
|
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 args as needed
|
2003-09-28 12:44:39 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
|
|
|
|
va_list ap; // Pointer to arguments
|
|
|
|
|
char buffer[16384]; // Format buffer
|
2003-09-28 12:44:39 +00:00
|
|
|
|
|
2003-12-03 03:59:04 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
MXML_DEBUG("mxmlNewTextf(parent=%p, whitespace=%s, format=\"%s\", ...)\n", parent, whitespace ? "true" : "false", format ? format : "(null)");
|
2003-09-28 12:44:39 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2005-05-14 12:34:29 +00:00
|
|
|
|
if (!format)
|
2003-09-28 12:44:39 +00:00
|
|
|
|
return (NULL);
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Create the node and set the text value...
|
|
|
|
|
if ((node = mxml_new(parent, MXML_TYPE_TEXT)) != NULL)
|
2003-09-28 12:44:39 +00:00
|
|
|
|
{
|
|
|
|
|
va_start(ap, format);
|
2024-02-27 20:04:27 +00:00
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap);
|
|
|
|
|
va_end(ap);
|
2003-09-28 12:44:39 +00:00
|
|
|
|
|
|
|
|
|
node->value.text.whitespace = whitespace;
|
2024-02-27 20:04:27 +00:00
|
|
|
|
node->value.text.string = strdup(buffer);
|
2003-09-28 12:44:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlRemove()' - Remove a node from its parent.
|
|
|
|
|
//
|
|
|
|
|
// This function does not free memory used by the node - use @link mxmlDelete@
|
|
|
|
|
// for that. This function does nothing if the node has no parent.
|
|
|
|
|
//
|
2003-06-04 17:37:23 +00:00
|
|
|
|
|
|
|
|
|
void
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxmlRemove(mxml_node_t *node) // I - Node to remove
|
2003-06-04 17:37:23 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxmlRemove(node=%p)\n", node);
|
2003-06-04 17:37:23 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Range check input...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
if (!node || !node->parent)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Remove from parent...
|
2003-06-04 17:37:23 +00:00
|
|
|
|
if (node->prev)
|
|
|
|
|
node->prev->next = node->next;
|
|
|
|
|
else
|
|
|
|
|
node->parent->child = node->next;
|
|
|
|
|
|
|
|
|
|
if (node->next)
|
|
|
|
|
node->next->prev = node->prev;
|
|
|
|
|
else
|
|
|
|
|
node->parent->last_child = node->prev;
|
2003-06-05 03:06:20 +00:00
|
|
|
|
|
|
|
|
|
node->parent = NULL;
|
|
|
|
|
node->prev = NULL;
|
|
|
|
|
node->next = NULL;
|
2003-06-04 17:37:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlNewXML()' - Create a new XML document tree.
|
|
|
|
|
//
|
|
|
|
|
// The "version" argument specifies the version number to put in the
|
2024-03-02 23:47:57 +00:00
|
|
|
|
// ?xml directive node. If `NULL`, version "1.0" is assumed.
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
2007-04-19 21:12:08 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t * // O - New ?xml node
|
|
|
|
|
mxmlNewXML(const char *version) // I - Version number to use
|
2007-04-19 21:12:08 +00:00
|
|
|
|
{
|
2024-03-02 23:47:57 +00:00
|
|
|
|
char directive[1024]; // Directive text
|
2007-04-19 21:12:08 +00:00
|
|
|
|
|
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
snprintf(directive, sizeof(directive), "xml version=\"%s\" encoding=\"utf-8\"", version ? version : "1.0");
|
2007-04-19 21:12:08 +00:00
|
|
|
|
|
2024-03-02 23:47:57 +00:00
|
|
|
|
return (mxmlNewDirective(NULL, directive));
|
2007-04-19 21:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlRelease()' - Release a node.
|
|
|
|
|
//
|
|
|
|
|
// When the reference count reaches zero, the node (and any children)
|
|
|
|
|
// is deleted via @link mxmlDelete@.
|
|
|
|
|
//
|
2007-04-18 01:08:58 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
int // O - New reference count
|
|
|
|
|
mxmlRelease(mxml_node_t *node) // I - Node
|
2007-04-18 01:08:58 +00:00
|
|
|
|
{
|
|
|
|
|
if (node)
|
|
|
|
|
{
|
|
|
|
|
if ((-- node->ref_count) <= 0)
|
|
|
|
|
{
|
|
|
|
|
mxmlDelete(node);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
else
|
2024-02-27 20:04:27 +00:00
|
|
|
|
{
|
2007-04-18 01:08:58 +00:00
|
|
|
|
return (node->ref_count);
|
2024-02-27 20:04:27 +00:00
|
|
|
|
}
|
2007-04-18 01:08:58 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2024-02-27 20:04:27 +00:00
|
|
|
|
{
|
2007-04-18 01:08:58 +00:00
|
|
|
|
return (-1);
|
2024-02-27 20:04:27 +00:00
|
|
|
|
}
|
2007-04-18 01:08:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxmlRetain()' - Retain a node.
|
|
|
|
|
//
|
2007-04-18 01:08:58 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
int // O - New reference count
|
|
|
|
|
mxmlRetain(mxml_node_t *node) // I - Node
|
2007-04-18 01:08:58 +00:00
|
|
|
|
{
|
|
|
|
|
if (node)
|
|
|
|
|
return (++ node->ref_count);
|
|
|
|
|
else
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxml_free()' - Free the memory used by a node.
|
|
|
|
|
//
|
|
|
|
|
// Note: Does not free child nodes, does not remove from parent.
|
|
|
|
|
//
|
2016-06-11 20:51:49 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_free(mxml_node_t *node) // I - Node
|
2016-06-11 20:51:49 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
int i; // Looping var
|
2016-06-11 20:51:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (node->type)
|
|
|
|
|
{
|
2024-03-02 23:47:57 +00:00
|
|
|
|
case MXML_TYPE_CDATA :
|
|
|
|
|
free(node->value.cdata);
|
|
|
|
|
break;
|
|
|
|
|
case MXML_TYPE_COMMENT :
|
|
|
|
|
free(node->value.comment);
|
|
|
|
|
break;
|
|
|
|
|
case MXML_TYPE_DECLARATION :
|
|
|
|
|
free(node->value.declaration);
|
|
|
|
|
break;
|
|
|
|
|
case MXML_TYPE_DIRECTIVE :
|
|
|
|
|
free(node->value.directive);
|
|
|
|
|
break;
|
2024-02-27 20:04:27 +00:00
|
|
|
|
case MXML_TYPE_ELEMENT :
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.element.name);
|
2016-06-11 20:51:49 +00:00
|
|
|
|
|
|
|
|
|
if (node->value.element.num_attrs)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < node->value.element.num_attrs; i ++)
|
|
|
|
|
{
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.element.attrs[i].name);
|
|
|
|
|
free(node->value.element.attrs[i].value);
|
2016-06-11 20:51:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(node->value.element.attrs);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2024-02-27 20:04:27 +00:00
|
|
|
|
case MXML_TYPE_INTEGER :
|
|
|
|
|
// Nothing to do
|
2016-06-11 20:51:49 +00:00
|
|
|
|
break;
|
2024-02-27 20:04:27 +00:00
|
|
|
|
case MXML_TYPE_OPAQUE :
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.opaque);
|
2016-06-11 20:51:49 +00:00
|
|
|
|
break;
|
2024-02-27 20:04:27 +00:00
|
|
|
|
case MXML_TYPE_REAL :
|
|
|
|
|
// Nothing to do
|
2016-06-11 20:51:49 +00:00
|
|
|
|
break;
|
2024-02-27 20:04:27 +00:00
|
|
|
|
case MXML_TYPE_TEXT :
|
2021-10-26 18:50:25 +00:00
|
|
|
|
free(node->value.text.string);
|
2016-06-11 20:51:49 +00:00
|
|
|
|
break;
|
2024-02-27 20:04:27 +00:00
|
|
|
|
case MXML_TYPE_CUSTOM :
|
|
|
|
|
if (node->value.custom.data && node->value.custom.destroy)
|
2016-06-11 20:51:49 +00:00
|
|
|
|
(*(node->value.custom.destroy))(node->value.custom.data);
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Free this node...
|
2016-06-11 20:51:49 +00:00
|
|
|
|
free(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// 'mxml_new()' - Create a new node.
|
|
|
|
|
//
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
static mxml_node_t * // O - New node
|
|
|
|
|
mxml_new(mxml_node_t *parent, // I - Parent node
|
|
|
|
|
mxml_type_t type) // I - Node type
|
2003-06-03 19:46:29 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t *node; // New node
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2003-12-03 03:59:04 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxml_new(parent=%p, type=%d)\n", parent, type);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Allocate memory for the node...
|
2003-06-03 19:46:29 +00:00
|
|
|
|
if ((node = calloc(1, sizeof(mxml_node_t))) == NULL)
|
2003-12-03 03:59:04 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxml_new: Returning NULL\n");
|
2003-06-03 19:46:29 +00:00
|
|
|
|
return (NULL);
|
2003-12-03 03:59:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
MXML_DEBUG("mxml_new: Returning %p\n", node);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Set the node type...
|
2007-04-18 01:08:58 +00:00
|
|
|
|
node->type = type;
|
|
|
|
|
node->ref_count = 1;
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Add to the parent if present...
|
2003-06-03 19:46:29 +00:00
|
|
|
|
if (parent)
|
2003-06-04 17:37:23 +00:00
|
|
|
|
mxmlAdd(parent, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, node);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
// Return the new node...
|
2003-06-03 19:46:29 +00:00
|
|
|
|
return (node);
|
|
|
|
|
}
|