2
* "$Id: mxml-set.c 22267 2006-04-24 17:11:45Z kpfleming $"
4
* Node set functions for Mini-XML, a small XML-like file parsing library.
6
* Copyright 2003-2005 by Michael Sweet.
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Library General Public
10
* License as published by the Free Software Foundation; either
11
* version 2, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
20
* mxmlSetElement() - Set the name of an element node.
21
* mxmlSetInteger() - Set the value of an integer node.
22
* mxmlSetOpaque() - Set the value of an opaque node.
23
* mxmlSetReal() - Set the value of a real number node.
24
* mxmlSetText() - Set the value of a text node.
25
* mxmlSetTextf() - Set the value of a text node to a formatted string.
29
* Include necessary headers...
37
* 'mxmlSetCustom()' - Set the data and destructor of a custom data node.
39
* The node is not changed if it is not a custom node.
42
int /* O - 0 on success, -1 on failure */
43
mxmlSetCustom(mxml_node_t *node, /* I - Node to set */
44
void *data, /* I - New data pointer */
45
void (*destroy)(void *))
46
/* I - New destructor function */
49
* Range check input...
52
if (!node || node->type != MXML_CUSTOM)
56
* Free any old element value and set the new value...
59
if (node->value.custom.data && node->value.custom.destroy)
60
(*(node->value.custom.destroy))(node->value.custom.data);
62
node->value.custom.data = data;
63
node->value.custom.destroy = destroy;
70
* 'mxmlSetElement()' - Set the name of an element node.
72
* The node is not changed if it is not an element node.
75
int /* O - 0 on success, -1 on failure */
76
mxmlSetElement(mxml_node_t *node, /* I - Node to set */
77
const char *name) /* I - New name string */
80
* Range check input...
83
if (!node || node->type != MXML_ELEMENT || !name)
87
* Free any old element value and set the new value...
90
if (node->value.element.name)
91
free(node->value.element.name);
93
node->value.element.name = strdup(name);
100
* 'mxmlSetInteger()' - Set the value of an integer node.
102
* The node is not changed if it is not an integer node.
105
int /* O - 0 on success, -1 on failure */
106
mxmlSetInteger(mxml_node_t *node, /* I - Node to set */
107
int integer) /* I - Integer value */
110
* Range check input...
113
if (!node || node->type != MXML_INTEGER)
117
* Set the new value and return...
120
node->value.integer = integer;
127
* 'mxmlSetOpaque()' - Set the value of an opaque node.
129
* The node is not changed if it is not an opaque node.
132
int /* O - 0 on success, -1 on failure */
133
mxmlSetOpaque(mxml_node_t *node, /* I - Node to set */
134
const char *opaque) /* I - Opaque string */
137
* Range check input...
140
if (!node || node->type != MXML_OPAQUE || !opaque)
144
* Free any old opaque value and set the new value...
147
if (node->value.opaque)
148
free(node->value.opaque);
150
node->value.opaque = strdup(opaque);
157
* 'mxmlSetReal()' - Set the value of a real number node.
159
* The node is not changed if it is not a real number node.
162
int /* O - 0 on success, -1 on failure */
163
mxmlSetReal(mxml_node_t *node, /* I - Node to set */
164
double real) /* I - Real number value */
167
* Range check input...
170
if (!node || node->type != MXML_REAL)
174
* Set the new value and return...
177
node->value.real = real;
184
* 'mxmlSetText()' - Set the value of a text node.
186
* The node is not changed if it is not a text node.
189
int /* O - 0 on success, -1 on failure */
190
mxmlSetText(mxml_node_t *node, /* I - Node to set */
191
int whitespace, /* I - 1 = leading whitespace, 0 = no whitespace */
192
const char *string) /* I - String */
195
* Range check input...
198
if (!node || node->type != MXML_TEXT || !string)
202
* Free any old string value and set the new value...
205
if (node->value.text.string)
206
free(node->value.text.string);
208
node->value.text.whitespace = whitespace;
209
node->value.text.string = strdup(string);
216
* 'mxmlSetTextf()' - Set the value of a text node to a formatted string.
218
* The node is not changed if it is not a text node.
221
int /* O - 0 on success, -1 on failure */
222
mxmlSetTextf(mxml_node_t *node, /* I - Node to set */
223
int whitespace, /* I - 1 = leading whitespace, 0 = no whitespace */
224
const char *format, /* I - Printf-style format string */
225
...) /* I - Additional arguments as needed */
227
va_list ap; /* Pointer to arguments */
231
* Range check input...
234
if (!node || node->type != MXML_TEXT || !format)
238
* Free any old string value and set the new value...
241
if (node->value.text.string)
242
free(node->value.text.string);
244
va_start(ap, format);
246
node->value.text.whitespace = whitespace;
247
node->value.text.string = mxml_strdupf(format, ap);
256
* End of "$Id: mxml-set.c 22267 2006-04-24 17:11:45Z kpfleming $".