2003-06-03 19:46:29 +00:00
|
|
|
/*
|
2004-04-06 01:47:20 +00:00
|
|
|
* "$Id: mxml.h,v 1.17 2004/04/06 01:47:20 mike Exp $"
|
2003-06-03 19:46:29 +00:00
|
|
|
*
|
2003-06-03 20:24:28 +00:00
|
|
|
* Header file for mini-XML, a small XML-like file parsing library.
|
2003-06-03 19:46:29 +00:00
|
|
|
*
|
2004-04-06 01:47:20 +00:00
|
|
|
* Copyright 2003-2004 by Michael Sweet.
|
2003-06-03 19:46:29 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prevent multiple inclusion...
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _mxml_h_
|
|
|
|
# define _mxml_h_
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Include necessary headers...
|
|
|
|
*/
|
|
|
|
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <string.h>
|
2003-06-04 00:30:04 +00:00
|
|
|
# include <ctype.h>
|
2003-06-04 16:30:40 +00:00
|
|
|
# include <errno.h>
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constants...
|
|
|
|
*/
|
|
|
|
|
2003-06-04 16:30:40 +00:00
|
|
|
# define MXML_WRAP 72 /* Wrap XML output at this column position */
|
2003-06-04 21:19:00 +00:00
|
|
|
# define MXML_TAB 8 /* Tabs every N columns */
|
|
|
|
|
|
|
|
# define MXML_NO_CALLBACK 0 /* Don't use a type callback */
|
2003-09-28 21:09:04 +00:00
|
|
|
# define MXML_INTEGER_CALLBACK mxml_integer_cb
|
|
|
|
/* Treat all data as integers */
|
|
|
|
# define MXML_OPAQUE_CALLBACK mxml_opaque_cb
|
2003-09-28 12:44:39 +00:00
|
|
|
/* Treat all data as opaque */
|
2003-09-28 21:09:04 +00:00
|
|
|
# define MXML_REAL_CALLBACK mxml_real_cb
|
|
|
|
/* Treat all data as real numbers */
|
|
|
|
# define MXML_TEXT_CALLBACK 0 /* Treat all data as text */
|
|
|
|
|
2003-06-04 21:19:00 +00:00
|
|
|
# define MXML_NO_PARENT 0 /* No parent for the node */
|
2003-06-04 16:30:40 +00:00
|
|
|
|
|
|
|
# define MXML_DESCEND 1 /* Descend when finding/walking */
|
|
|
|
# define MXML_NO_DESCEND 0 /* Don't descend when finding/walking */
|
|
|
|
# define MXML_DESCEND_FIRST -1 /* Descend for first find */
|
2003-06-03 19:46:29 +00:00
|
|
|
|
2003-06-04 21:19:00 +00:00
|
|
|
# define MXML_WS_BEFORE_OPEN 0 /* Callback for before open tag */
|
|
|
|
# define MXML_WS_AFTER_OPEN 1 /* Callback for after open tag */
|
|
|
|
# define MXML_WS_BEFORE_CLOSE 2 /* Callback for before close tag */
|
|
|
|
# define MXML_WS_AFTER_CLOSE 3 /* Callback for after close tag */
|
2003-06-04 17:37:23 +00:00
|
|
|
|
|
|
|
# define MXML_ADD_BEFORE 0 /* Add node before specified node */
|
|
|
|
# define MXML_ADD_AFTER 1 /* Add node after specified node */
|
|
|
|
# define MXML_ADD_TO_PARENT NULL /* Add node relative to parent */
|
|
|
|
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Data types...
|
|
|
|
*/
|
|
|
|
|
2003-06-14 23:56:47 +00:00
|
|
|
typedef enum mxml_type_e /**** The XML node type. ****/
|
2003-06-03 19:46:29 +00:00
|
|
|
{
|
|
|
|
MXML_ELEMENT, /* XML element with attributes */
|
|
|
|
MXML_INTEGER, /* Integer value */
|
|
|
|
MXML_OPAQUE, /* Opaque string */
|
|
|
|
MXML_REAL, /* Real value */
|
2003-06-19 03:39:23 +00:00
|
|
|
MXML_TEXT /* Text fragment */
|
2003-06-03 19:46:29 +00:00
|
|
|
} mxml_type_t;
|
|
|
|
|
2003-06-14 23:56:47 +00:00
|
|
|
typedef struct mxml_attr_s /**** An XML element attribute value. ****/
|
2003-06-03 19:46:29 +00:00
|
|
|
{
|
2003-06-19 03:20:41 +00:00
|
|
|
char *name; /* Attribute name */
|
|
|
|
char *value; /* Attribute value */
|
2003-06-03 19:46:29 +00:00
|
|
|
} mxml_attr_t;
|
|
|
|
|
2003-06-14 23:56:47 +00:00
|
|
|
typedef struct mxml_value_s /**** An XML element value. ****/
|
2003-06-03 19:46:29 +00:00
|
|
|
{
|
2003-06-19 03:20:41 +00:00
|
|
|
char *name; /* Name of element */
|
|
|
|
int num_attrs; /* Number of attributes */
|
|
|
|
mxml_attr_t *attrs; /* Attributes */
|
2003-06-03 19:46:29 +00:00
|
|
|
} mxml_element_t;
|
|
|
|
|
2003-06-14 23:56:47 +00:00
|
|
|
typedef struct mxml_text_s /**** An XML text value. ****/
|
2003-06-07 21:27:05 +00:00
|
|
|
{
|
2003-06-19 03:20:41 +00:00
|
|
|
int whitespace; /* Leading whitespace? */
|
|
|
|
char *string; /* Fragment string */
|
2003-06-07 21:27:05 +00:00
|
|
|
} mxml_text_t;
|
|
|
|
|
2003-06-14 23:56:47 +00:00
|
|
|
typedef union mxml_value_u /**** An XML node value. ****/
|
2003-06-07 21:27:05 +00:00
|
|
|
{
|
|
|
|
mxml_element_t element; /* Element */
|
|
|
|
int integer; /* Integer number */
|
|
|
|
char *opaque; /* Opaque string */
|
|
|
|
double real; /* Real number */
|
|
|
|
mxml_text_t text; /* Text fragment */
|
|
|
|
} mxml_value_t;
|
|
|
|
|
2003-09-28 21:09:04 +00:00
|
|
|
typedef struct mxml_node_s /**** An XML node. ****/
|
2003-06-03 19:46:29 +00:00
|
|
|
{
|
2003-06-19 03:20:41 +00:00
|
|
|
mxml_type_t type; /* Node type */
|
2003-09-28 21:09:04 +00:00
|
|
|
struct mxml_node_s *next; /* Next node under same parent */
|
|
|
|
struct mxml_node_s *prev; /* Previous node under same parent */
|
|
|
|
struct mxml_node_s *parent; /* Parent node */
|
|
|
|
struct mxml_node_s *child; /* First child node */
|
|
|
|
struct mxml_node_s *last_child; /* Last child node */
|
2003-06-19 03:20:41 +00:00
|
|
|
mxml_value_t value; /* Node value */
|
2003-09-28 21:09:04 +00:00
|
|
|
} mxml_node_t;
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* C++ support...
|
|
|
|
*/
|
|
|
|
|
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
# endif /* __cplusplus */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes...
|
|
|
|
*/
|
|
|
|
|
2003-06-04 17:37:23 +00:00
|
|
|
extern void mxmlAdd(mxml_node_t *parent, int where,
|
|
|
|
mxml_node_t *child, mxml_node_t *node);
|
2003-06-03 19:46:29 +00:00
|
|
|
extern void mxmlDelete(mxml_node_t *node);
|
|
|
|
extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
|
|
|
|
extern void mxmlElementSetAttr(mxml_node_t *node, const char *name,
|
|
|
|
const char *value);
|
2003-12-18 04:16:37 +00:00
|
|
|
extern const char *mxmlEntityGetName(int val);
|
|
|
|
extern int mxmlEntityGetValue(const char *name);
|
2003-06-03 19:46:29 +00:00
|
|
|
extern mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top,
|
2003-06-04 16:30:40 +00:00
|
|
|
const char *name, const char *attr,
|
|
|
|
const char *value, int descend);
|
2003-06-03 19:46:29 +00:00
|
|
|
extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp,
|
|
|
|
mxml_type_t (*cb)(mxml_node_t *));
|
2003-06-19 03:20:41 +00:00
|
|
|
extern mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s,
|
|
|
|
mxml_type_t (*cb)(mxml_node_t *));
|
2003-06-03 19:46:29 +00:00
|
|
|
extern mxml_node_t *mxmlNewElement(mxml_node_t *parent, const char *name);
|
|
|
|
extern mxml_node_t *mxmlNewInteger(mxml_node_t *parent, int integer);
|
|
|
|
extern mxml_node_t *mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
|
|
|
|
extern mxml_node_t *mxmlNewReal(mxml_node_t *parent, double real);
|
|
|
|
extern mxml_node_t *mxmlNewText(mxml_node_t *parent, int whitespace,
|
|
|
|
const char *string);
|
2003-09-28 12:44:39 +00:00
|
|
|
extern mxml_node_t *mxmlNewTextf(mxml_node_t *parent, int whitespace,
|
|
|
|
const char *format, ...)
|
|
|
|
# ifdef __GNUC__
|
|
|
|
__attribute__ ((__format__ (__printf__, 3, 4)))
|
|
|
|
# endif /* __GNUC__ */
|
|
|
|
;
|
2003-06-04 17:37:23 +00:00
|
|
|
extern void mxmlRemove(mxml_node_t *node);
|
2003-07-22 10:29:19 +00:00
|
|
|
extern char *mxmlSaveAllocString(mxml_node_t *node,
|
|
|
|
int (*cb)(mxml_node_t *, int));
|
2003-06-04 17:37:23 +00:00
|
|
|
extern int mxmlSaveFile(mxml_node_t *node, FILE *fp,
|
|
|
|
int (*cb)(mxml_node_t *, int));
|
2003-06-19 03:20:41 +00:00
|
|
|
extern int mxmlSaveString(mxml_node_t *node, char *buffer,
|
|
|
|
int bufsize,
|
|
|
|
int (*cb)(mxml_node_t *, int));
|
2003-09-28 12:44:39 +00:00
|
|
|
extern int mxmlSetElement(mxml_node_t *node, const char *name);
|
2003-12-03 03:59:04 +00:00
|
|
|
extern void mxmlSetErrorCallback(void (*cb)(const char *));
|
2003-09-28 12:44:39 +00:00
|
|
|
extern int mxmlSetInteger(mxml_node_t *node, int integer);
|
|
|
|
extern int mxmlSetOpaque(mxml_node_t *node, const char *opaque);
|
|
|
|
extern int mxmlSetReal(mxml_node_t *node, double real);
|
|
|
|
extern int mxmlSetText(mxml_node_t *node, int whitespace,
|
|
|
|
const char *string);
|
|
|
|
extern int mxmlSetTextf(mxml_node_t *node, int whitespace,
|
|
|
|
const char *format, ...)
|
|
|
|
# ifdef __GNUC__
|
|
|
|
__attribute__ ((__format__ (__printf__, 3, 4)))
|
|
|
|
# endif /* __GNUC__ */
|
|
|
|
;
|
2003-06-04 16:30:40 +00:00
|
|
|
extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top,
|
|
|
|
int descend);
|
|
|
|
extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,
|
|
|
|
int descend);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
2003-09-28 12:44:39 +00:00
|
|
|
/*
|
|
|
|
* Private functions...
|
|
|
|
*/
|
|
|
|
|
2003-12-03 03:59:04 +00:00
|
|
|
extern void mxml_error(const char *format, ...);
|
|
|
|
extern mxml_type_t mxml_integer_cb(mxml_node_t *node);
|
|
|
|
extern mxml_type_t mxml_opaque_cb(mxml_node_t *node);
|
|
|
|
extern mxml_type_t mxml_real_cb(mxml_node_t *node);
|
2003-09-28 12:44:39 +00:00
|
|
|
|
|
|
|
|
2003-06-03 19:46:29 +00:00
|
|
|
/*
|
|
|
|
* C++ support...
|
|
|
|
*/
|
|
|
|
|
|
|
|
# ifdef __cplusplus
|
|
|
|
}
|
|
|
|
# endif /* __cplusplus */
|
|
|
|
#endif /* !_mxml_h_ */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-04-06 01:47:20 +00:00
|
|
|
* End of "$Id: mxml.h,v 1.17 2004/04/06 01:47:20 mike Exp $".
|
2003-06-03 19:46:29 +00:00
|
|
|
*/
|