diff --git a/src/engine/Account-xml-parser-v1.c b/src/engine/Account-xml-parser-v1.c index 41a74387c7..075ad801a9 100644 --- a/src/engine/Account-xml-parser-v1.c +++ b/src/engine/Account-xml-parser-v1.c @@ -43,11 +43,12 @@ static gboolean account_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) + gpointer parent_data, + gpointer global_data, + gpointer *data_for_children, + gpointer *result, + const gchar *tag, + gchar **attrs) { /* pass the parent data down to the children */ *data_for_children = parent_data; @@ -77,11 +78,12 @@ account_start_handler(GSList* sibling_data, static gboolean account_restore_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) + gpointer parent_data, + gpointer global_data, + gpointer *data_for_children, + gpointer *result, + const gchar *tag, + gchar **attrs) { Account *acc = xaccMallocAccount(); diff --git a/src/engine/Commodity-xml-parser-v1.c b/src/engine/Commodity-xml-parser-v1.c index 8257d50c8e..6f78eb91b9 100644 --- a/src/engine/Commodity-xml-parser-v1.c +++ b/src/engine/Commodity-xml-parser-v1.c @@ -10,6 +10,28 @@ #include "gnc-commodity.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 . If not, it's an + error. + + Example: + + + NASDAQ + XYZZY + Grue Enterprises + XXX + 100 + + + + */ + /* ==================================================================== */ /*********************************/ @@ -45,12 +67,10 @@ typedef struct { } CommodityParseInfo; static gboolean -commodity_restore_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +commodity_restore_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, + gpointer *data_for_children, gpointer *result, + const gchar *tag, gchar **attrs) { CommodityParseInfo *cpi = (CommodityParseInfo *) g_new0(CommodityParseInfo, 1); @@ -238,12 +258,10 @@ typedef struct { } CommodityLookupParseInfo; static gboolean -generic_gnc_commodity_lookup_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +generic_gnc_commodity_lookup_start_handler( + GSList* sibling_data, gpointer parent_data, gpointer global_data, + gpointer *data_for_children, gpointer *result, const gchar *tag, + gchar **attrs) { CommodityLookupParseInfo *cpi = g_new0(CommodityLookupParseInfo, 1); g_return_val_if_fail(cpi, FALSE); diff --git a/src/engine/Ledger-xml-parser-v1.c b/src/engine/Ledger-xml-parser-v1.c index a6c623f4af..5eb502f7cd 100644 --- a/src/engine/Ledger-xml-parser-v1.c +++ b/src/engine/Ledger-xml-parser-v1.c @@ -31,12 +31,9 @@ static gboolean -ledger_data_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +ledger_data_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, gpointer *data_for_children, + gpointer *result, const gchar *tag, gchar **attrs) { AccountGroup *ag; diff --git a/src/engine/Query-xml-parser-v1.c b/src/engine/Query-xml-parser-v1.c index bf3074594f..1fc9764186 100644 --- a/src/engine/Query-xml-parser-v1.c +++ b/src/engine/Query-xml-parser-v1.c @@ -35,11 +35,12 @@ static gboolean query_server_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) + gpointer parent_data, + gpointer global_data, + gpointer *data_for_children, + gpointer *result, + const gchar *tag, + gchar **attrs) { return(TRUE); } @@ -87,12 +88,9 @@ query_server_end_handler(gpointer data_for_children, */ static gboolean -query_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +query_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, gpointer *data_for_children, + gpointer *result, const gchar *tag, gchar **attrs) { return(TRUE); } @@ -140,12 +138,9 @@ query_end_handler(gpointer data_for_children, */ static gboolean -query_restore_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +query_restore_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, gpointer *data_for_children, + gpointer *result, const gchar *tag, gchar **attrs) { Query *q; q = xaccMallocQuery(); @@ -237,12 +232,9 @@ query_restore_fail_handler(gpointer data_for_children, */ static gboolean -query_and_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +query_and_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, gpointer *data_for_children, + gpointer *result, const gchar *tag, gchar **attrs) { Query *q; @@ -346,12 +338,11 @@ qrestore_genericpred_end_handler(gpointer data_for_children, */ static gboolean -qrestore_datepred_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +qrestore_datepred_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, + gpointer *data_for_children, + gpointer *result, const gchar *tag, + gchar **attrs) { DatePredicateData *dp = g_new (DatePredicateData, 1); g_return_val_if_fail(dp, FALSE); diff --git a/src/engine/Transaction-xml-parser-v1.c b/src/engine/Transaction-xml-parser-v1.c index b475cbeb0f..5eead365bc 100644 --- a/src/engine/Transaction-xml-parser-v1.c +++ b/src/engine/Transaction-xml-parser-v1.c @@ -42,12 +42,9 @@ */ static gboolean -transaction_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +transaction_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, gpointer *data_for_children, + gpointer *result, const gchar *tag, gchar **attrs) { /* pass the parent data down to the children */ *data_for_children = parent_data; @@ -89,12 +86,9 @@ transaction_start_handler(GSList* sibling_data, */ static gboolean -txn_restore_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +txn_restore_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, gpointer *data_for_children, + gpointer *result, const gchar *tag, gchar **attrs) { Transaction *trans = xaccMallocTransaction(); g_return_val_if_fail(trans, FALSE); @@ -392,12 +386,10 @@ txn_rest_date_entered_end_handler(gpointer data_for_children, */ static gboolean -txn_restore_split_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +txn_restore_split_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, + gpointer *data_for_children, gpointer *result, + const gchar *tag, gchar **attrs) { Split *s = xaccMallocSplit(); g_return_val_if_fail(s, FALSE); diff --git a/src/engine/io-gncxml-r.c b/src/engine/io-gncxml-r.c index 3d921f0474..d9b13ae502 100644 --- a/src/engine/io-gncxml-r.c +++ b/src/engine/io-gncxml-r.c @@ -103,10 +103,9 @@ sixtp_handle_catastrophe(sixtp_sax_data *sax_data) { while(*stack) { sixtp_stack_frame *current_frame = (sixtp_stack_frame *) (*stack)->data; - sixtp_fail_handler fail_handler = current_frame->parser->fail_handler; /* cleanup the current frame */ - if(fail_handler) { + if(current_frame->parser->fail_handler) { GSList *sibling_data; gpointer parent_data; @@ -121,19 +120,21 @@ sixtp_handle_catastrophe(sixtp_sax_data *sax_data) { sibling_data = parent_frame->data_from_children; } - fail_handler(current_frame->data_for_children, - current_frame->data_from_children, - sibling_data, - parent_data, - sax_data->global_data, - ¤t_frame->frame_data, - current_frame->tag); + current_frame->parser->fail_handler(current_frame->data_for_children, + current_frame->data_from_children, + sibling_data, + parent_data, + sax_data->global_data, + ¤t_frame->frame_data, + current_frame->tag); } /* now cleanup any children's results */ for(lp = current_frame->data_from_children; lp; lp = lp->next) { 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); @@ -180,7 +181,7 @@ sixtp_setup_parser (sixtp *sixtp, sax_data->global_data, &top_frame->data_for_children, &top_frame->frame_data, - NULL); + NULL, NULL); } if(!sax_data->parsing_ok) { @@ -344,45 +345,7 @@ typedef struct { } 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 . If not, it's an - error. - - Example: - - - NASDAQ - XYZZY - Grue Enterprises - XXX - 100 - - - - */ - -/**************/ -/* - * - * Does nothing. -*/ - - -/* ==================================================================== */ - - - /* ================================================================= */ -/* ================================================================= */ -/* ================================================================= */ -/* ================================================================= */ -/****************************************************************************/ /* (lineage ) Fancy and strange - look for an integer version number. If we get diff --git a/src/engine/sixtp-kvp-parser.c b/src/engine/sixtp-kvp-parser.c index 91dd16d00a..b29e8ed110 100644 --- a/src/engine/sixtp-kvp-parser.c +++ b/src/engine/sixtp-kvp-parser.c @@ -600,12 +600,9 @@ kvp_frame_slot_parser_new(sixtp *kvp_frame_parser) { */ static gboolean -kvp_frame_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +kvp_frame_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, gpointer *data_for_children, + gpointer *result, const gchar *tag, gchar **attrs) { kvp_frame *f = kvp_frame_new(); g_return_val_if_fail(f, FALSE); diff --git a/src/engine/sixtp-utils.c b/src/engine/sixtp-utils.c index b4dc481cf8..37fd511582 100644 --- a/src/engine/sixtp-utils.c +++ b/src/engine/sixtp-utils.c @@ -417,12 +417,10 @@ string_to_timespec_nsecs(const gchar *str, Timespec *ts) { */ gboolean -generic_timespec_start_handler(GSList* sibling_data, - gpointer parent_data, - gpointer global_data, - gpointer *data_for_children, - gpointer *result, - const gchar *tag) +generic_timespec_start_handler(GSList* sibling_data, gpointer parent_data, + gpointer global_data, + gpointer *data_for_children, gpointer *result, + const gchar *tag, gchar **attrs) { TimespecParseInfo *tsp = g_new0(TimespecParseInfo, 1); g_return_val_if_fail(tsp, FALSE); diff --git a/src/engine/sixtp-utils.h b/src/engine/sixtp-utils.h index 22f0a79735..a86bd25b14 100644 --- a/src/engine/sixtp-utils.h +++ b/src/engine/sixtp-utils.h @@ -65,7 +65,7 @@ gboolean generic_timespec_start_handler(GSList* sibling_data, gpointer global_data, gpointer *data_for_children, gpointer *result, - const gchar *tag); + const gchar *tag, gchar **attrs); gboolean timespec_parse_ok(TimespecParseInfo *info); diff --git a/src/engine/sixtp.c b/src/engine/sixtp.c index c69f88dab0..89599115e5 100644 --- a/src/engine/sixtp.c +++ b/src/engine/sixtp.c @@ -6,6 +6,7 @@ static short module = MOD_IO; +/************************************************************************/ gboolean is_child_result_from_node_named(sixtp_child_result *cr, const char *tag) { 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); } +/************************************************************************/ + + +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_new(void) { sixtp *s = g_new0(sixtp, 1); @@ -47,6 +106,98 @@ sixtp_new(void) { 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 sixtp_sax_start_handler(void *user_data, const xmlChar *name, @@ -123,7 +274,8 @@ sixtp_sax_start_handler(void *user_data, pdata->global_data, &new_frame->data_for_children, &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); } } - -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); -} diff --git a/src/engine/sixtp.h b/src/engine/sixtp.h index 1cf1898cd1..672d725040 100644 --- a/src/engine/sixtp.h +++ b/src/engine/sixtp.h @@ -41,8 +41,8 @@ typedef gboolean (*sixtp_start_handler)(GSList* sibling_data, gpointer global_data, gpointer *data_for_children, gpointer *result, - - const gchar *tag); + const gchar *tag, + gchar **attrs); typedef gboolean (*sixtp_before_child_handler)(gpointer data_for_children, GSList* data_from_children, @@ -50,7 +50,6 @@ typedef gboolean (*sixtp_before_child_handler)(gpointer data_for_children, gpointer parent_data, gpointer global_data, gpointer *result, - const gchar *tag, const gchar *child_tag); @@ -60,7 +59,6 @@ typedef gboolean (*sixtp_after_child_handler)(gpointer data_for_children, gpointer parent_data, gpointer global_data, gpointer *result, - const gchar *tag, const gchar *child_tag, sixtp_child_result *child_result); @@ -71,14 +69,12 @@ typedef gboolean (*sixtp_end_handler)(gpointer data_for_children, gpointer parent_data, gpointer global_data, gpointer *result, - const gchar *tag); typedef gboolean (*sixtp_characters_handler)(GSList *sibling_data, gpointer parent_data, gpointer global_data, gpointer *result, - const char *text, int length); @@ -152,7 +148,6 @@ void sixtp_sax_end_handler(void *user_data, const xmlChar *name); sixtp* sixtp_new(void); 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_before_child(sixtp *parser, sixtp_before_child_handler handler);