mxml-private.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Private definitions for Mini-XML, a small XML file parsing library.
  3. *
  4. * https://www.msweet.org/mxml
  5. *
  6. * Copyright © 2003-2019 by Michael R Sweet.
  7. *
  8. * Licensed under Apache License v2.0. See the file "LICENSE" for more
  9. * information.
  10. */
  11. #ifndef _mxml_private_h_
  12. # define _mxml_private_h_
  13. /*
  14. * Include necessary headers...
  15. */
  16. # include "mxml-config.h"
  17. # include "mxml.h"
  18. /*
  19. * Private structures...
  20. */
  21. typedef struct _mxml_attr_s /**** An XML element attribute value. ****/
  22. {
  23. char *name; /* Attribute name */
  24. char *value; /* Attribute value */
  25. } _mxml_attr_t;
  26. typedef struct _mxml_element_s /**** An XML element value. ****/
  27. {
  28. char *name; /* Name of element */
  29. int num_attrs; /* Number of attributes */
  30. _mxml_attr_t *attrs; /* Attributes */
  31. } _mxml_element_t;
  32. typedef struct _mxml_text_s /**** An XML text value. ****/
  33. {
  34. int whitespace; /* Leading whitespace? */
  35. char *string; /* Fragment string */
  36. } _mxml_text_t;
  37. typedef struct _mxml_custom_s /**** An XML custom value. ****/
  38. {
  39. void *data; /* Pointer to (allocated) custom data */
  40. mxml_custom_destroy_cb_t destroy; /* Pointer to destructor function */
  41. } _mxml_custom_t;
  42. typedef union _mxml_value_u /**** An XML node value. ****/
  43. {
  44. _mxml_element_t element; /* Element */
  45. int integer; /* Integer number */
  46. char *opaque; /* Opaque string */
  47. double real; /* Real number */
  48. _mxml_text_t text; /* Text fragment */
  49. _mxml_custom_t custom; /* Custom data @since Mini-XML 2.1@ */
  50. } _mxml_value_t;
  51. struct _mxml_node_s /**** An XML node. ****/
  52. {
  53. mxml_type_t type; /* Node type */
  54. struct _mxml_node_s *next; /* Next node under same parent */
  55. struct _mxml_node_s *prev; /* Previous node under same parent */
  56. struct _mxml_node_s *parent; /* Parent node */
  57. struct _mxml_node_s *child; /* First child node */
  58. struct _mxml_node_s *last_child; /* Last child node */
  59. _mxml_value_t value; /* Node value */
  60. int ref_count; /* Use count */
  61. void *user_data; /* User data */
  62. };
  63. struct _mxml_index_s /**** An XML node index. ****/
  64. {
  65. char *attr; /* Attribute used for indexing or NULL */
  66. int num_nodes; /* Number of nodes in index */
  67. int alloc_nodes; /* Allocated nodes in index */
  68. int cur_node; /* Current node */
  69. mxml_node_t **nodes; /* Node array */
  70. };
  71. typedef struct _mxml_global_s /**** Global, per-thread data ****/
  72. {
  73. void (*error_cb)(const char *);
  74. int num_entity_cbs;
  75. int (*entity_cbs[100])(const char *name);
  76. int wrap;
  77. mxml_custom_load_cb_t custom_load_cb;
  78. mxml_custom_save_cb_t custom_save_cb;
  79. } _mxml_global_t;
  80. /*
  81. * Functions...
  82. */
  83. extern _mxml_global_t *_mxml_global(void);
  84. extern int _mxml_entity_cb(const char *name);
  85. #endif /* !_mxml_private_h_ */