/home/dko/projects/mobilec/tags/MobileC-v1.10.2/MobileC-v1.10.2/src/mxml-2.2.2/mxml.h

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

Generated on Fri Jul 11 17:59:45 2008 for Mobile-C by  doxygen 1.5.4