GnuCash c935c2f+
Loading...
Searching...
No Matches
sixtp.h
1/********************************************************************
2 * sixtp.h -- header file for XML parsing *
3 * Copyright 2001 Gnumatic, Inc. *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation; either version 2 of *
8 * the License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License*
16 * along with this program; if not, contact: *
17 * *
18 * Free Software Foundation Voice: +1-617-542-5942 *
19 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20 * Boston, MA 02110-1301, USA gnu@gnu.org *
21 * *
22 ********************************************************************/
23
24#ifndef SIXTP_H
25#define SIXTP_H
26
27#include <glib.h>
28
29#include <stdio.h>
30
31#include <stdarg.h>
32#include "gnc-engine.h"
33
34#include "gnc-xml-helper.h"
35#include "gnc-backend-xml.h"
36
37typedef struct sixtp_gdv2 sixtp_gdv2;
38typedef void (*countCallbackFn) (sixtp_gdv2* gd, const char* type);
39
40typedef struct
41{
42 int accounts_total;
43 int accounts_loaded;
44
45 int books_total;
46 int books_loaded;
47
48 int commodities_total;
49 int commodities_loaded;
50
51 int transactions_total;
52 int transactions_loaded;
53
54 int prices_total;
55 int prices_loaded;
56
57 int schedXactions_total;
58 int schedXactions_loaded;
59
60 int budgets_total;
61 int budgets_loaded;
63
65{
66 QofBook* book;
67 load_counter counter;
68 countCallbackFn countCallback;
69 QofBePercentageFunc gui_display_fn;
70 gboolean exporting;
71};
72typedef struct _sixtp_child_result sixtp_child_result;
73
74typedef gboolean (*sixtp_start_handler) (GSList* sibling_data,
75 gpointer parent_data,
76 gpointer global_data,
77 gpointer* data_for_children,
78 gpointer* result,
79 const gchar* tag,
80 gchar** attrs);
81
82typedef gboolean (*sixtp_before_child_handler) (gpointer data_for_children,
83 GSList* data_from_children,
84 GSList* sibling_data,
85 gpointer parent_data,
86 gpointer global_data,
87 gpointer* result,
88 const gchar* tag,
89 const gchar* child_tag);
90
91typedef gboolean (*sixtp_after_child_handler) (gpointer data_for_children,
92 GSList* data_from_children,
93 GSList* sibling_data,
94 gpointer parent_data,
95 gpointer global_data,
96 gpointer* result,
97 const gchar* tag,
98 const gchar* child_tag,
99 sixtp_child_result* child_result);
100
101typedef gboolean (*sixtp_end_handler) (gpointer data_for_children,
102 GSList* data_from_children,
103 GSList* sibling_data,
104 gpointer parent_data,
105 gpointer global_data,
106 gpointer* result,
107 const gchar* tag);
108
109typedef gboolean (*sixtp_characters_handler) (GSList* sibling_data,
110 gpointer parent_data,
111 gpointer global_data,
112 gpointer* result,
113 const char* text,
114 int length);
115
116typedef void (*sixtp_result_handler) (sixtp_child_result* result);
117
118typedef void (*sixtp_fail_handler) (gpointer data_for_children,
119 GSList* data_from_children,
120 GSList* sibling_data,
121 gpointer parent_data,
122 gpointer global_data,
123 gpointer* result,
124 const gchar* tag);
125
126typedef void (*sixtp_push_handler) (xmlParserCtxtPtr xml_context,
127 gpointer user_data);
128
129typedef struct sixtp
130{
131 /* If you change this, don't forget to modify all the copy/etc. functions */
132 sixtp_start_handler start_handler;
133 sixtp_before_child_handler before_child;
134 sixtp_after_child_handler after_child;
135 sixtp_end_handler end_handler;
136 sixtp_characters_handler characters_handler;
137
138 sixtp_fail_handler fail_handler;
139 /* called for failures before the close tag */
140
141 sixtp_result_handler cleanup_result; /* called unless failure */
142 sixtp_result_handler cleanup_chars; /* called unless failure */
143
144 sixtp_result_handler result_fail_handler;
145 /* called to cleanup results from this node on failure */
146
147 sixtp_result_handler chars_fail_handler;
148 /* called to cleanup character results when cleaning up this node's
149 children. */
150
151 GHashTable* child_parsers;
152} sixtp;
153
154typedef enum
155{
156 SIXTP_NO_MORE_HANDLERS,
157
158 SIXTP_START_HANDLER_ID,
159 SIXTP_BEFORE_CHILD_HANDLER_ID,
160 SIXTP_AFTER_CHILD_HANDLER_ID,
161 SIXTP_END_HANDLER_ID,
162 SIXTP_CHARACTERS_HANDLER_ID,
163
164 SIXTP_FAIL_HANDLER_ID,
165
166 SIXTP_CLEANUP_RESULT_ID,
167 SIXTP_CLEANUP_CHARS_ID,
168
169 SIXTP_RESULT_FAIL_ID,
170
171 SIXTP_CHARS_FAIL_ID,
172} sixtp_handler_type;
173
174/* completely invalid tag for xml */
175#define SIXTP_MAGIC_CATCHER "&MAGIX&"
176
177typedef enum
178{
179 SIXTP_CHILD_RESULT_CHARS,
180 SIXTP_CHILD_RESULT_NODE
181} sixtp_child_result_type;
182
184{
185 sixtp_child_result_type type;
186 gchar* tag; /* NULL for a CHARS node. */
187 gpointer data;
188 gboolean should_cleanup;
189 sixtp_result_handler cleanup_handler;
190 sixtp_result_handler fail_handler;
191};
192
193typedef struct sixtp_sax_data
194{
195 gboolean parsing_ok;
196 GSList* stack;
197 gpointer global_data;
198 xmlParserCtxtPtr saxParserCtxt;
199 sixtp* bad_xml_parser;
201
202gboolean is_child_result_from_node_named (sixtp_child_result* cr,
203 const char* tag);
204void sixtp_child_free_data (sixtp_child_result* result);
205void sixtp_child_result_destroy (sixtp_child_result* r);
206void sixtp_child_result_print (sixtp_child_result* cr, FILE* f);
207
208void sixtp_sax_start_handler (void* user_data, const xmlChar* name,
209 const xmlChar** attrs);
210void sixtp_sax_characters_handler (void* user_data, const xmlChar* text,
211 int len);
212void sixtp_sax_end_handler (void* user_data, const xmlChar* name);
213
214sixtp* sixtp_new (void);
215void sixtp_destroy (sixtp* sp);
216
217void sixtp_handle_catastrophe (sixtp_sax_data* sax_data);
218xmlEntityPtr sixtp_sax_get_entity_handler (void* user_data,
219 const xmlChar* name);
220
221gboolean sixtp_parse_file (sixtp* sixtp, const char* filename,
222 gpointer data_for_top_level, gpointer global_data,
223 gpointer* parse_result);
224gboolean sixtp_parse_fd (sixtp* sixtp, FILE* fd,
225 gpointer data_for_top_level, gpointer global_data,
226 gpointer* parse_result);
227gboolean sixtp_parse_buffer (sixtp* sixtp, char* bufp, int bufsz,
228 gpointer data_for_top_level, gpointer global_data,
229 gpointer* parse_result);
230gboolean sixtp_parse_push (sixtp* sixtp, sixtp_push_handler push_handler,
231 gpointer push_user_data, gpointer data_for_top_level,
232 gpointer global_data, gpointer* parse_result);
233
234void sixtp_set_start (sixtp* parser, sixtp_start_handler start_handler);
235void sixtp_set_before_child (sixtp* parser,
236 sixtp_before_child_handler handler);
237void sixtp_set_after_child (sixtp* parser, sixtp_after_child_handler handler);
238void sixtp_set_end (sixtp* parser, sixtp_end_handler end_handler);
239void sixtp_set_chars (sixtp* parser, sixtp_characters_handler char_handler);
240void sixtp_set_cleanup_result (sixtp* parser, sixtp_result_handler handler);
241void sixtp_set_cleanup_chars (sixtp* parser, sixtp_result_handler handler);
242void sixtp_set_fail (sixtp* parser, sixtp_fail_handler handler);
243void sixtp_set_result_fail (sixtp* parser, sixtp_result_handler handler);
244void sixtp_set_chars_fail (sixtp* parser, sixtp_result_handler handler);
245
246sixtp* sixtp_set_any (sixtp* tochange, gboolean cleanup, ...);
247sixtp* sixtp_add_some_sub_parsers (sixtp* tochange, gboolean cleanup, ...);
248
249gboolean sixtp_add_sub_parser (sixtp* parser, const gchar* tag,
250 sixtp* sub_parser);
251
252QofBookFileType gnc_is_our_xml_file (const char* filename,
253 gboolean* with_encoding);
254
255QofBookFileType gnc_is_our_first_xml_chunk (char* chunk,
256 gboolean* with_encoding);
258void sixtp_run_callback (sixtp_gdv2* data, const char* type);
259
260#endif /* _SIXTP_H_ */
load and save data to files
All type declarations for the whole Gnucash engine.
void(* QofBePercentageFunc)(const char *message, double percent)
DOCUMENT ME!
Definition qofbackend.h:163
QofBook reference.
Definition qofbook-p.hpp:47
Definition sixtp.h:130