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