~ubuntu-branches/ubuntu/saucy/dahdi-tools/saucy-proposed

« back to all changes in this revision

Viewing changes to menuselect/mxml/mxml-set.c

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2013-08-25 12:48:37 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130825124837-wtefi7f9dsihg8is
Tags: 1:2.7.0-1ubuntu1
* Merge from debian. Remaining changes:
  - debian/control: Added gawk as dependency for dkms build
  - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source
  - debian/control: Set ubuntu maintainer    
  - added debian/dahdi.postinst
  - debian/control: Removed Uploaders field.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * "$Id: mxml-set.c 22267 2006-04-24 17:11:45Z kpfleming $"
3
 
 *
4
 
 * Node set functions for Mini-XML, a small XML-like file parsing library.
5
 
 *
6
 
 * Copyright 2003-2005 by Michael Sweet.
7
 
 *
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.
12
 
 *
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.
17
 
 *
18
 
 * Contents:
19
 
 *
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.
26
 
 */
27
 
 
28
 
/*
29
 
 * Include necessary headers...
30
 
 */
31
 
 
32
 
#include "config.h"
33
 
#include "mxml.h"
34
 
 
35
 
 
36
 
/*
37
 
 * 'mxmlSetCustom()' - Set the data and destructor of a custom data node.
38
 
 *
39
 
 * The node is not changed if it is not a custom node.
40
 
 */
41
 
 
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 */
47
 
{
48
 
 /*
49
 
  * Range check input...
50
 
  */
51
 
 
52
 
  if (!node || node->type != MXML_CUSTOM)
53
 
    return (-1);
54
 
 
55
 
 /*
56
 
  * Free any old element value and set the new value...
57
 
  */
58
 
 
59
 
  if (node->value.custom.data && node->value.custom.destroy)
60
 
    (*(node->value.custom.destroy))(node->value.custom.data);
61
 
 
62
 
  node->value.custom.data    = data;
63
 
  node->value.custom.destroy = destroy;
64
 
 
65
 
  return (0);
66
 
}
67
 
 
68
 
 
69
 
/*
70
 
 * 'mxmlSetElement()' - Set the name of an element node.
71
 
 *
72
 
 * The node is not changed if it is not an element node.
73
 
 */
74
 
 
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 */
78
 
{
79
 
 /*
80
 
  * Range check input...
81
 
  */
82
 
 
83
 
  if (!node || node->type != MXML_ELEMENT || !name)
84
 
    return (-1);
85
 
 
86
 
 /*
87
 
  * Free any old element value and set the new value...
88
 
  */
89
 
 
90
 
  if (node->value.element.name)
91
 
    free(node->value.element.name);
92
 
 
93
 
  node->value.element.name = strdup(name);
94
 
 
95
 
  return (0);
96
 
}
97
 
 
98
 
 
99
 
/*
100
 
 * 'mxmlSetInteger()' - Set the value of an integer node.
101
 
 *
102
 
 * The node is not changed if it is not an integer node.
103
 
 */
104
 
 
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 */
108
 
{
109
 
 /*
110
 
  * Range check input...
111
 
  */
112
 
 
113
 
  if (!node || node->type != MXML_INTEGER)
114
 
    return (-1);
115
 
 
116
 
 /*
117
 
  * Set the new value and return...
118
 
  */
119
 
 
120
 
  node->value.integer = integer;
121
 
 
122
 
  return (0);
123
 
}
124
 
 
125
 
 
126
 
/*
127
 
 * 'mxmlSetOpaque()' - Set the value of an opaque node.
128
 
 *
129
 
 * The node is not changed if it is not an opaque node.
130
 
 */
131
 
 
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 */
135
 
{
136
 
 /*
137
 
  * Range check input...
138
 
  */
139
 
 
140
 
  if (!node || node->type != MXML_OPAQUE || !opaque)
141
 
    return (-1);
142
 
 
143
 
 /*
144
 
  * Free any old opaque value and set the new value...
145
 
  */
146
 
 
147
 
  if (node->value.opaque)
148
 
    free(node->value.opaque);
149
 
 
150
 
  node->value.opaque = strdup(opaque);
151
 
 
152
 
  return (0);
153
 
}
154
 
 
155
 
 
156
 
/*
157
 
 * 'mxmlSetReal()' - Set the value of a real number node.
158
 
 *
159
 
 * The node is not changed if it is not a real number node.
160
 
 */
161
 
 
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 */
165
 
{
166
 
 /*
167
 
  * Range check input...
168
 
  */
169
 
 
170
 
  if (!node || node->type != MXML_REAL)
171
 
    return (-1);
172
 
 
173
 
 /*
174
 
  * Set the new value and return...
175
 
  */
176
 
 
177
 
  node->value.real = real;
178
 
 
179
 
  return (0);
180
 
}
181
 
 
182
 
 
183
 
/*
184
 
 * 'mxmlSetText()' - Set the value of a text node.
185
 
 *
186
 
 * The node is not changed if it is not a text node.
187
 
 */
188
 
 
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 */
193
 
{
194
 
 /*
195
 
  * Range check input...
196
 
  */
197
 
 
198
 
  if (!node || node->type != MXML_TEXT || !string)
199
 
    return (-1);
200
 
 
201
 
 /*
202
 
  * Free any old string value and set the new value...
203
 
  */
204
 
 
205
 
  if (node->value.text.string)
206
 
    free(node->value.text.string);
207
 
 
208
 
  node->value.text.whitespace = whitespace;
209
 
  node->value.text.string     = strdup(string);
210
 
 
211
 
  return (0);
212
 
}
213
 
 
214
 
 
215
 
/*
216
 
 * 'mxmlSetTextf()' - Set the value of a text node to a formatted string.
217
 
 *
218
 
 * The node is not changed if it is not a text node.
219
 
 */
220
 
 
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 */
226
 
{
227
 
  va_list       ap;                     /* Pointer to arguments */
228
 
 
229
 
 
230
 
 /*
231
 
  * Range check input...
232
 
  */
233
 
 
234
 
  if (!node || node->type != MXML_TEXT || !format)
235
 
    return (-1);
236
 
 
237
 
 /*
238
 
  * Free any old string value and set the new value...
239
 
  */
240
 
 
241
 
  if (node->value.text.string)
242
 
    free(node->value.text.string);
243
 
 
244
 
  va_start(ap, format);
245
 
 
246
 
  node->value.text.whitespace = whitespace;
247
 
  node->value.text.string     = mxml_strdupf(format, ap);
248
 
 
249
 
  va_end(ap);
250
 
 
251
 
  return (0);
252
 
}
253
 
 
254
 
 
255
 
/*
256
 
 * End of "$Id: mxml-set.c 22267 2006-04-24 17:11:45Z kpfleming $".
257
 
 */