mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
James LewisMoss's patch continuing the xml code refactoring.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3523 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
b021a813a7
commit
82fc84f7ed
@ -43,11 +43,12 @@
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
account_start_handler(GSList* sibling_data,
|
account_start_handler(GSList* sibling_data,
|
||||||
gpointer parent_data,
|
gpointer parent_data,
|
||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *data_for_children,
|
gpointer *data_for_children,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
const gchar *tag)
|
const gchar *tag,
|
||||||
|
gchar **attrs)
|
||||||
{
|
{
|
||||||
/* pass the parent data down to the children */
|
/* pass the parent data down to the children */
|
||||||
*data_for_children = parent_data;
|
*data_for_children = parent_data;
|
||||||
@ -77,11 +78,12 @@ account_start_handler(GSList* sibling_data,
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
account_restore_start_handler(GSList* sibling_data,
|
account_restore_start_handler(GSList* sibling_data,
|
||||||
gpointer parent_data,
|
gpointer parent_data,
|
||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *data_for_children,
|
gpointer *data_for_children,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
const gchar *tag)
|
const gchar *tag,
|
||||||
|
gchar **attrs)
|
||||||
{
|
{
|
||||||
Account *acc = xaccMallocAccount();
|
Account *acc = xaccMallocAccount();
|
||||||
|
|
||||||
|
@ -10,6 +10,28 @@
|
|||||||
#include "gnc-commodity.h"
|
#include "gnc-commodity.h"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* Commodity restorer.
|
||||||
|
|
||||||
|
Right now we just check to see that fields aren't duplicated. If
|
||||||
|
fields don't show up, then we just use "".
|
||||||
|
|
||||||
|
We also check to see that we get a <fraction>. If not, it's an
|
||||||
|
error.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
<commodity>
|
||||||
|
<restore>
|
||||||
|
<space>NASDAQ</space>
|
||||||
|
<id>XYZZY</id>
|
||||||
|
<name>Grue Enterprises</name>
|
||||||
|
<xcode>XXX</xcode>
|
||||||
|
<fraction>100</fraction>
|
||||||
|
</restore>
|
||||||
|
</commodity>
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/* ==================================================================== */
|
/* ==================================================================== */
|
||||||
|
|
||||||
/*********************************/
|
/*********************************/
|
||||||
@ -45,12 +67,10 @@ typedef struct {
|
|||||||
} CommodityParseInfo;
|
} CommodityParseInfo;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
commodity_restore_start_handler(GSList* sibling_data,
|
commodity_restore_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data,
|
||||||
gpointer global_data,
|
gpointer *data_for_children, gpointer *result,
|
||||||
gpointer *data_for_children,
|
const gchar *tag, gchar **attrs)
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
CommodityParseInfo *cpi = (CommodityParseInfo *) g_new0(CommodityParseInfo, 1);
|
CommodityParseInfo *cpi = (CommodityParseInfo *) g_new0(CommodityParseInfo, 1);
|
||||||
|
|
||||||
@ -238,12 +258,10 @@ typedef struct {
|
|||||||
} CommodityLookupParseInfo;
|
} CommodityLookupParseInfo;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
generic_gnc_commodity_lookup_start_handler(GSList* sibling_data,
|
generic_gnc_commodity_lookup_start_handler(
|
||||||
gpointer parent_data,
|
GSList* sibling_data, gpointer parent_data, gpointer global_data,
|
||||||
gpointer global_data,
|
gpointer *data_for_children, gpointer *result, const gchar *tag,
|
||||||
gpointer *data_for_children,
|
gchar **attrs)
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
CommodityLookupParseInfo *cpi = g_new0(CommodityLookupParseInfo, 1);
|
CommodityLookupParseInfo *cpi = g_new0(CommodityLookupParseInfo, 1);
|
||||||
g_return_val_if_fail(cpi, FALSE);
|
g_return_val_if_fail(cpi, FALSE);
|
||||||
|
@ -31,12 +31,9 @@
|
|||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ledger_data_start_handler(GSList* sibling_data,
|
ledger_data_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data, gpointer *data_for_children,
|
||||||
gpointer global_data,
|
gpointer *result, const gchar *tag, gchar **attrs)
|
||||||
gpointer *data_for_children,
|
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
AccountGroup *ag;
|
AccountGroup *ag;
|
||||||
|
|
||||||
|
@ -35,11 +35,12 @@
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
query_server_start_handler(GSList* sibling_data,
|
query_server_start_handler(GSList* sibling_data,
|
||||||
gpointer parent_data,
|
gpointer parent_data,
|
||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *data_for_children,
|
gpointer *data_for_children,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
const gchar *tag)
|
const gchar *tag,
|
||||||
|
gchar **attrs)
|
||||||
{
|
{
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
@ -87,12 +88,9 @@ query_server_end_handler(gpointer data_for_children,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
query_start_handler(GSList* sibling_data,
|
query_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data, gpointer *data_for_children,
|
||||||
gpointer global_data,
|
gpointer *result, const gchar *tag, gchar **attrs)
|
||||||
gpointer *data_for_children,
|
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
@ -140,12 +138,9 @@ query_end_handler(gpointer data_for_children,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
query_restore_start_handler(GSList* sibling_data,
|
query_restore_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data, gpointer *data_for_children,
|
||||||
gpointer global_data,
|
gpointer *result, const gchar *tag, gchar **attrs)
|
||||||
gpointer *data_for_children,
|
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
Query *q;
|
Query *q;
|
||||||
q = xaccMallocQuery();
|
q = xaccMallocQuery();
|
||||||
@ -237,12 +232,9 @@ query_restore_fail_handler(gpointer data_for_children,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
query_and_start_handler(GSList* sibling_data,
|
query_and_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data, gpointer *data_for_children,
|
||||||
gpointer global_data,
|
gpointer *result, const gchar *tag, gchar **attrs)
|
||||||
gpointer *data_for_children,
|
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
Query *q;
|
Query *q;
|
||||||
|
|
||||||
@ -346,12 +338,11 @@ qrestore_genericpred_end_handler(gpointer data_for_children,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
qrestore_datepred_start_handler(GSList* sibling_data,
|
qrestore_datepred_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data,
|
||||||
gpointer global_data,
|
gpointer *data_for_children,
|
||||||
gpointer *data_for_children,
|
gpointer *result, const gchar *tag,
|
||||||
gpointer *result,
|
gchar **attrs)
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
DatePredicateData *dp = g_new (DatePredicateData, 1);
|
DatePredicateData *dp = g_new (DatePredicateData, 1);
|
||||||
g_return_val_if_fail(dp, FALSE);
|
g_return_val_if_fail(dp, FALSE);
|
||||||
|
@ -42,12 +42,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
transaction_start_handler(GSList* sibling_data,
|
transaction_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data, gpointer *data_for_children,
|
||||||
gpointer global_data,
|
gpointer *result, const gchar *tag, gchar **attrs)
|
||||||
gpointer *data_for_children,
|
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
/* pass the parent data down to the children */
|
/* pass the parent data down to the children */
|
||||||
*data_for_children = parent_data;
|
*data_for_children = parent_data;
|
||||||
@ -89,12 +86,9 @@ transaction_start_handler(GSList* sibling_data,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
txn_restore_start_handler(GSList* sibling_data,
|
txn_restore_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data, gpointer *data_for_children,
|
||||||
gpointer global_data,
|
gpointer *result, const gchar *tag, gchar **attrs)
|
||||||
gpointer *data_for_children,
|
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
Transaction *trans = xaccMallocTransaction();
|
Transaction *trans = xaccMallocTransaction();
|
||||||
g_return_val_if_fail(trans, FALSE);
|
g_return_val_if_fail(trans, FALSE);
|
||||||
@ -392,12 +386,10 @@ txn_rest_date_entered_end_handler(gpointer data_for_children,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
txn_restore_split_start_handler(GSList* sibling_data,
|
txn_restore_split_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data,
|
||||||
gpointer global_data,
|
gpointer *data_for_children, gpointer *result,
|
||||||
gpointer *data_for_children,
|
const gchar *tag, gchar **attrs)
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
Split *s = xaccMallocSplit();
|
Split *s = xaccMallocSplit();
|
||||||
g_return_val_if_fail(s, FALSE);
|
g_return_val_if_fail(s, FALSE);
|
||||||
|
@ -103,10 +103,9 @@ sixtp_handle_catastrophe(sixtp_sax_data *sax_data) {
|
|||||||
|
|
||||||
while(*stack) {
|
while(*stack) {
|
||||||
sixtp_stack_frame *current_frame = (sixtp_stack_frame *) (*stack)->data;
|
sixtp_stack_frame *current_frame = (sixtp_stack_frame *) (*stack)->data;
|
||||||
sixtp_fail_handler fail_handler = current_frame->parser->fail_handler;
|
|
||||||
|
|
||||||
/* cleanup the current frame */
|
/* cleanup the current frame */
|
||||||
if(fail_handler) {
|
if(current_frame->parser->fail_handler) {
|
||||||
GSList *sibling_data;
|
GSList *sibling_data;
|
||||||
gpointer parent_data;
|
gpointer parent_data;
|
||||||
|
|
||||||
@ -121,19 +120,21 @@ sixtp_handle_catastrophe(sixtp_sax_data *sax_data) {
|
|||||||
sibling_data = parent_frame->data_from_children;
|
sibling_data = parent_frame->data_from_children;
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_handler(current_frame->data_for_children,
|
current_frame->parser->fail_handler(current_frame->data_for_children,
|
||||||
current_frame->data_from_children,
|
current_frame->data_from_children,
|
||||||
sibling_data,
|
sibling_data,
|
||||||
parent_data,
|
parent_data,
|
||||||
sax_data->global_data,
|
sax_data->global_data,
|
||||||
¤t_frame->frame_data,
|
¤t_frame->frame_data,
|
||||||
current_frame->tag);
|
current_frame->tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now cleanup any children's results */
|
/* now cleanup any children's results */
|
||||||
for(lp = current_frame->data_from_children; lp; lp = lp->next) {
|
for(lp = current_frame->data_from_children; lp; lp = lp->next) {
|
||||||
sixtp_child_result *cresult = (sixtp_child_result *) lp->data;
|
sixtp_child_result *cresult = (sixtp_child_result *) lp->data;
|
||||||
if(cresult->fail_handler) cresult->fail_handler(cresult);
|
if(cresult->fail_handler) {
|
||||||
|
cresult->fail_handler(cresult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*stack = sixtp_pop_and_destroy_frame(*stack);
|
*stack = sixtp_pop_and_destroy_frame(*stack);
|
||||||
@ -180,7 +181,7 @@ sixtp_setup_parser (sixtp *sixtp,
|
|||||||
sax_data->global_data,
|
sax_data->global_data,
|
||||||
&top_frame->data_for_children,
|
&top_frame->data_for_children,
|
||||||
&top_frame->frame_data,
|
&top_frame->frame_data,
|
||||||
NULL);
|
NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!sax_data->parsing_ok) {
|
if(!sax_data->parsing_ok) {
|
||||||
@ -344,45 +345,7 @@ typedef struct {
|
|||||||
} GNCParseStatus;
|
} GNCParseStatus;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************/
|
|
||||||
/* Commodity restorer.
|
|
||||||
|
|
||||||
Right now we just check to see that fields aren't duplicated. If
|
|
||||||
fields don't show up, then we just use "".
|
|
||||||
|
|
||||||
We also check to see that we get a <fraction>. If not, it's an
|
|
||||||
error.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
<commodity>
|
|
||||||
<restore>
|
|
||||||
<space>NASDAQ</space>
|
|
||||||
<id>XYZZY</id>
|
|
||||||
<name>Grue Enterprises</name>
|
|
||||||
<xcode>XXX</xcode>
|
|
||||||
<fraction>100</fraction>
|
|
||||||
</restore>
|
|
||||||
</commodity>
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**************/
|
|
||||||
/* <commodity>
|
|
||||||
*
|
|
||||||
* Does nothing.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* ==================================================================== */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ================================================================= */
|
/* ================================================================= */
|
||||||
/* ================================================================= */
|
|
||||||
/* ================================================================= */
|
|
||||||
/* ================================================================= */
|
|
||||||
/****************************************************************************/
|
|
||||||
/* <version> (lineage <gnc>)
|
/* <version> (lineage <gnc>)
|
||||||
|
|
||||||
Fancy and strange - look for an integer version number. If we get
|
Fancy and strange - look for an integer version number. If we get
|
||||||
|
@ -600,12 +600,9 @@ kvp_frame_slot_parser_new(sixtp *kvp_frame_parser) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
kvp_frame_start_handler(GSList* sibling_data,
|
kvp_frame_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data, gpointer *data_for_children,
|
||||||
gpointer global_data,
|
gpointer *result, const gchar *tag, gchar **attrs)
|
||||||
gpointer *data_for_children,
|
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
kvp_frame *f = kvp_frame_new();
|
kvp_frame *f = kvp_frame_new();
|
||||||
g_return_val_if_fail(f, FALSE);
|
g_return_val_if_fail(f, FALSE);
|
||||||
|
@ -417,12 +417,10 @@ string_to_timespec_nsecs(const gchar *str, Timespec *ts) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
generic_timespec_start_handler(GSList* sibling_data,
|
generic_timespec_start_handler(GSList* sibling_data, gpointer parent_data,
|
||||||
gpointer parent_data,
|
gpointer global_data,
|
||||||
gpointer global_data,
|
gpointer *data_for_children, gpointer *result,
|
||||||
gpointer *data_for_children,
|
const gchar *tag, gchar **attrs)
|
||||||
gpointer *result,
|
|
||||||
const gchar *tag)
|
|
||||||
{
|
{
|
||||||
TimespecParseInfo *tsp = g_new0(TimespecParseInfo, 1);
|
TimespecParseInfo *tsp = g_new0(TimespecParseInfo, 1);
|
||||||
g_return_val_if_fail(tsp, FALSE);
|
g_return_val_if_fail(tsp, FALSE);
|
||||||
|
@ -65,7 +65,7 @@ gboolean generic_timespec_start_handler(GSList* sibling_data,
|
|||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *data_for_children,
|
gpointer *data_for_children,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
const gchar *tag);
|
const gchar *tag, gchar **attrs);
|
||||||
|
|
||||||
gboolean timespec_parse_ok(TimespecParseInfo *info);
|
gboolean timespec_parse_ok(TimespecParseInfo *info);
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
static short module = MOD_IO;
|
static short module = MOD_IO;
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
gboolean
|
gboolean
|
||||||
is_child_result_from_node_named(sixtp_child_result *cr, const char *tag) {
|
is_child_result_from_node_named(sixtp_child_result *cr, const char *tag) {
|
||||||
return((cr->type == SIXTP_CHILD_RESULT_NODE)
|
return((cr->type == SIXTP_CHILD_RESULT_NODE)
|
||||||
@ -33,6 +34,64 @@ sixtp_child_result_print(sixtp_child_result *cr, FILE *f) {
|
|||||||
fprintf(f, "((tag %s) (data %p))", cr->tag, cr->data);
|
fprintf(f, "((tag %s) (data %p))", cr->tag, cr->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler) {
|
||||||
|
parser->start_handler = start_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler) {
|
||||||
|
parser->before_child = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_after_child(sixtp *parser, sixtp_after_child_handler handler) {
|
||||||
|
parser->after_child = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_end(sixtp *parser, sixtp_end_handler end_handler) {
|
||||||
|
parser->end_handler = end_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_chars(sixtp *parser, sixtp_characters_handler char_handler) {
|
||||||
|
parser->characters_handler = char_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_cleanup_result(sixtp *parser,
|
||||||
|
sixtp_result_handler handler) {
|
||||||
|
parser->cleanup_result = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_cleanup_chars(sixtp *parser,
|
||||||
|
sixtp_result_handler handler) {
|
||||||
|
parser->cleanup_chars = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_fail(sixtp *parser,
|
||||||
|
sixtp_fail_handler handler) {
|
||||||
|
parser->fail_handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_result_fail(sixtp *parser,
|
||||||
|
sixtp_result_handler handler) {
|
||||||
|
parser->result_fail_handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_set_chars_fail(sixtp *parser,
|
||||||
|
sixtp_result_handler handler) {
|
||||||
|
parser->chars_fail_handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
sixtp *
|
sixtp *
|
||||||
sixtp_new(void) {
|
sixtp_new(void) {
|
||||||
sixtp *s = g_new0(sixtp, 1);
|
sixtp *s = g_new0(sixtp, 1);
|
||||||
@ -47,6 +106,98 @@ sixtp_new(void) {
|
|||||||
return(s);
|
return(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sixtp*
|
||||||
|
sixtp_new_full(sixtp_start_handler starter,
|
||||||
|
sixtp_before_child_handler cdbeforer,
|
||||||
|
sixtp_after_child_handler chafterer,
|
||||||
|
sixtp_end_handler ender,
|
||||||
|
sixtp_characters_handler charer,
|
||||||
|
sixtp_fail_handler failer,
|
||||||
|
sixtp_result_handler cleanresulter,
|
||||||
|
sixtp_result_handler cleancharer,
|
||||||
|
sixtp_result_handler resultfailer,
|
||||||
|
sixtp_result_handler charsfailer)
|
||||||
|
{
|
||||||
|
sixtp *ret = sixtp_new();
|
||||||
|
g_return_val_if_fail(ret, NULL);
|
||||||
|
|
||||||
|
sixtp_set_start(ret, starter);
|
||||||
|
sixtp_set_before_child(ret, cdbeforer);
|
||||||
|
sixtp_set_after_child(ret, chafterer);
|
||||||
|
sixtp_set_end(ret, ender);
|
||||||
|
sixtp_set_chars(ret, charer);
|
||||||
|
sixtp_set_fail(ret, failer);
|
||||||
|
sixtp_set_cleanup_result(ret, cleanresulter);
|
||||||
|
sixtp_set_cleanup_chars(ret, cleancharer);
|
||||||
|
sixtp_set_result_fail(ret, resultfailer);
|
||||||
|
sixtp_set_chars_fail(ret, charsfailer);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sixtp_destroy_child(gpointer key, gpointer value,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
static void
|
||||||
|
sixtp_destroy_node(sixtp *sp, GHashTable *corpses) {
|
||||||
|
g_return_if_fail(sp);
|
||||||
|
g_return_if_fail(corpses);
|
||||||
|
g_hash_table_foreach(sp->children, sixtp_destroy_child, corpses);
|
||||||
|
g_hash_table_destroy(sp->children);
|
||||||
|
g_free(sp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data) {
|
||||||
|
GHashTable *corpses = (GHashTable *) user_data;
|
||||||
|
sixtp *child = (sixtp *) value;
|
||||||
|
gpointer lookup_key;
|
||||||
|
gpointer lookup_value;
|
||||||
|
|
||||||
|
PINFO ("Killing sixtp child under key <%s>", (char *) key);
|
||||||
|
g_free(key);
|
||||||
|
|
||||||
|
if(!corpses) {
|
||||||
|
PERR("no corpses in sixtp_destroy_child <%s>\n", (char *) key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!child) {
|
||||||
|
PERR("no child in sixtp_destroy_child <%s>\n", (char *) key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!g_hash_table_lookup_extended(corpses, (gconstpointer) child,
|
||||||
|
&lookup_key, &lookup_value)) {
|
||||||
|
/* haven't killed this one yet. */
|
||||||
|
g_hash_table_insert(corpses, child, (gpointer) 1);
|
||||||
|
sixtp_destroy_node(child, corpses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixtp_destroy(sixtp *sp) {
|
||||||
|
GHashTable *corpses;
|
||||||
|
g_return_if_fail(sp);
|
||||||
|
corpses = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||||
|
sixtp_destroy_node(sp, corpses);
|
||||||
|
g_hash_table_destroy(corpses);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
sixtp_add_sub_parser(sixtp *parser, const gchar* tag, sixtp *sub_parser) {
|
||||||
|
g_return_val_if_fail(parser, FALSE);
|
||||||
|
g_return_val_if_fail(tag, FALSE);
|
||||||
|
g_return_val_if_fail(sub_parser, FALSE);
|
||||||
|
|
||||||
|
g_hash_table_insert(parser->children, g_strdup(tag), (gpointer) sub_parser);
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
void
|
void
|
||||||
sixtp_sax_start_handler(void *user_data,
|
sixtp_sax_start_handler(void *user_data,
|
||||||
const xmlChar *name,
|
const xmlChar *name,
|
||||||
@ -123,7 +274,8 @@ sixtp_sax_start_handler(void *user_data,
|
|||||||
pdata->global_data,
|
pdata->global_data,
|
||||||
&new_frame->data_for_children,
|
&new_frame->data_for_children,
|
||||||
&new_frame->frame_data,
|
&new_frame->frame_data,
|
||||||
next_parser_tag);
|
next_parser_tag,
|
||||||
|
(gchar**)attrs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,114 +404,3 @@ sixtp_sax_end_handler(void *user_data, const xmlChar *name) {
|
|||||||
child_result_data);
|
child_result_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_destroy(sixtp *sp) {
|
|
||||||
GHashTable *corpses;
|
|
||||||
g_return_if_fail(sp);
|
|
||||||
corpses = g_hash_table_new(g_direct_hash, g_direct_equal);
|
|
||||||
sixtp_destroy_node(sp, corpses);
|
|
||||||
g_hash_table_destroy(corpses);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler) {
|
|
||||||
parser->start_handler = start_handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler) {
|
|
||||||
parser->before_child = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_after_child(sixtp *parser, sixtp_after_child_handler handler) {
|
|
||||||
parser->after_child = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_end(sixtp *parser, sixtp_end_handler end_handler) {
|
|
||||||
parser->end_handler = end_handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_chars(sixtp *parser, sixtp_characters_handler char_handler) {
|
|
||||||
parser->characters_handler = char_handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_cleanup_result(sixtp *parser,
|
|
||||||
sixtp_result_handler handler) {
|
|
||||||
parser->cleanup_result = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_cleanup_chars(sixtp *parser,
|
|
||||||
sixtp_result_handler handler) {
|
|
||||||
parser->cleanup_chars = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_fail(sixtp *parser,
|
|
||||||
sixtp_fail_handler handler) {
|
|
||||||
parser->fail_handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_result_fail(sixtp *parser,
|
|
||||||
sixtp_result_handler handler) {
|
|
||||||
parser->result_fail_handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_set_chars_fail(sixtp *parser,
|
|
||||||
sixtp_result_handler handler) {
|
|
||||||
parser->chars_fail_handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data) {
|
|
||||||
GHashTable *corpses = (GHashTable *) user_data;
|
|
||||||
sixtp *child = (sixtp *) value;
|
|
||||||
gpointer lookup_key;
|
|
||||||
gpointer lookup_value;
|
|
||||||
|
|
||||||
PINFO ("Killing sixtp child under key <%s>", (char *) key);
|
|
||||||
g_free(key);
|
|
||||||
|
|
||||||
if(!corpses) {
|
|
||||||
PERR("no corpses in sixtp_destroy_child <%s>\n", (char *) key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!child) {
|
|
||||||
PERR("no child in sixtp_destroy_child <%s>\n", (char *) key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!g_hash_table_lookup_extended(corpses, (gconstpointer) child,
|
|
||||||
&lookup_key, &lookup_value)) {
|
|
||||||
/* haven't killed this one yet. */
|
|
||||||
g_hash_table_insert(corpses, child, (gpointer) 1);
|
|
||||||
sixtp_destroy_node(child, corpses);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
sixtp_destroy_node(sixtp *sp, GHashTable *corpses) {
|
|
||||||
g_return_if_fail(sp);
|
|
||||||
g_return_if_fail(corpses);
|
|
||||||
g_hash_table_foreach(sp->children, sixtp_destroy_child, corpses);
|
|
||||||
g_hash_table_destroy(sp->children);
|
|
||||||
g_free(sp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
sixtp_add_sub_parser(sixtp *parser, const gchar* tag, sixtp *sub_parser) {
|
|
||||||
g_return_val_if_fail(parser, FALSE);
|
|
||||||
g_return_val_if_fail(tag, FALSE);
|
|
||||||
g_return_val_if_fail(sub_parser, FALSE);
|
|
||||||
|
|
||||||
g_hash_table_insert(parser->children, g_strdup(tag), (gpointer) sub_parser);
|
|
||||||
return(TRUE);
|
|
||||||
}
|
|
||||||
|
@ -41,8 +41,8 @@ typedef gboolean (*sixtp_start_handler)(GSList* sibling_data,
|
|||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *data_for_children,
|
gpointer *data_for_children,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
|
const gchar *tag,
|
||||||
const gchar *tag);
|
gchar **attrs);
|
||||||
|
|
||||||
typedef gboolean (*sixtp_before_child_handler)(gpointer data_for_children,
|
typedef gboolean (*sixtp_before_child_handler)(gpointer data_for_children,
|
||||||
GSList* data_from_children,
|
GSList* data_from_children,
|
||||||
@ -50,7 +50,6 @@ typedef gboolean (*sixtp_before_child_handler)(gpointer data_for_children,
|
|||||||
gpointer parent_data,
|
gpointer parent_data,
|
||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
|
|
||||||
const gchar *tag,
|
const gchar *tag,
|
||||||
const gchar *child_tag);
|
const gchar *child_tag);
|
||||||
|
|
||||||
@ -60,7 +59,6 @@ typedef gboolean (*sixtp_after_child_handler)(gpointer data_for_children,
|
|||||||
gpointer parent_data,
|
gpointer parent_data,
|
||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
|
|
||||||
const gchar *tag,
|
const gchar *tag,
|
||||||
const gchar *child_tag,
|
const gchar *child_tag,
|
||||||
sixtp_child_result *child_result);
|
sixtp_child_result *child_result);
|
||||||
@ -71,14 +69,12 @@ typedef gboolean (*sixtp_end_handler)(gpointer data_for_children,
|
|||||||
gpointer parent_data,
|
gpointer parent_data,
|
||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
|
|
||||||
const gchar *tag);
|
const gchar *tag);
|
||||||
|
|
||||||
typedef gboolean (*sixtp_characters_handler)(GSList *sibling_data,
|
typedef gboolean (*sixtp_characters_handler)(GSList *sibling_data,
|
||||||
gpointer parent_data,
|
gpointer parent_data,
|
||||||
gpointer global_data,
|
gpointer global_data,
|
||||||
gpointer *result,
|
gpointer *result,
|
||||||
|
|
||||||
const char *text,
|
const char *text,
|
||||||
int length);
|
int length);
|
||||||
|
|
||||||
@ -152,7 +148,6 @@ void sixtp_sax_end_handler(void *user_data, const xmlChar *name);
|
|||||||
sixtp* sixtp_new(void);
|
sixtp* sixtp_new(void);
|
||||||
|
|
||||||
void sixtp_destroy(sixtp *sp);
|
void sixtp_destroy(sixtp *sp);
|
||||||
void sixtp_destroy_node(sixtp *sp, GHashTable *corpses);
|
|
||||||
|
|
||||||
void sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler);
|
void sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler);
|
||||||
void sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler);
|
void sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler);
|
||||||
|
Loading…
Reference in New Issue
Block a user