Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

include/gimp-print/mxml.h

Go to the documentation of this file.
00001 /*
00002  * "$Id: mxml.h,v 1.2 2004/04/27 23:23:45 rlk Exp $"
00003  *
00004  * Header file for mini-XML, a small XML-like file parsing library.
00005  *
00006  * Copyright 2003 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 GIMP_PRINT_MXML_H
00024 #  define GIMP_PRINT_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 STP_MXML_WRAP         70      /* Wrap XML output at this column position */
00042 #  define STP_MXML_TAB          8       /* Tabs every N columns */
00043 
00044 #  define STP_MXML_NO_CALLBACK  0       /* Don't use a type callback */
00045 #  define STP_MXML_NO_PARENT    0       /* No parent for the node */
00046 
00047 #  define STP_MXML_DESCEND              1       /* Descend when finding/walking */
00048 #  define STP_MXML_NO_DESCEND   0       /* Don't descend when finding/walking */
00049 #  define STP_MXML_DESCEND_FIRST        -1      /* Descend for first find */
00050 
00051 #  define STP_MXML_WS_BEFORE_OPEN       0       /* Callback for before open tag */
00052 #  define STP_MXML_WS_AFTER_OPEN        1       /* Callback for after open tag */
00053 #  define STP_MXML_WS_BEFORE_CLOSE      2       /* Callback for before close tag */
00054 #  define STP_MXML_WS_AFTER_CLOSE       3       /* Callback for after close tag */
00055 
00056 #  define STP_MXML_ADD_BEFORE   0       /* Add node before specified node */
00057 #  define STP_MXML_ADD_AFTER    1       /* Add node after specified node */
00058 #  define STP_MXML_ADD_TO_PARENT        NULL    /* Add node relative to parent */
00059 
00060 
00061 /*
00062  * Data types...
00063  */
00064 
00065 typedef enum stp_mxml_type_e            /**** The XML node type. ****/
00066 {
00067   STP_MXML_ELEMENT,                             /* XML element with attributes */
00068   STP_MXML_INTEGER,                             /* Integer value */
00069   STP_MXML_OPAQUE,                              /* Opaque string */
00070   STP_MXML_REAL,                                /* Real value */
00071   STP_MXML_TEXT                         /* Text fragment */
00072 } stp_mxml_type_t;
00073 
00074 typedef struct stp_mxml_attr_s          /**** An XML element attribute value. ****/
00075 {
00076   char  *name;                          /* Attribute name */
00077   char  *value;                         /* Attribute value */
00078 } stp_mxml_attr_t;
00079 
00080 typedef struct stp_mxml_value_s         /**** An XML element value. ****/
00081 {
00082   char          *name;                  /* Name of element */
00083   int           num_attrs;              /* Number of attributes */
00084   stp_mxml_attr_t       *attrs;                 /* Attributes */
00085 } stp_mxml_element_t;
00086 
00087 typedef struct stp_mxml_text_s          /**** An XML text value. ****/
00088 {
00089   int           whitespace;             /* Leading whitespace? */
00090   char          *string;                /* Fragment string */
00091 } stp_mxml_text_t;
00092 
00093 typedef union stp_mxml_value_u          /**** An XML node value. ****/
00094 {
00095   stp_mxml_element_t    element;        /* Element */
00096   int                   integer;        /* Integer number */
00097   char                  *opaque;        /* Opaque string */
00098   double                real;           /* Real number */
00099   stp_mxml_text_t               text;           /* Text fragment */
00100 } stp_mxml_value_t;
00101 
00102 typedef struct stp_mxml_node_s stp_mxml_node_t; /**** An XML node. ****/
00103 
00104 struct stp_mxml_node_s                  /**** An XML node. ****/
00105 {
00106   stp_mxml_type_t       type;                   /* Node type */
00107   stp_mxml_node_t       *next;                  /* Next node under same parent */
00108   stp_mxml_node_t       *prev;                  /* Previous node under same parent */
00109   stp_mxml_node_t       *parent;                /* Parent node */
00110   stp_mxml_node_t       *child;                 /* First child node */
00111   stp_mxml_node_t       *last_child;            /* Last child node */
00112   stp_mxml_value_t      value;                  /* Node value */
00113 };
00114 
00115 
00116 /*
00117  * C++ support...
00118  */
00119 
00120 #  ifdef __cplusplus
00121 extern "C" {
00122 #  endif /* __cplusplus */
00123 
00124 /*
00125  * Prototypes...
00126  */
00127 
00128 extern void             stp_mxmlAdd(stp_mxml_node_t *parent, int where,
00129                                 stp_mxml_node_t *child, stp_mxml_node_t *node);
00130 extern void             stp_mxmlDelete(stp_mxml_node_t *node);
00131 extern const char       *stp_mxmlElementGetAttr(stp_mxml_node_t *node, const char *name);
00132 extern void             stp_mxmlElementSetAttr(stp_mxml_node_t *node, const char *name,
00133                                            const char *value);
00134 extern stp_mxml_node_t  *stp_mxmlFindElement(stp_mxml_node_t *node, stp_mxml_node_t *top,
00135                                          const char *name, const char *attr,
00136                                          const char *value, int descend);
00137 extern stp_mxml_node_t  *stp_mxmlLoadFile(stp_mxml_node_t *top, FILE *fp,
00138                                       stp_mxml_type_t (*cb)(stp_mxml_node_t *));
00139 extern stp_mxml_node_t  *stp_mxmlLoadString(stp_mxml_node_t *top, const char *s,
00140                                         stp_mxml_type_t (*cb)(stp_mxml_node_t *));
00141 extern stp_mxml_node_t  *stp_mxmlNewElement(stp_mxml_node_t *parent, const char *name);
00142 extern stp_mxml_node_t  *stp_mxmlNewInteger(stp_mxml_node_t *parent, int integer);
00143 extern stp_mxml_node_t  *stp_mxmlNewOpaque(stp_mxml_node_t *parent, const char *opaque);
00144 extern stp_mxml_node_t  *stp_mxmlNewReal(stp_mxml_node_t *parent, double real);
00145 extern stp_mxml_node_t  *stp_mxmlNewText(stp_mxml_node_t *parent, int whitespace,
00146                                      const char *string);
00147 extern void             stp_mxmlRemove(stp_mxml_node_t *node);
00148 extern char             *stp_mxmlSaveAllocString(stp_mxml_node_t *node,
00149                                              int (*cb)(stp_mxml_node_t *, int));
00150 extern int              stp_mxmlSaveFile(stp_mxml_node_t *node, FILE *fp,
00151                                      int (*cb)(stp_mxml_node_t *, int));
00152 extern int              stp_mxmlSaveString(stp_mxml_node_t *node, char *buffer,
00153                                        int bufsize,
00154                                        int (*cb)(stp_mxml_node_t *, int));
00155 extern stp_mxml_node_t  *stp_mxmlWalkNext(stp_mxml_node_t *node, stp_mxml_node_t *top,
00156                                       int descend);
00157 extern stp_mxml_node_t  *stp_mxmlWalkPrev(stp_mxml_node_t *node, stp_mxml_node_t *top,
00158                                       int descend);
00159 
00160 
00161 /*
00162  * C++ support...
00163  */
00164 
00165 #  ifdef __cplusplus
00166 }
00167 #  endif /* __cplusplus */
00168 #endif /* !GIMP_PRINT_MXML_H */
00169 
00170 
00171 /*
00172  * End of "$Id: mxml.h,v 1.2 2004/04/27 23:23:45 rlk Exp $".
00173  */

Generated on Wed Aug 25 07:56:13 2004 for libgimpprint API Reference by doxygen 1.3.6