|
|
|
@ -13,54 +13,187 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetCDATA()' - Set the element name of a CDATA node.
|
|
|
|
|
// 'mxmlSetCDATA()' - Set the data for a CDATA node.
|
|
|
|
|
//
|
|
|
|
|
// The node is not changed if it (or its first child) is not a CDATA element node.
|
|
|
|
|
// The node is not changed if it (or its first child) is not a CDATA node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetCDATA(mxml_node_t *node, // I - Node to set
|
|
|
|
|
const char *data) // I - New data string
|
|
|
|
|
{ |
|
|
|
|
size_t datalen; // Length of data string
|
|
|
|
|
char *s; // New element name
|
|
|
|
|
char *s; // New element name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && strncmp(node->value.element.name, "![CDATA[", 8) && node->child && node->child->type == MXML_TYPE_ELEMENT && !strncmp(node->child->value.element.name, "![CDATA[", 8)) |
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_CDATA) |
|
|
|
|
node = node->child; |
|
|
|
|
|
|
|
|
|
if (!node || node->type != MXML_TYPE_ELEMENT || strncmp(node->value.element.name, "![CDATA[", 8)) |
|
|
|
|
if (!node || node->type != MXML_TYPE_CDATA) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!data) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (data == (node->value.element.name + 8)) |
|
|
|
|
if (data == node->value.cdata) |
|
|
|
|
{ |
|
|
|
|
// Don't change the value...
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Allocate the new value, free any old element value, and set the new value...
|
|
|
|
|
datalen = strlen(data); |
|
|
|
|
|
|
|
|
|
if ((s = malloc(datalen + 9)) == NULL) |
|
|
|
|
if ((s = strdup(data)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for CDATA."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.element.name); |
|
|
|
|
node->value.element.name = s; |
|
|
|
|
snprintf(node->value.element.name, datalen + 9, "![CDATA[%s", data); |
|
|
|
|
free(node->value.cdata); |
|
|
|
|
node->value.cdata = s; |
|
|
|
|
|
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetCDATAf()' - Set the data for a CDATA to a formatted string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!format) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
if ((s = strdup(buffer)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for CDATA string."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.cdata); |
|
|
|
|
node->value.cdata = s; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetComment()' - Set a comment to a literal string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!comment) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL comment not allowed."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (comment == node->value.comment) |
|
|
|
|
return (true); |
|
|
|
|
|
|
|
|
|
// Free any old string value and set the new value...
|
|
|
|
|
if ((s = strdup(comment)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for comment string."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.comment); |
|
|
|
|
node->value.comment = s; |
|
|
|
|
|
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetCommentf()' - Set a comment to a formatted string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!format) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
if ((s = strdup(buffer)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for comment string."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.comment); |
|
|
|
|
node->value.comment = s; |
|
|
|
|
|
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -70,7 +203,7 @@ mxmlSetCDATA(mxml_node_t *node, // I - Node to set |
|
|
|
|
// The node is not changed if it (or its first child) is not a custom node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetCustom( |
|
|
|
|
mxml_node_t *node, // I - Node to set
|
|
|
|
|
void *data, // I - New data pointer
|
|
|
|
@ -83,13 +216,13 @@ mxmlSetCustom( |
|
|
|
|
if (!node || node->type != MXML_TYPE_CUSTOM) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (data == node->value.custom.data) |
|
|
|
|
{ |
|
|
|
|
node->value.custom.destroy = destroy; |
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Free any old element value and set the new value...
|
|
|
|
@ -99,7 +232,188 @@ mxmlSetCustom( |
|
|
|
|
node->value.custom.data = data; |
|
|
|
|
node->value.custom.destroy = destroy; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetDeclaration()' - Set a comment to a literal string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!declaration) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL declaration not allowed."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (declaration == node->value.declaration) |
|
|
|
|
return (true); |
|
|
|
|
|
|
|
|
|
// Free any old string value and set the new value...
|
|
|
|
|
if ((s = strdup(declaration)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for declaration string."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.declaration); |
|
|
|
|
node->value.declaration = s; |
|
|
|
|
|
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetDeclarationf()' - Set a comment to a formatted string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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...
|
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!format) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
if ((s = strdup(buffer)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for declaration string."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.declaration); |
|
|
|
|
node->value.declaration = s; |
|
|
|
|
|
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetDirective()' - Set a directive to a literal string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!directive) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL directive not allowed."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (directive == node->value.directive) |
|
|
|
|
return (true); |
|
|
|
|
|
|
|
|
|
// Free any old string value and set the new value...
|
|
|
|
|
if ((s = strdup(directive)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for directive string."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.directive); |
|
|
|
|
node->value.directive = s; |
|
|
|
|
|
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'mxmlSetDirectivef()' - Set a directive to a formatted string.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!format) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
if ((s = strdup(buffer)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for directive string."); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.directive); |
|
|
|
|
node->value.directive = s; |
|
|
|
|
|
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -109,7 +423,7 @@ mxmlSetCustom( |
|
|
|
|
// The node is not changed if it is not an element node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetElement(mxml_node_t *node, // I - Node to set
|
|
|
|
|
const char *name) // I - New name string
|
|
|
|
|
{ |
|
|
|
@ -120,28 +434,28 @@ mxmlSetElement(mxml_node_t *node, // I - Node to set |
|
|
|
|
if (!node || node->type != MXML_TYPE_ELEMENT) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!name) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (name == node->value.element.name) |
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
|
|
|
|
|
// Free any old element value and set the new value...
|
|
|
|
|
if ((s = strdup(name)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for element name."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.element.name); |
|
|
|
|
node->value.element.name = s; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -151,9 +465,9 @@ mxmlSetElement(mxml_node_t *node, // I - Node to set |
|
|
|
|
// The node is not changed if it (or its first child) is not an integer node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetInteger(mxml_node_t *node, // I - Node to set
|
|
|
|
|
int integer) // I - Integer value
|
|
|
|
|
long integer) // I - Integer value
|
|
|
|
|
{ |
|
|
|
|
// Range check input...
|
|
|
|
|
if (node && node->type == MXML_TYPE_ELEMENT && node->child && node->child->type == MXML_TYPE_INTEGER) |
|
|
|
@ -162,13 +476,13 @@ mxmlSetInteger(mxml_node_t *node, // I - Node to set |
|
|
|
|
if (!node || node->type != MXML_TYPE_INTEGER) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set the new value and return...
|
|
|
|
|
node->value.integer = integer; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -178,7 +492,7 @@ mxmlSetInteger(mxml_node_t *node, // I - Node to set |
|
|
|
|
// The node is not changed if it (or its first child) is not an opaque node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetOpaque(mxml_node_t *node, // I - Node to set
|
|
|
|
|
const char *opaque) // I - Opaque string
|
|
|
|
|
{ |
|
|
|
@ -192,28 +506,28 @@ mxmlSetOpaque(mxml_node_t *node, // I - Node to set |
|
|
|
|
if (!node || node->type != MXML_TYPE_OPAQUE) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!opaque) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (node->value.opaque == opaque) |
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
|
|
|
|
|
// Free any old opaque value and set the new value...
|
|
|
|
|
if ((s = strdup(opaque)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for opaque string."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.opaque); |
|
|
|
|
node->value.opaque = s; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -223,7 +537,7 @@ mxmlSetOpaque(mxml_node_t *node, // I - Node to set |
|
|
|
|
// The node is not changed if it (or its first child) is not an opaque node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetOpaquef(mxml_node_t *node, // I - Node to set
|
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
|
|
|
@ -240,12 +554,12 @@ mxmlSetOpaquef(mxml_node_t *node, // I - Node to set |
|
|
|
|
if (!node || node->type != MXML_TYPE_OPAQUE) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!format) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Format the new string, free any old string value, and set the new value...
|
|
|
|
@ -256,13 +570,13 @@ mxmlSetOpaquef(mxml_node_t *node, // I - Node to set |
|
|
|
|
if ((s = strdup(buffer)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for opaque string."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.opaque); |
|
|
|
|
node->value.opaque = s; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -272,7 +586,7 @@ mxmlSetOpaquef(mxml_node_t *node, // I - Node to set |
|
|
|
|
// The node is not changed if it (or its first child) is not a real number node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetReal(mxml_node_t *node, // I - Node to set
|
|
|
|
|
double real) // I - Real number value
|
|
|
|
|
{ |
|
|
|
@ -286,13 +600,13 @@ mxmlSetReal(mxml_node_t *node, // I - Node to set |
|
|
|
|
if (!node || node->type != MXML_TYPE_REAL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set the new value and return...
|
|
|
|
|
node->value.real = real; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -302,9 +616,9 @@ mxmlSetReal(mxml_node_t *node, // I - Node to set |
|
|
|
|
// The node is not changed if it (or its first child) is not a text node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetText(mxml_node_t *node, // I - Node to set
|
|
|
|
|
int whitespace, // I - 1 = leading whitespace, 0 = no whitespace
|
|
|
|
|
bool whitespace, // I - `true` = leading whitespace, `false` = no whitespace
|
|
|
|
|
const char *string) // I - String
|
|
|
|
|
{ |
|
|
|
|
char *s; // New string
|
|
|
|
@ -317,25 +631,25 @@ mxmlSetText(mxml_node_t *node, // I - Node to set |
|
|
|
|
if (!node || node->type != MXML_TYPE_TEXT) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!string) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (string == node->value.text.string) |
|
|
|
|
{ |
|
|
|
|
node->value.text.whitespace = whitespace; |
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Free any old string value and set the new value...
|
|
|
|
|
if ((s = strdup(string)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for text string."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.text.string); |
|
|
|
@ -343,7 +657,7 @@ mxmlSetText(mxml_node_t *node, // I - Node to set |
|
|
|
|
node->value.text.whitespace = whitespace; |
|
|
|
|
node->value.text.string = s; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -353,9 +667,9 @@ mxmlSetText(mxml_node_t *node, // I - Node to set |
|
|
|
|
// The node is not changed if it (or its first child) is not a text node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetTextf(mxml_node_t *node, // I - Node to set
|
|
|
|
|
int whitespace, // I - 1 = leading whitespace, 0 = no whitespace
|
|
|
|
|
bool whitespace, // I - `true` = leading whitespace, `false` = no whitespace
|
|
|
|
|
const char *format, // I - Printf-style format string
|
|
|
|
|
...) // I - Additional arguments as needed
|
|
|
|
|
{ |
|
|
|
@ -371,18 +685,15 @@ mxmlSetTextf(mxml_node_t *node, // I - Node to set |
|
|
|
|
if (!node || node->type != MXML_TYPE_TEXT) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Wrong node type."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
else if (!format) |
|
|
|
|
{ |
|
|
|
|
mxml_error("NULL string not allowed."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Free any old string value and set the new value... |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
// Free any old string value and set the new value...
|
|
|
|
|
va_start(ap, format); |
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, ap); |
|
|
|
|
va_end(ap); |
|
|
|
@ -390,7 +701,7 @@ mxmlSetTextf(mxml_node_t *node, // I - Node to set |
|
|
|
|
if ((s = strdup(buffer)) == NULL) |
|
|
|
|
{ |
|
|
|
|
mxml_error("Unable to allocate memory for text string."); |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(node->value.text.string); |
|
|
|
@ -398,7 +709,7 @@ mxmlSetTextf(mxml_node_t *node, // I - Node to set |
|
|
|
|
node->value.text.whitespace = whitespace; |
|
|
|
|
node->value.text.string = s; |
|
|
|
|
|
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -406,15 +717,15 @@ mxmlSetTextf(mxml_node_t *node, // I - Node to set |
|
|
|
|
// 'mxmlSetUserData()' - Set the user data pointer for a node.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
int // O - 0 on success, -1 on failure
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
mxmlSetUserData(mxml_node_t *node, // I - Node to set
|
|
|
|
|
void *data) // I - User data pointer
|
|
|
|
|
{ |
|
|
|
|
// Range check input...
|
|
|
|
|
if (!node) |
|
|
|
|
return (-1); |
|
|
|
|
return (false); |
|
|
|
|
|
|
|
|
|
// Set the user data pointer and return...
|
|
|
|
|
node->user_data = data; |
|
|
|
|
return (0); |
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|