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_WRAP 72
00042 # define MXML_TAB 8
00043
00044 # define MXML_NO_CALLBACK 0
00045 # define MXML_INTEGER_CALLBACK mxml_integer_cb
00046
00047 # define MXML_OPAQUE_CALLBACK mxml_opaque_cb
00048
00049 # define MXML_REAL_CALLBACK mxml_real_cb
00050
00051 # define MXML_TEXT_CALLBACK 0
00052
00053 # define MXML_NO_PARENT 0
00054
00055 # define MXML_DESCEND 1
00056 # define MXML_NO_DESCEND 0
00057 # define MXML_DESCEND_FIRST -1
00058
00059 # define MXML_WS_BEFORE_OPEN 0
00060 # define MXML_WS_AFTER_OPEN 1
00061 # define MXML_WS_BEFORE_CLOSE 2
00062 # define MXML_WS_AFTER_CLOSE 3
00063
00064 # define MXML_ADD_BEFORE 0
00065 # define MXML_ADD_AFTER 1
00066 # define MXML_ADD_TO_PARENT NULL
00067
00068
00069
00070
00071
00072
00073 typedef enum mxml_type_e
00074 {
00075 MXML_ELEMENT,
00076 MXML_INTEGER,
00077 MXML_OPAQUE,
00078 MXML_REAL,
00079 MXML_TEXT,
00080 MXML_CUSTOM
00081 } mxml_type_t;
00082
00083 typedef struct mxml_attr_s
00084 {
00085 char *name;
00086 char *value;
00087 } mxml_attr_t;
00088
00089 typedef struct mxml_value_s
00090 {
00091 char *name;
00092 int num_attrs;
00093 mxml_attr_t *attrs;
00094 } mxml_element_t;
00095
00096 typedef struct mxml_text_s
00097 {
00098 int whitespace;
00099 char *string;
00100 } mxml_text_t;
00101
00102 typedef struct mxml_custom_s
00103 {
00104 void *data;
00105 void (*destroy)(void *);
00106
00107 } mxml_custom_t;
00108
00109 typedef union mxml_value_u
00110 {
00111 mxml_element_t element;
00112 int integer;
00113 char *opaque;
00114 double real;
00115 mxml_text_t text;
00116 mxml_custom_t custom;
00117 } mxml_value_t;
00118
00119 typedef struct mxml_node_s
00120 {
00121 mxml_type_t type;
00122 struct mxml_node_s *next;
00123 struct mxml_node_s *prev;
00124 struct mxml_node_s *parent;
00125 struct mxml_node_s *child;
00126 struct mxml_node_s *last_child;
00127 mxml_value_t value;
00128 } mxml_node_t;
00129
00130 typedef struct mxml_index_s
00131 {
00132 char *attr;
00133 int num_nodes;
00134 int alloc_nodes;
00135 int cur_node;
00136 mxml_node_t **nodes;
00137 } mxml_index_t;
00138
00139 typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *);
00140
00141
00142 typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *);
00143
00144
00145
00146
00147
00148
00149
00150 # ifdef __cplusplus
00151 extern "C" {
00152 # endif
00153
00154
00155
00156
00157
00158 extern void mxmlAdd(mxml_node_t *parent, int where,
00159 mxml_node_t *child, mxml_node_t *node);
00160 extern void mxmlDelete(mxml_node_t *node);
00161 extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
00162 extern void mxmlElementSetAttr(mxml_node_t *node, const char *name,
00163 const char *value);
00164 extern int mxmlEntityAddCallback(int (*cb)(const char *name));
00165 extern const char *mxmlEntityGetName(int val);
00166 extern int mxmlEntityGetValue(const char *name);
00167 extern void mxmlEntityRemoveCallback(int (*cb)(const char *name));
00168 extern mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top,
00169 const char *name, const char *attr,
00170 const char *value, int descend);
00171 extern void mxmlIndexDelete(mxml_index_t *ind);
00172 extern mxml_node_t *mxmlIndexEnum(mxml_index_t *ind);
00173 extern mxml_node_t *mxmlIndexFind(mxml_index_t *ind,
00174 const char *element,
00175 const char *value);
00176 extern mxml_index_t *mxmlIndexNew(mxml_node_t *node, const char *element,
00177 const char *attr);
00178 extern mxml_node_t *mxmlIndexReset(mxml_index_t *ind);
00179 extern mxml_node_t *mxmlLoadFd(mxml_node_t *top, int fd,
00180 mxml_type_t (*cb)(mxml_node_t *));
00181 extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp,
00182 mxml_type_t (*cb)(mxml_node_t *));
00183 extern mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s,
00184 mxml_type_t (*cb)(mxml_node_t *));
00185 extern mxml_node_t *mxmlNewCustom(mxml_node_t *parent, void *data,
00186 void (*destroy)(void *));
00187 extern mxml_node_t *mxmlNewElement(mxml_node_t *parent, const char *name);
00188 extern mxml_node_t *mxmlNewInteger(mxml_node_t *parent, int integer);
00189 extern mxml_node_t *mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
00190 extern mxml_node_t *mxmlNewReal(mxml_node_t *parent, double real);
00191 extern mxml_node_t *mxmlNewText(mxml_node_t *parent, int whitespace,
00192 const char *string);
00193 extern mxml_node_t *mxmlNewTextf(mxml_node_t *parent, int whitespace,
00194 const char *format, ...)
00195 # ifdef __GNUC__
00196 __attribute__ ((__format__ (__printf__, 3, 4)))
00197 # endif
00198 ;
00199 extern void mxmlRemove(mxml_node_t *node);
00200 extern char *mxmlSaveAllocString(mxml_node_t *node,
00201 const char *(*cb)(mxml_node_t *, int));
00202 extern int mxmlSaveFd(mxml_node_t *node, int fd,
00203 const char *(*cb)(mxml_node_t *, int));
00204 extern int mxmlSaveFile(mxml_node_t *node, FILE *fp,
00205 const char *(*cb)(mxml_node_t *, int));
00206 extern int mxmlSaveString(mxml_node_t *node, char *buffer,
00207 int bufsize,
00208 const char *(*cb)(mxml_node_t *, int));
00209 extern int mxmlSetCustom(mxml_node_t *node, void *data,
00210 void (*destroy)(void *));
00211 extern void mxmlSetCustomHandlers(mxml_custom_load_cb_t load,
00212 mxml_custom_save_cb_t save);
00213 extern int mxmlSetElement(mxml_node_t *node, const char *name);
00214 extern void mxmlSetErrorCallback(void (*cb)(const char *));
00215 extern int mxmlSetInteger(mxml_node_t *node, int integer);
00216 extern int mxmlSetOpaque(mxml_node_t *node, const char *opaque);
00217 extern int mxmlSetReal(mxml_node_t *node, double real);
00218 extern int mxmlSetText(mxml_node_t *node, int whitespace,
00219 const char *string);
00220 extern int mxmlSetTextf(mxml_node_t *node, int whitespace,
00221 const char *format, ...)
00222 # ifdef __GNUC__
00223 __attribute__ ((__format__ (__printf__, 3, 4)))
00224 # endif
00225 ;
00226 extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top,
00227 int descend);
00228 extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,
00229 int descend);
00230
00231
00232
00233
00234
00235
00236 extern void mxml_error(const char *format, ...);
00237 extern mxml_type_t mxml_integer_cb(mxml_node_t *node);
00238 extern mxml_type_t mxml_opaque_cb(mxml_node_t *node);
00239 extern mxml_type_t mxml_real_cb(mxml_node_t *node);
00240
00241
00242
00243
00244
00245
00246 # ifdef __cplusplus
00247 }
00248 # endif
00249 #endif
00250
00251
00252
00253
00254