00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _mxml_h_
00024 # define _mxml_h_
00025
00026
00027
00028
00029
00030 # include <stdio.h>
00031 # include <stdlib.h>
00032 # include <string.h>
00033 # include <ctype.h>
00034 # include <errno.h>
00035
00036
00037
00038
00039
00040
00041 # define MXML_TAB 8
00042
00043 # define MXML_NO_CALLBACK 0
00044 # define MXML_INTEGER_CALLBACK mxml_integer_cb
00045
00046 # define MXML_OPAQUE_CALLBACK mxml_opaque_cb
00047
00048 # define MXML_REAL_CALLBACK mxml_real_cb
00049
00050 # define MXML_TEXT_CALLBACK 0
00051 # define MXML_IGNORE_CALLBACK mxml_ignore_cb
00052
00053
00054 # define MXML_NO_PARENT 0
00055
00056 # define MXML_DESCEND 1
00057 # define MXML_NO_DESCEND 0
00058 # define MXML_DESCEND_FIRST -1
00059
00060 # define MXML_WS_BEFORE_OPEN 0
00061 # define MXML_WS_AFTER_OPEN 1
00062 # define MXML_WS_BEFORE_CLOSE 2
00063 # define MXML_WS_AFTER_CLOSE 3
00064
00065 # define MXML_ADD_BEFORE 0
00066 # define MXML_ADD_AFTER 1
00067 # define MXML_ADD_TO_PARENT NULL
00068
00069
00070
00071
00072
00073
00074 typedef enum mxml_sax_event_e
00075 {
00076 MXML_SAX_CDATA,
00077 MXML_SAX_COMMENT,
00078 MXML_SAX_DATA,
00079 MXML_SAX_DIRECTIVE,
00080 MXML_SAX_ELEMENT_CLOSE,
00081 MXML_SAX_ELEMENT_OPEN
00082 } mxml_sax_event_t;
00083
00084 typedef enum mxml_type_e
00085 {
00086 MXML_IGNORE = -1,
00087 MXML_ELEMENT,
00088 MXML_INTEGER,
00089 MXML_OPAQUE,
00090 MXML_REAL,
00091 MXML_TEXT,
00092 MXML_CUSTOM
00093 } mxml_type_t;
00094
00095 typedef void (*mxml_custom_destroy_cb_t)(void *);
00096
00097
00098 typedef void (*mxml_error_cb_t)(const char *);
00099
00100
00101 typedef struct mxml_attr_s
00102 {
00103 char *name;
00104 char *value;
00105 } mxml_attr_t;
00106
00107 typedef struct mxml_element_s
00108 {
00109 char *name;
00110 int num_attrs;
00111 mxml_attr_t *attrs;
00112 } mxml_element_t;
00113
00114 typedef struct mxml_text_s
00115 {
00116 int whitespace;
00117 char *string;
00118 } mxml_text_t;
00119
00120 typedef struct mxml_custom_s
00121 {
00122 void *data;
00123 mxml_custom_destroy_cb_t destroy;
00124 } mxml_custom_t;
00125
00126 typedef union mxml_value_u
00127 {
00128 mxml_element_t element;
00129 int integer;
00130 char *opaque;
00131 double real;
00132 mxml_text_t text;
00133 mxml_custom_t custom;
00134 } mxml_value_t;
00135
00136 typedef struct mxml_node_s
00137 {
00138 mxml_type_t type;
00139 struct mxml_node_s *next;
00140 struct mxml_node_s *prev;
00141 struct mxml_node_s *parent;
00142 struct mxml_node_s *child;
00143 struct mxml_node_s *last_child;
00144 mxml_value_t value;
00145 int ref_count;
00146 void *user_data;
00147 } mxml_node_t;
00148
00149 typedef struct mxml_index_s
00150 {
00151 char *attr;
00152 int num_nodes;
00153 int alloc_nodes;
00154 int cur_node;
00155 mxml_node_t **nodes;
00156 } mxml_index_t;
00157
00158 typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *);
00159
00160
00161 typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *);
00162
00163
00164 typedef mxml_type_t (*mxml_load_cb_t)(mxml_node_t *);
00165
00166
00167 typedef const char *(*mxml_save_cb_t)(mxml_node_t *, int);
00168
00169
00170 typedef void (*mxml_sax_cb_t)(mxml_node_t *, mxml_sax_event_t, void *);
00171
00172
00173
00174
00175
00176
00177
00178 # ifdef __cplusplus
00179 extern "C" {
00180 # endif
00181
00182
00183
00184
00185
00186 extern void mxmlAdd(mxml_node_t *parent, int where,
00187 mxml_node_t *child, mxml_node_t *node);
00188 extern void mxmlDelete(mxml_node_t *node);
00189 extern void mxmlElementDeleteAttr(mxml_node_t *node,
00190 const char *name);
00191 extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
00192 extern void mxmlElementSetAttr(mxml_node_t *node, const char *name,
00193 const char *value);
00194 extern void mxmlElementSetAttrf(mxml_node_t *node, const char *name,
00195 const char *format, ...)
00196 # ifdef __GNUC__
00197 __attribute__ ((__format__ (__printf__, 3, 4)))
00198 # endif
00199 ;
00200 extern int mxmlEntityAddCallback(int (*cb)(const char *name));
00201 extern const char *mxmlEntityGetName(int val);
00202 extern int mxmlEntityGetValue(const char *name);
00203 extern void mxmlEntityRemoveCallback(int (*cb)(const char *name));
00204 extern mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top,
00205 const char *name, const char *attr,
00206 const char *value, int descend);
00207 extern void mxmlIndexDelete(mxml_index_t *ind);
00208 extern mxml_node_t *mxmlIndexEnum(mxml_index_t *ind);
00209 extern mxml_node_t *mxmlIndexFind(mxml_index_t *ind,
00210 const char *element,
00211 const char *value);
00212 extern mxml_index_t *mxmlIndexNew(mxml_node_t *node, const char *element,
00213 const char *attr);
00214 extern mxml_node_t *mxmlIndexReset(mxml_index_t *ind);
00215 extern mxml_node_t *mxmlLoadFd(mxml_node_t *top, int fd,
00216 mxml_type_t (*cb)(mxml_node_t *));
00217 extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp,
00218 mxml_type_t (*cb)(mxml_node_t *));
00219 extern mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s,
00220 mxml_type_t (*cb)(mxml_node_t *));
00221 extern mxml_node_t *mxmlNewCDATA(mxml_node_t *parent, const char *string);
00222 extern mxml_node_t *mxmlNewCustom(mxml_node_t *parent, void *data,
00223 mxml_custom_destroy_cb_t destroy);
00224 extern mxml_node_t *mxmlNewElement(mxml_node_t *parent, const char *name);
00225 extern mxml_node_t *mxmlNewInteger(mxml_node_t *parent, int integer);
00226 extern mxml_node_t *mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
00227 extern mxml_node_t *mxmlNewReal(mxml_node_t *parent, double real);
00228 extern mxml_node_t *mxmlNewText(mxml_node_t *parent, int whitespace,
00229 const char *string);
00230 extern mxml_node_t *mxmlNewTextf(mxml_node_t *parent, int whitespace,
00231 const char *format, ...)
00232 # ifdef __GNUC__
00233 __attribute__ ((__format__ (__printf__, 3, 4)))
00234 # endif
00235 ;
00236 extern mxml_node_t *mxmlNewXML(const char *version);
00237 extern int mxmlRelease(mxml_node_t *node);
00238 extern void mxmlRemove(mxml_node_t *node);
00239 extern int mxmlRetain(mxml_node_t *node);
00240 extern char *mxmlSaveAllocString(mxml_node_t *node,
00241 mxml_save_cb_t cb);
00242 extern int mxmlSaveFd(mxml_node_t *node, int fd,
00243 mxml_save_cb_t cb);
00244 extern int mxmlSaveFile(mxml_node_t *node, FILE *fp,
00245 mxml_save_cb_t cb);
00246 extern int mxmlSaveString(mxml_node_t *node, char *buffer,
00247 int bufsize, mxml_save_cb_t cb);
00248 extern mxml_node_t *mxmlSAXLoadFd(mxml_node_t *top, int fd,
00249 mxml_type_t (*cb)(mxml_node_t *),
00250 mxml_sax_cb_t sax, void *sax_data);
00251 extern mxml_node_t *mxmlSAXLoadFile(mxml_node_t *top, FILE *fp,
00252 mxml_type_t (*cb)(mxml_node_t *),
00253 mxml_sax_cb_t sax, void *sax_data);
00254 extern mxml_node_t *mxmlSAXLoadString(mxml_node_t *top, const char *s,
00255 mxml_type_t (*cb)(mxml_node_t *),
00256 mxml_sax_cb_t sax, void *sax_data);
00257 extern int mxmlSetCDATA(mxml_node_t *node, const char *data);
00258 extern int mxmlSetCustom(mxml_node_t *node, void *data,
00259 mxml_custom_destroy_cb_t destroy);
00260 extern void mxmlSetCustomHandlers(mxml_custom_load_cb_t load,
00261 mxml_custom_save_cb_t save);
00262 extern int mxmlSetElement(mxml_node_t *node, const char *name);
00263 extern void mxmlSetErrorCallback(mxml_error_cb_t cb);
00264 extern int mxmlSetInteger(mxml_node_t *node, int integer);
00265 extern int mxmlSetOpaque(mxml_node_t *node, const char *opaque);
00266 extern int mxmlSetReal(mxml_node_t *node, double real);
00267 extern int mxmlSetText(mxml_node_t *node, int whitespace,
00268 const char *string);
00269 extern int mxmlSetTextf(mxml_node_t *node, int whitespace,
00270 const char *format, ...)
00271 # ifdef __GNUC__
00272 __attribute__ ((__format__ (__printf__, 3, 4)))
00273 # endif
00274 ;
00275 extern void mxmlSetWrapMargin(int column);
00276 extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top,
00277 int descend);
00278 extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,
00279 int descend);
00280
00281
00282
00283
00284
00285
00286 extern void mxml_error(const char *format, ...);
00287 extern mxml_type_t mxml_ignore_cb(mxml_node_t *node);
00288 extern mxml_type_t mxml_integer_cb(mxml_node_t *node);
00289 extern mxml_type_t mxml_opaque_cb(mxml_node_t *node);
00290 extern mxml_type_t mxml_real_cb(mxml_node_t *node);
00291
00292
00293
00294
00295
00296
00297 # ifdef __cplusplus
00298 }
00299 # endif
00300 #endif