2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// Private definitions for Mini-XML, a small XML file parsing library.
|
|
|
|
|
//
|
|
|
|
|
// https://www.msweet.org/mxml
|
|
|
|
|
//
|
|
|
|
|
// Copyright © 2003-2024 by Michael R Sweet.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
// information.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef MXML_PRIVATE_H
|
|
|
|
|
# define MXML_PRIVATE_H
|
2019-11-19 16:27:12 +00:00
|
|
|
|
# include "config.h"
|
|
|
|
|
# include "mxml.h"
|
2024-03-06 23:18:29 +00:00
|
|
|
|
# include <locale.h>
|
2007-09-21 04:46:02 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// Private macros...
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
# ifdef DEBUG
|
|
|
|
|
# define MXML_DEBUG(...) fprintf(stderr, __VA_ARGS__)
|
|
|
|
|
# else
|
|
|
|
|
# define MXML_DEBUG(...)
|
|
|
|
|
# endif // DEBUG
|
2024-04-21 21:08:39 +00:00
|
|
|
|
# ifndef MXML_ALLOC_SIZE
|
|
|
|
|
# define MXML_ALLOC_SIZE 16 // Allocation increment
|
|
|
|
|
# endif // !MXML_ALLOC_SIZE
|
2024-03-07 01:03:48 +00:00
|
|
|
|
# define MXML_TAB 8 // Tabs every N columns
|
2024-02-27 20:04:27 +00:00
|
|
|
|
|
2007-09-21 04:46:02 +00:00
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// Private structures...
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
typedef struct _mxml_attr_s // An XML element attribute value.
|
2019-01-05 01:02:48 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
char *name; // Attribute name
|
|
|
|
|
char *value; // Attribute value
|
2019-01-05 01:02:48 +00:00
|
|
|
|
} _mxml_attr_t;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
typedef struct _mxml_element_s // An XML element value.
|
2019-01-05 01:02:48 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
char *name; // Name of element
|
2024-03-02 23:47:57 +00:00
|
|
|
|
size_t num_attrs; // Number of attributes
|
2024-02-27 20:04:27 +00:00
|
|
|
|
_mxml_attr_t *attrs; // Attributes
|
2019-01-05 01:02:48 +00:00
|
|
|
|
} _mxml_element_t;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
typedef struct _mxml_text_s // An XML text value.
|
2019-01-05 01:02:48 +00:00
|
|
|
|
{
|
2024-03-02 23:47:57 +00:00
|
|
|
|
bool whitespace; // Leading whitespace?
|
2024-02-27 20:04:27 +00:00
|
|
|
|
char *string; // Fragment string
|
2019-01-05 01:02:48 +00:00
|
|
|
|
} _mxml_text_t;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
typedef struct _mxml_custom_s // An XML custom value.
|
2019-01-05 01:02:48 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
void *data; // Pointer to (allocated) custom data
|
2024-03-19 01:46:14 +00:00
|
|
|
|
mxml_custfree_cb_t free_cb; // Free callback function
|
|
|
|
|
void *free_cbdata; // Free callback data
|
2019-01-05 01:02:48 +00:00
|
|
|
|
} _mxml_custom_t;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
typedef union _mxml_value_u // An XML node value.
|
2019-01-05 01:02:48 +00:00
|
|
|
|
{
|
2024-03-02 23:47:57 +00:00
|
|
|
|
char *cdata; // CDATA string
|
|
|
|
|
char *comment; // Common string
|
|
|
|
|
char *declaration; // Declaration string
|
|
|
|
|
char *directive; // Processing instruction string
|
2024-02-27 20:04:27 +00:00
|
|
|
|
_mxml_element_t element; // Element
|
2024-03-02 23:47:57 +00:00
|
|
|
|
long integer; // Integer number
|
2024-02-27 20:04:27 +00:00
|
|
|
|
char *opaque; // Opaque string
|
|
|
|
|
double real; // Real number
|
|
|
|
|
_mxml_text_t text; // Text fragment
|
2024-03-02 23:47:57 +00:00
|
|
|
|
_mxml_custom_t custom; // Custom data
|
2019-01-05 01:02:48 +00:00
|
|
|
|
} _mxml_value_t;
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
struct _mxml_node_s // An XML node.
|
2019-01-05 01:02:48 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_type_t type; // Node type
|
|
|
|
|
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
|
|
|
|
|
_mxml_value_t value; // Node value
|
2024-03-02 23:47:57 +00:00
|
|
|
|
size_t ref_count; // Use count
|
2024-02-27 20:04:27 +00:00
|
|
|
|
void *user_data; // User data
|
2019-01-05 01:02:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-19 01:46:14 +00:00
|
|
|
|
typedef struct _mxml_global_s // Global, per-thread data
|
|
|
|
|
{
|
|
|
|
|
mxml_strcopy_cb_t strcopy_cb; // String copy callback function
|
|
|
|
|
mxml_strfree_cb_t strfree_cb; // String free callback function
|
|
|
|
|
void *str_cbdata; // String callback data
|
|
|
|
|
} _mxml_global_t;
|
|
|
|
|
|
|
|
|
|
struct _mxml_index_s // An XML node index.
|
2019-01-05 01:02:48 +00:00
|
|
|
|
{
|
2024-02-27 20:04:27 +00:00
|
|
|
|
char *attr; // Attribute used for indexing or NULL
|
2024-03-02 23:47:57 +00:00
|
|
|
|
size_t num_nodes; // Number of nodes in index
|
|
|
|
|
size_t alloc_nodes; // Allocated nodes in index
|
|
|
|
|
size_t cur_node; // Current node
|
2024-02-27 20:04:27 +00:00
|
|
|
|
mxml_node_t **nodes; // Node array
|
2019-01-05 01:02:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-19 01:46:14 +00:00
|
|
|
|
struct _mxml_options_s // XML options
|
2007-09-21 04:46:02 +00:00
|
|
|
|
{
|
2024-03-19 01:46:14 +00:00
|
|
|
|
struct lconv *loc; // Locale data
|
|
|
|
|
size_t loc_declen; // Length of decimal point string
|
|
|
|
|
mxml_custload_cb_t custload_cb; // Custom load callback function
|
|
|
|
|
mxml_custsave_cb_t custsave_cb; // Custom save callback function
|
|
|
|
|
void *cust_cbdata; // Custom callback data
|
|
|
|
|
mxml_entity_cb_t entity_cb; // Entity callback function
|
|
|
|
|
void *entity_cbdata; // Entity callback data
|
|
|
|
|
mxml_error_cb_t error_cb; // Error callback function
|
|
|
|
|
void *error_cbdata; // Error callback data
|
|
|
|
|
mxml_sax_cb_t sax_cb; // SAX callback function
|
|
|
|
|
void *sax_cbdata; // SAX callback data
|
|
|
|
|
mxml_type_cb_t type_cb; // Type callback function
|
|
|
|
|
void *type_cbdata; // Type callback data
|
|
|
|
|
mxml_type_t type_value; // Fixed type value (if no type callback)
|
|
|
|
|
int wrap; // Wrap margin
|
|
|
|
|
mxml_ws_cb_t ws_cb; // Whitespace callback function
|
|
|
|
|
void *ws_cbdata; // Whitespace callback data
|
|
|
|
|
};
|
2007-09-21 04:46:02 +00:00
|
|
|
|
|
|
|
|
|
|
2024-02-27 20:04:27 +00:00
|
|
|
|
//
|
|
|
|
|
// Private functions...
|
|
|
|
|
//
|
2007-09-21 04:46:02 +00:00
|
|
|
|
|
|
|
|
|
extern _mxml_global_t *_mxml_global(void);
|
2024-03-06 19:45:10 +00:00
|
|
|
|
extern const char *_mxml_entity_string(int ch);
|
2024-03-19 01:46:14 +00:00
|
|
|
|
extern int _mxml_entity_value(mxml_options_t *options, const char *name);
|
|
|
|
|
extern void _mxml_error(mxml_options_t *options, const char *format, ...) MXML_FORMAT(2,3);
|
2024-03-07 19:06:50 +00:00
|
|
|
|
extern char *_mxml_strcopy(const char *s);
|
|
|
|
|
extern void _mxml_strfree(char *s);
|
2024-02-27 20:04:27 +00:00
|
|
|
|
|
|
|
|
|
#endif // !MXML_PRIVATE_H
|