/home/dko/projects/mobilec/trunk/src/mxml-2.2.2/mxml.h

Go to the documentation of this file.
00001 /*
00002  * "$Id: mxml.h,v 1.1 2007/05/23 20:43:28 david_ko Exp $"
00003  *
00004  * Header file for Mini-XML, a small XML-like file parsing library.
00005  *
00006  * Copyright 2003-2005 by Michael Sweet.
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  */
00018 
00019 /*
00020  * Prevent multiple inclusion...
00021  */
00022 
00023 #ifndef _mxml_h_
00024 #  define _mxml_h_
00025 
00026 /*
00027  * Include necessary headers...
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  * Constants...
00039  */
00040 
00041 #  define MXML_WRAP             72      /* Wrap XML output at this column position */
00042 #  define MXML_TAB              8       /* Tabs every N columns */
00043 
00044 #  define MXML_NO_CALLBACK      0       /* Don't use a type callback */
00045 #  define MXML_INTEGER_CALLBACK mxml_integer_cb
00046                                         /* Treat all data as integers */
00047 #  define MXML_OPAQUE_CALLBACK  mxml_opaque_cb
00048                                         /* Treat all data as opaque */
00049 #  define MXML_REAL_CALLBACK    mxml_real_cb
00050                                         /* Treat all data as real numbers */
00051 #  define MXML_TEXT_CALLBACK    0       /* Treat all data as text */
00052 
00053 #  define MXML_NO_PARENT        0       /* No parent for the node */
00054 
00055 #  define MXML_DESCEND          1       /* Descend when finding/walking */
00056 #  define MXML_NO_DESCEND       0       /* Don't descend when finding/walking */
00057 #  define MXML_DESCEND_FIRST    -1      /* Descend for first find */
00058 
00059 #  define MXML_WS_BEFORE_OPEN   0       /* Callback for before open tag */
00060 #  define MXML_WS_AFTER_OPEN    1       /* Callback for after open tag */
00061 #  define MXML_WS_BEFORE_CLOSE  2       /* Callback for before close tag */
00062 #  define MXML_WS_AFTER_CLOSE   3       /* Callback for after close tag */
00063 
00064 #  define MXML_ADD_BEFORE       0       /* Add node before specified node */
00065 #  define MXML_ADD_AFTER        1       /* Add node after specified node */
00066 #  define MXML_ADD_TO_PARENT    NULL    /* Add node relative to parent */
00067 
00068 
00069 /*
00070  * Data types...
00071  */
00072 
00073 typedef enum mxml_type_e                /**** The XML node type. ****/
00074 {
00075   MXML_ELEMENT,                         /* XML element with attributes */
00076   MXML_INTEGER,                         /* Integer value */
00077   MXML_OPAQUE,                          /* Opaque string */
00078   MXML_REAL,                            /* Real value */
00079   MXML_TEXT,                            /* Text fragment */
00080   MXML_CUSTOM                           /* Custom data */
00081 } mxml_type_t;
00082 
00083 typedef struct mxml_attr_s              /**** An XML element attribute value. ****/
00084 {
00085   char                  *name;          /* Attribute name */
00086   char                  *value;         /* Attribute value */
00087 } mxml_attr_t;
00088 
00089 typedef struct mxml_value_s             /**** An XML element value. ****/
00090 {
00091   char                  *name;          /* Name of element */
00092   int                   num_attrs;      /* Number of attributes */
00093   mxml_attr_t           *attrs;         /* Attributes */
00094 } mxml_element_t;
00095 
00096 typedef struct mxml_text_s              /**** An XML text value. ****/
00097 {
00098   int                   whitespace;     /* Leading whitespace? */
00099   char                  *string;        /* Fragment string */
00100 } mxml_text_t;
00101 
00102 typedef struct mxml_custom_s            /**** An XML custom value. ****/
00103 {
00104   void                  *data;          /* Pointer to (allocated) custom data */
00105   void                  (*destroy)(void *);
00106                                         /* Pointer to destructor function */
00107 } mxml_custom_t;
00108 
00109 typedef union mxml_value_u              /**** An XML node value. ****/
00110 {
00111   mxml_element_t        element;        /* Element */
00112   int                   integer;        /* Integer number */
00113   char                  *opaque;        /* Opaque string */
00114   double                real;           /* Real number */
00115   mxml_text_t           text;           /* Text fragment */
00116   mxml_custom_t         custom;         /* Custom data */
00117 } mxml_value_t;
00118 
00119 typedef struct mxml_node_s              /**** An XML node. ****/
00120 {
00121   mxml_type_t           type;           /* Node type */
00122   struct mxml_node_s    *next;          /* Next node under same parent */
00123   struct mxml_node_s    *prev;          /* Previous node under same parent */
00124   struct mxml_node_s    *parent;        /* Parent node */
00125   struct mxml_node_s    *child;         /* First child node */
00126   struct mxml_node_s    *last_child;    /* Last child node */
00127   mxml_value_t          value;          /* Node value */
00128 } mxml_node_t;
00129 
00130 typedef struct mxml_index_s             /**** An XML node index. ****/
00131 {
00132   char                  *attr;          /* Attribute used for indexing or NULL */
00133   int                   num_nodes;      /* Number of nodes in index */
00134   int                   alloc_nodes;    /* Allocated nodes in index */
00135   int                   cur_node;       /* Current node */
00136   mxml_node_t           **nodes;        /* Node array */
00137 } mxml_index_t;
00138 
00139 typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *);
00140                                         /**** Custom data load callback function ****/
00141 
00142 typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *);  
00143                                         /**** Custom data save callback function ****/
00144 
00145 
00146 /*
00147  * C++ support...
00148  */
00149 
00150 #  ifdef __cplusplus
00151 extern "C" {
00152 #  endif /* __cplusplus */
00153 
00154 /*
00155  * Prototypes...
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 /* __GNUC__ */
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 /* __GNUC__ */
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  * Private functions...
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  * C++ support...
00244  */
00245 
00246 #  ifdef __cplusplus
00247 }
00248 #  endif /* __cplusplus */
00249 #endif /* !_mxml_h_ */
00250 
00251 
00252 /*
00253  * End of "$Id: mxml.h,v 1.1 2007/05/23 20:43:28 david_ko Exp $".
00254  */

Generated on Fri May 16 14:49:54 2008 for Mobile-C by  doxygen 1.5.4