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

mxml.h

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

Generated on Thu Feb 10 19:29:29 2005 for libgutenprint API Reference by  doxygen 1.4.1