James LewisMoss's xml patch.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3526 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-01-25 22:52:08 +00:00
parent 126f274e17
commit 0535856463
14 changed files with 567 additions and 474 deletions

View File

@ -481,78 +481,74 @@ acc_restore_parent_end_handler(gpointer data_for_children,
return(TRUE);
}
sixtp*
parent_lookup_parser_new()
{
return sixtp_set_any(sixtp_new(), TRUE,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID,
acc_restore_parent_end_handler,
SIXTP_NO_MORE_HANDLERS);
}
sixtp *
gnc_account_parser_new(void)
{
sixtp *restore_pr;
sixtp *acc_restore_currency_pr;
sixtp *acc_restore_security_pr;
sixtp *acc_restore_parent_pr;
sixtp *acc_restore_parent_guid_pr;
sixtp *acc_restore_slots_pr;
sixtp *ret;
/* <account> */
ret = sixtp_new();
g_return_val_if_fail(ret, NULL);
sixtp_set_start(ret, account_start_handler);
sixtp_set_chars(ret, allow_and_ignore_only_whitespace);
if(!(ret = sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, account_start_handler,
SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
/* <account> <restore> */
restore_pr = setup_restorer(ret, account_restore_start_handler,
account_restore_end_handler,
account_restore_fail_handler,
account_restore_after_child_handler);
g_return_val_if_fail(restore_pr, NULL);
if(!(restore_pr =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, account_restore_start_handler,
SIXTP_END_HANDLER_ID, account_restore_end_handler,
SIXTP_FAIL_HANDLER_ID, account_restore_fail_handler,
SIXTP_AFTER_CHILD_HANDLER_ID,
account_restore_after_child_handler,
SIXTP_NO_MORE_HANDLERS)))
{
sixtp_destroy(ret);
return NULL;
}
/* <restore> (<name> | <guid> | <type> | <code> | <description> | <notes>)*/
sixtp_add_sub_parser(
restore_pr, "name",
restore_char_generator(acc_restore_name_end_handler));
sixtp_add_sub_parser(
restore_pr, "guid",
restore_char_generator(acc_restore_guid_end_handler));
sixtp_add_sub_parser(
restore_pr, "type",
restore_char_generator(acc_restore_type_end_handler));
sixtp_add_sub_parser(
restore_pr, "code",
restore_char_generator(acc_restore_code_end_handler));
sixtp_add_sub_parser(
restore_pr, "description",
restore_char_generator(acc_restore_description_end_handler));
sixtp_add_sub_parser(
restore_pr, "notes",
restore_char_generator(acc_restore_notes_end_handler));
if(!sixtp_add_some_sub_parsers(
restore_pr, TRUE,
"name", restore_char_generator(acc_restore_name_end_handler),
"guid", restore_char_generator(acc_restore_guid_end_handler),
"type", restore_char_generator(acc_restore_type_end_handler),
"code", restore_char_generator(acc_restore_code_end_handler),
"description",
restore_char_generator(acc_restore_description_end_handler),
"notes", restore_char_generator(acc_restore_notes_end_handler),
/* <account> <restore> <currency> */
"currency", generic_gnc_commodity_lookup_parser_new(),
/* <account> <restore> <security> */
"security", generic_gnc_commodity_lookup_parser_new(),
/* <account> <restore> <parent> */
"parent", sixtp_add_some_sub_parsers(
parent_lookup_parser_new(), TRUE,
"guid", generic_guid_parser_new(),
0),
"slots", kvp_frame_parser_new(),
0))
{
sixtp_destroy(ret);
return NULL;
}
/* <account> <restore> <currency> */
acc_restore_currency_pr = generic_gnc_commodity_lookup_parser_new();
g_return_val_if_fail(acc_restore_currency_pr, NULL);
sixtp_add_sub_parser(restore_pr, "currency", acc_restore_currency_pr);
/* <account> <restore> <security> */
acc_restore_security_pr = generic_gnc_commodity_lookup_parser_new();
g_return_val_if_fail(acc_restore_security_pr, NULL);
sixtp_add_sub_parser(restore_pr, "security", acc_restore_security_pr);
/* <account> <restore> <parent> */
acc_restore_parent_pr = sixtp_new();
g_return_val_if_fail(acc_restore_parent_pr, NULL);
sixtp_set_chars(acc_restore_parent_pr, allow_and_ignore_only_whitespace);
sixtp_set_end(acc_restore_parent_pr, acc_restore_parent_end_handler);
sixtp_add_sub_parser(restore_pr, "parent", acc_restore_parent_pr);
/* <account> <restore> <parent> <guid> */
acc_restore_parent_guid_pr = generic_guid_parser_new();
g_return_val_if_fail(acc_restore_parent_guid_pr, NULL);
sixtp_add_sub_parser(acc_restore_parent_pr, "guid",
acc_restore_parent_guid_pr);
/* <account> <restore> <slots> */
acc_restore_slots_pr = kvp_frame_parser_new();
g_return_val_if_fail(acc_restore_slots_pr, NULL);
sixtp_add_sub_parser(restore_pr, "slots", acc_restore_slots_pr);
sixtp_add_sub_parser(ret, "restore", restore_pr);
return ret;
}

View File

@ -172,18 +172,6 @@ commodity_restore_end_handler(gpointer data_for_children,
return(ok);
}
/* --------------------------------------------------- */
#define COM_PARSE(NAME) \
{ \
sixtp *tmp_pr = simple_chars_only_parser_new(NULL); \
if(!tmp_pr) { \
sixtp_destroy(top_level); \
return(NULL); \
} \
sixtp_add_sub_parser(restore_pr, #NAME, tmp_pr); \
}
/* --------------------------------------------------- */
sixtp *
commodity_restore_parser_new(void)
@ -194,23 +182,30 @@ commodity_restore_parser_new(void)
top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
restore_pr = setup_restorer(top_level,
commodity_restore_start_handler,
commodity_restore_end_handler,
generic_free_data_for_children,
commodity_restore_after_child_handler);
if(!restore_pr)
if(!(restore_pr = sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, commodity_restore_start_handler,
SIXTP_END_HANDLER_ID, commodity_restore_end_handler,
SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
SIXTP_AFTER_CHILD_HANDLER_ID, commodity_restore_after_child_handler,
SIXTP_NO_MORE_HANDLERS)))
{
sixtp_destroy(top_level);
return(NULL);
}
COM_PARSE(space);
COM_PARSE(id);
COM_PARSE(name);
COM_PARSE(xcode);
COM_PARSE(fraction);
sixtp_add_sub_parser(top_level, "restore", restore_pr);
if(!sixtp_add_some_sub_parsers(
restore_pr, TRUE,
"space", simple_chars_only_parser_new(NULL),
"id", simple_chars_only_parser_new(NULL),
"name", simple_chars_only_parser_new(NULL),
"xcode", simple_chars_only_parser_new(NULL),
"fraction", simple_chars_only_parser_new(NULL),
0))
{
return NULL;
}
return(top_level);
}
@ -337,33 +332,29 @@ generic_gnc_commodity_lookup_end_handler(gpointer data_for_children,
sixtp *
generic_gnc_commodity_lookup_parser_new(void)
{
sixtp *top_level = sixtp_new();
sixtp *namespace_pr;
sixtp *id_pr;
sixtp *top_level;
g_return_val_if_fail(top_level, NULL);
sixtp_set_start(top_level, generic_gnc_commodity_lookup_start_handler);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, generic_gnc_commodity_lookup_end_handler);
sixtp_set_fail(top_level, generic_free_data_for_children);
sixtp_set_after_child(top_level,
generic_gnc_commodity_lookup_after_child_handler);
namespace_pr = simple_chars_only_parser_new(NULL);
if(!namespace_pr) {
sixtp_destroy(top_level);
return(NULL);
if(!(top_level = sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, generic_gnc_commodity_lookup_start_handler,
SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, generic_gnc_commodity_lookup_end_handler,
SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
SIXTP_AFTER_CHILD_HANDLER_ID,
generic_gnc_commodity_lookup_after_child_handler,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
sixtp_add_sub_parser(top_level, "space", namespace_pr);
id_pr = simple_chars_only_parser_new(NULL);
if(!id_pr) {
sixtp_destroy(top_level);
return(NULL);
if(!sixtp_add_some_sub_parsers(
top_level, TRUE,
"space", simple_chars_only_parser_new(NULL),
"id", simple_chars_only_parser_new(NULL),
0))
{
return NULL;
}
sixtp_add_sub_parser(top_level, "id", id_pr);
return(top_level);
}

View File

@ -105,43 +105,30 @@ sixtp*
ledger_data_parser_new(void)
{
sixtp *top_level;
sixtp *acc_pr;
sixtp *com_pr;
sixtp *tran_pr;
/* <ledger-data> */
top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
sixtp_set_start(top_level, ledger_data_start_handler);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, ledger_data_end_handler);
sixtp_set_cleanup_result(top_level, ledger_data_result_cleanup);
sixtp_set_fail(top_level, ledger_data_fail_handler);
sixtp_set_result_fail(top_level, ledger_data_result_cleanup);
/* <commodity> */
com_pr = commodity_restore_parser_new();
if(!com_pr) {
sixtp_destroy(top_level);
return(NULL);
if(!(top_level = sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, ledger_data_start_handler,
SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, ledger_data_end_handler,
SIXTP_CLEANUP_RESULT_ID, ledger_data_result_cleanup,
SIXTP_FAIL_HANDLER_ID, ledger_data_fail_handler,
SIXTP_RESULT_FAIL_ID, ledger_data_result_cleanup,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
sixtp_add_sub_parser(top_level, "commodity", com_pr);
acc_pr = gnc_account_parser_new();
if(!acc_pr) {
sixtp_destroy(top_level);
return(NULL);
if(!sixtp_add_some_sub_parsers(
top_level, TRUE,
"commodity", commodity_restore_parser_new(),
"account", gnc_account_parser_new(),
"transaction", gnc_transaction_parser_new(),
0))
{
return NULL;
}
sixtp_add_sub_parser(top_level, "account", acc_pr);
/* <transaction> */
tran_pr = gnc_transaction_parser_new();
if(!tran_pr) {
sixtp_destroy(top_level);
return(NULL);
}
sixtp_add_sub_parser(top_level, "transaction", tran_pr);
return(top_level);
}

View File

@ -427,60 +427,31 @@ generic_pred_sense_end_handler(gpointer data_for_children,
return(TRUE);
}
/* --------------------------------------------------- */
#define PRED_PARSE(PRED,NAME,TOK) \
{ \
sixtp *tmp_pr = simple_chars_only_parser_new(NULL); \
if(!tmp_pr) { \
sixtp_destroy(top_level); \
return(NULL); \
} \
sixtp_set_end(tmp_pr, PRED##_##NAME##_end_handler); \
sixtp_add_sub_parser(top_level, TOK, tmp_pr); \
static sixtp*
pred_parser_new(sixtp_end_handler ender)
{
return sixtp_set_any(simple_chars_only_parser_new(NULL), FALSE,
SIXTP_END_HANDLER_ID, ender,
SIXTP_NO_MORE_HANDLERS);
}
/* --------------------------------------------------- */
/* ================================================================= */
static sixtp*
qrestore_datepred_parser_new(void)
{
sixtp *top_level = sixtp_new();
sixtp *restore_pr = top_level;
g_return_val_if_fail(top_level, NULL);
PRED_PARSE(generic_pred, sense, "sense");
PRED_PARSE(datepred, use_start, "use-start");
PRED_PARSE(datepred, use_end, "use-end");
sixtp_add_sub_parser(
restore_pr, "start-date",
generic_timespec_parser_new(datepred_start_date_end_handler));
sixtp_add_sub_parser(
restore_pr, "end-date",
generic_timespec_parser_new(datepred_end_date_end_handler));
return(top_level);
return sixtp_add_some_sub_parsers(
sixtp_new(), TRUE,
"sense", pred_parser_new(generic_pred_sense_end_handler),
"use-start", pred_parser_new(datepred_use_start_end_handler),
"use-end", pred_parser_new(datepred_use_end_end_handler),
"start-date",
generic_timespec_parser_new(datepred_start_date_end_handler),
"end-date",
generic_timespec_parser_new(datepred_end_date_end_handler),
0);
}
/* ================================================================= */
/* Generic predicate restorion macro */
#define RESTORE_PRED(NAME,TOK,REST) \
{ \
sixtp *tmp_pr = REST##_##NAME##_parser_new(); \
if(!tmp_pr) { \
sixtp_destroy(top_level); \
return(NULL); \
} \
sixtp_set_start(tmp_pr, REST##_##NAME##_start_handler); \
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace); \
sixtp_set_end(tmp_pr, qrestore_genericpred_end_handler); \
/* sixtp_set_after_child(tmp_pr, REST##_##NAME##_after_child_handler); */ \
sixtp_set_fail(tmp_pr, REST##_##NAME##_fail_handler); \
sixtp_add_sub_parser(and_pr, TOK, tmp_pr); \
}
/* ================================================================= */
sixtp*
query_server_parser_new (void)
{
@ -488,50 +459,76 @@ query_server_parser_new (void)
sixtp *query_pr;
sixtp *restore_pr;
sixtp *and_pr;
sixtp *date_pred_pr;
/* <query_server> */
top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
sixtp_set_start(top_level, query_server_start_handler);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, query_server_end_handler);
if(!(top_level =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, query_server_start_handler,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, query_server_end_handler,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
/* <query_server> <query> */
query_pr = sixtp_new();
if (!query_pr) {
if(!(query_pr =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, query_start_handler,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, query_end_handler,
SIXTP_NO_MORE_HANDLERS)))
{
sixtp_destroy(top_level);
return (NULL);
}
sixtp_set_start(query_pr, query_start_handler);
sixtp_set_chars(query_pr, allow_and_ignore_only_whitespace);
sixtp_set_end(query_pr, query_end_handler);
sixtp_add_sub_parser(top_level, "query", query_pr);
/* <query> <restore> */
restore_pr = setup_restorer(query_pr,
query_restore_start_handler,
query_restore_end_handler,
query_restore_fail_handler,
query_restore_after_child_handler);
if(!restore_pr)
if(!(restore_pr = sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, query_restore_start_handler,
SIXTP_END_HANDLER_ID, query_restore_end_handler,
SIXTP_FAIL_HANDLER_ID, query_restore_fail_handler,
SIXTP_AFTER_CHILD_HANDLER_ID, query_restore_after_child_handler,
SIXTP_NO_MORE_HANDLERS)))
{
sixtp_destroy(top_level);
return(NULL);
}
sixtp_add_sub_parser(query_pr, "restore", restore_pr);
/* <query> <restore> <and-terms> */
and_pr = sixtp_new();
if (!and_pr) {
if(!(and_pr =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, query_and_start_handler,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, query_and_end_handler,
SIXTP_FAIL_HANDLER_ID, query_and_fail_handler,
SIXTP_NO_MORE_HANDLERS)))
{
sixtp_destroy(top_level);
return (NULL);
}
sixtp_set_start(and_pr, query_and_start_handler);
sixtp_set_chars(and_pr, allow_and_ignore_only_whitespace);
sixtp_set_end(and_pr, query_and_end_handler);
sixtp_set_fail(and_pr, query_and_fail_handler);
sixtp_add_sub_parser(restore_pr, "and-terms", and_pr);
RESTORE_PRED(datepred, "date-pred", qrestore);
if(!(date_pred_pr =
sixtp_set_any(qrestore_datepred_parser_new(), FALSE,
SIXTP_START_HANDLER_ID, qrestore_datepred_start_handler,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, qrestore_genericpred_end_handler,
SIXTP_FAIL_HANDLER_ID, qrestore_datepred_fail_handler,
SIXTP_NO_MORE_HANDLERS)))
{
sixtp_destroy(top_level);
return NULL;
}
sixtp_add_sub_parser(and_pr, "date-pred", date_pred_pr);
return(top_level);
}

View File

@ -740,65 +740,41 @@ static sixtp *
gnc_txn_restore_split_parser_new(void)
{
sixtp *top_level;
sixtp *restore_pr;
sixtp *damount_pr;
sixtp *value_pr;
sixtp *tmp_pr;
top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
sixtp_set_start(top_level, txn_restore_split_start_handler);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, txn_restore_split_end_handler);
sixtp_set_fail(top_level, txn_restore_split_fail_handler);
sixtp_set_after_child(top_level, txn_restore_split_after_child_handler);
/* <restore> (<guid> | <memo> | <action> | <account> | <reconcile-state>) */
restore_pr = top_level;
sixtp_add_sub_parser(
restore_pr, "guid",
restore_char_generator(txn_restore_split_guid_end_handler));
sixtp_add_sub_parser(
restore_pr, "memo",
restore_char_generator(txn_restore_split_memo_end_handler));
sixtp_add_sub_parser(
restore_pr, "action",
restore_char_generator(txn_restore_split_action_end_handler));
sixtp_add_sub_parser(
restore_pr, "account",
restore_char_generator(txn_restore_split_account_end_handler));
sixtp_add_sub_parser(
restore_pr, "reconcile-state",
restore_char_generator(txn_restore_split_reconcile_state_end_handler));
/* <restore> <reconcile-date> */
sixtp_add_sub_parser(
restore_pr, "reconcile-date",
generic_timespec_parser_new(txn_restore_split_reconcile_date_end_handler));
/* <restore> <quantity> */
damount_pr = generic_gnc_numeric_parser_new();
if(!damount_pr) {
sixtp_destroy(top_level);
return(NULL);
if(!(top_level =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, txn_restore_split_start_handler,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, txn_restore_split_end_handler,
SIXTP_FAIL_HANDLER_ID, txn_restore_split_fail_handler,
SIXTP_AFTER_CHILD_HANDLER_ID,
txn_restore_split_after_child_handler,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
sixtp_add_sub_parser(top_level, "quantity", damount_pr);
/* <restore> <value> */
value_pr = generic_gnc_numeric_parser_new();
if(!value_pr) {
sixtp_destroy(top_level);
return(NULL);
if(!sixtp_add_some_sub_parsers(
top_level, TRUE,
"guid", restore_char_generator(txn_restore_split_guid_end_handler),
"memo", restore_char_generator(txn_restore_split_memo_end_handler),
"action",
restore_char_generator(txn_restore_split_action_end_handler),
"account",
restore_char_generator(txn_restore_split_account_end_handler),
"reconcile-state",
restore_char_generator(txn_restore_split_reconcile_state_end_handler),
"reconcile-date",
generic_timespec_parser_new(
txn_restore_split_reconcile_date_end_handler),
"quantity", generic_gnc_numeric_parser_new(),
"value", generic_gnc_numeric_parser_new(),
"slots", kvp_frame_parser_new(),
0))
{
return NULL;
}
sixtp_add_sub_parser(top_level, "value", value_pr);
/* <restore> <slots> */
tmp_pr = kvp_frame_parser_new();
if(!tmp_pr) {
sixtp_destroy(top_level);
return(NULL);
}
sixtp_add_sub_parser(top_level, "slots", tmp_pr);
return(top_level);
}
@ -810,61 +786,51 @@ gnc_transaction_parser_new(void)
{
sixtp *top_level;
sixtp *restore_pr;
sixtp *split_pr;
sixtp *tmp_pr;
top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
sixtp_set_start(top_level, transaction_start_handler);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_after_child(top_level, txn_restore_after_child_handler);
if(!(top_level =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, transaction_start_handler,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_AFTER_CHILD_HANDLER_ID,
txn_restore_after_child_handler,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
/* <restore> */
restore_pr = setup_restorer(top_level,
txn_restore_start_handler,
txn_restore_end_handler,
txn_restore_fail_handler,
txn_restore_after_child_handler);
if(!restore_pr)
if(!(restore_pr =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, txn_restore_start_handler,
SIXTP_END_HANDLER_ID, txn_restore_end_handler,
SIXTP_FAIL_HANDLER_ID, txn_restore_fail_handler,
SIXTP_AFTER_CHILD_HANDLER_ID,
txn_restore_after_child_handler,
SIXTP_NO_MORE_HANDLERS)))
{
sixtp_destroy(top_level);
return(NULL);
}
sixtp_add_sub_parser(top_level, "restore", restore_pr);
/* <restore> (<guid> | <num> | <description> ) */
sixtp_add_sub_parser(
restore_pr, "guid",
restore_char_generator(txn_restore_guid_end_handler));
sixtp_add_sub_parser(
restore_pr, "num",
restore_char_generator(txn_restore_num_end_handler));
sixtp_add_sub_parser(
restore_pr, "description",
restore_char_generator(txn_restore_description_end_handler));
/* <restore> (<date-posted> | <date-entered>) */
sixtp_add_sub_parser(
restore_pr, "date-posted",
generic_timespec_parser_new(txn_rest_date_posted_end_handler));
sixtp_add_sub_parser(
restore_pr, "date-entered",
generic_timespec_parser_new(txn_rest_date_entered_end_handler));
/* <restore> <slots> */
tmp_pr = kvp_frame_parser_new();
if(!tmp_pr) {
sixtp_destroy(top_level);
return(NULL);
if(!(sixtp_add_some_sub_parsers(
restore_pr, TRUE,
"guid", restore_char_generator(txn_restore_guid_end_handler),
"num", restore_char_generator(txn_restore_num_end_handler),
"description",
restore_char_generator(txn_restore_description_end_handler),
"date-posted",
generic_timespec_parser_new(txn_rest_date_posted_end_handler),
"date-entered",
generic_timespec_parser_new(txn_rest_date_entered_end_handler),
"slots", kvp_frame_parser_new(),
"split", gnc_txn_restore_split_parser_new(),
0)))
{
sixtp_destroy(top_level);
return NULL;
}
sixtp_add_sub_parser(restore_pr, "slots", tmp_pr);
/* <restore> <split> */
split_pr = gnc_txn_restore_split_parser_new();
if(!split_pr) {
sixtp_destroy(top_level);
return(NULL);
}
sixtp_add_sub_parser(restore_pr, "split", split_pr);
return(top_level);
}

View File

@ -508,13 +508,12 @@ gnc_parser_after_child_handler(gpointer data_for_children,
static sixtp*
gnc_parser_new(void)
{
sixtp *top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_before_child(top_level, gnc_parser_before_child_handler);
sixtp_set_after_child(top_level, gnc_parser_after_child_handler);
return(top_level);
return sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
SIXTP_BEFORE_CHILD_HANDLER_ID, gnc_parser_before_child_handler,
SIXTP_AFTER_CHILD_HANDLER_ID, gnc_parser_after_child_handler,
SIXTP_NO_MORE_HANDLERS);
}
/* ================================================================== */

View File

@ -54,16 +54,15 @@ kvp_value_result_cleanup(sixtp_child_result *cr)
static sixtp*
simple_kvp_value_parser_new(sixtp_end_handler end_handler)
{
sixtp *top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
sixtp_set_chars(top_level, generic_accumulate_chars);
sixtp_set_end(top_level, end_handler);
sixtp_set_cleanup_result(top_level, kvp_value_result_cleanup);
sixtp_set_cleanup_chars(top_level, sixtp_child_free_data);
sixtp_set_result_fail(top_level, kvp_value_result_cleanup);
sixtp_set_chars_fail(top_level, sixtp_child_free_data);
return(top_level);
return sixtp_set_any(sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID,
generic_accumulate_chars,
SIXTP_END_HANDLER_ID, end_handler,
SIXTP_CLEANUP_RESULT_ID, kvp_value_result_cleanup,
SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
SIXTP_RESULT_FAIL_ID, kvp_value_result_cleanup,
SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
SIXTP_NO_MORE_HANDLERS);
}
/* <gint64> - gint64 kvp_value parser.
@ -353,23 +352,17 @@ kvp_frame_binary_end_handler(gpointer data_for_children,
static sixtp*
binary_kvp_value_parser_new(void)
{
sixtp *top_level = sixtp_new();
sixtp *hex_pr;
g_return_val_if_fail(top_level, NULL);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, kvp_frame_binary_end_handler);
sixtp_set_cleanup_result(top_level, kvp_value_result_cleanup);
sixtp_set_result_fail(top_level, kvp_value_result_cleanup);
hex_pr = hex_binary_kvp_value_parser_new();
if(!hex_pr) {
sixtp_destroy(top_level);
return(NULL);
}
sixtp_add_sub_parser(top_level, "hex", hex_pr);
return(top_level);
return sixtp_add_some_sub_parsers(
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, kvp_frame_binary_end_handler,
SIXTP_CLEANUP_RESULT_ID, kvp_value_result_cleanup,
SIXTP_RESULT_FAIL_ID, kvp_value_result_cleanup,
SIXTP_NO_MORE_HANDLERS),
TRUE,
"hex", hex_binary_kvp_value_parser_new(),
0);
}
/*********************************/
@ -453,22 +446,26 @@ add_all_kvp_value_parsers_as_sub_nodes(sixtp *p,
static sixtp*
glist_kvp_value_parser_new(sixtp *kvp_frame_parser) {
sixtp *top_level = sixtp_new();
sixtp *top_level = sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, glist_kvp_value_end_handler,
SIXTP_CLEANUP_RESULT_ID, kvp_value_result_cleanup,
SIXTP_RESULT_FAIL_ID, kvp_value_result_cleanup,
SIXTP_NO_MORE_HANDLERS);
if(!top_level)
{
return NULL;
}
g_return_val_if_fail(top_level, NULL);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, glist_kvp_value_end_handler);
sixtp_set_cleanup_result(top_level, kvp_value_result_cleanup);
sixtp_set_result_fail(top_level, kvp_value_result_cleanup);
if(!add_all_kvp_value_parsers_as_sub_nodes(top_level,
kvp_frame_parser,
top_level)) {
sixtp_destroy(top_level);
return(NULL);
}
if(!add_all_kvp_value_parsers_as_sub_nodes(top_level,
kvp_frame_parser,
top_level)) {
sixtp_destroy(top_level);
return(NULL);
}
return(top_level);
return(top_level);
}
/*********************************/
@ -554,15 +551,20 @@ kvp_frame_slot_end_handler(gpointer data_for_children,
static sixtp*
kvp_frame_slot_parser_new(sixtp *kvp_frame_parser) {
sixtp *top_level = sixtp_new();
sixtp *top_level;
sixtp *child_pr;
sixtp *glist_pr;
g_return_val_if_fail(kvp_frame_parser, NULL);
g_return_val_if_fail(top_level, NULL);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, kvp_frame_slot_end_handler);
if(!(top_level = sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, kvp_frame_slot_end_handler,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
child_pr = simple_chars_only_parser_new(NULL);
if(!child_pr) { sixtp_destroy(top_level); return(NULL); }
@ -645,21 +647,28 @@ kvp_frame_result_cleanup(sixtp_child_result *cr)
sixtp*
kvp_frame_parser_new(void)
{
sixtp *top_level = sixtp_new();
sixtp *child_pr;
sixtp *top_level;
g_return_val_if_fail(top_level, NULL);
if(!(top_level = sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, kvp_frame_start_handler,
SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, kvp_frame_end_handler,
SIXTP_CLEANUP_RESULT_ID, kvp_frame_result_cleanup,
SIXTP_RESULT_FAIL_ID, kvp_frame_result_cleanup,
SIXTP_FAIL_HANDLER_ID, kvp_frame_fail_handler,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
sixtp_set_start(top_level, kvp_frame_start_handler);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, kvp_frame_end_handler);
sixtp_set_cleanup_result(top_level, kvp_frame_result_cleanup);
sixtp_set_result_fail(top_level, kvp_frame_result_cleanup);
sixtp_set_fail(top_level, kvp_frame_fail_handler);
child_pr = kvp_frame_slot_parser_new(top_level);
if(!child_pr) { sixtp_destroy(top_level); return(NULL); }
sixtp_add_sub_parser(top_level, "s", child_pr);
if(!(sixtp_add_some_sub_parsers(
top_level, TRUE,
"s", kvp_frame_slot_parser_new(top_level),
0)))
{
return NULL;
}
return(top_level);
}

View File

@ -298,17 +298,17 @@ generic_return_chars_end_handler(gpointer data_for_children,
sixtp*
simple_chars_only_parser_new(sixtp_end_handler end_handler)
{
sixtp *top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
if(!end_handler) end_handler = generic_return_chars_end_handler;
sixtp_set_chars(top_level, generic_accumulate_chars);
sixtp_set_end(top_level, end_handler);
sixtp_set_cleanup_result(top_level, sixtp_child_free_data);
sixtp_set_cleanup_chars(top_level, sixtp_child_free_data);
sixtp_set_result_fail(top_level, sixtp_child_free_data);
sixtp_set_chars_fail(top_level, sixtp_child_free_data);
return(top_level);
return sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_END_HANDLER_ID, (end_handler
? end_handler
: generic_return_chars_end_handler),
SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
SIXTP_NO_MORE_HANDLERS);
}
@ -528,37 +528,41 @@ generic_timespec_nsecs_end_handler(gpointer data_for_children,
return(TRUE);
}
#define TIMESPEC_TOK(NAME,TOK) \
{ \
sixtp *tmp_pr = sixtp_new(); \
if(!tmp_pr) { \
sixtp_destroy(top_level); \
return(NULL); \
} \
sixtp_set_chars(tmp_pr, generic_accumulate_chars); \
sixtp_set_end(tmp_pr, generic_timespec_##NAME##_end_handler); \
sixtp_set_cleanup_chars(tmp_pr, sixtp_child_free_data); \
sixtp_set_chars_fail(tmp_pr, sixtp_child_free_data); \
sixtp_add_sub_parser(top_level, TOK, tmp_pr); \
static sixtp*
timespec_sixtp_new(sixtp_end_handler ender)
{
return sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
SIXTP_END_HANDLER_ID, ender,
SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
SIXTP_NO_MORE_HANDLERS);
}
sixtp *
generic_timespec_parser_new(sixtp_end_handler end_handler)
{
sixtp *top_level = sixtp_new();
sixtp *top_level =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, generic_timespec_start_handler,
SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
SIXTP_END_HANDLER_ID, end_handler,
SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
SIXTP_NO_MORE_HANDLERS);
g_return_val_if_fail(top_level, NULL);
sixtp_set_start(top_level, generic_timespec_start_handler);
sixtp_set_chars(top_level, allow_and_ignore_only_whitespace);
sixtp_set_end(top_level, end_handler);
sixtp_set_cleanup_result(top_level, sixtp_child_free_data);
sixtp_set_fail(top_level, generic_free_data_for_children);
sixtp_set_result_fail(top_level, sixtp_child_free_data);
TIMESPEC_TOK(secs, "s");
TIMESPEC_TOK(nsecs, "ns");
if(!sixtp_add_some_sub_parsers(
top_level, TRUE,
"s", timespec_sixtp_new(generic_timespec_secs_end_handler),
"ns", timespec_sixtp_new(generic_timespec_nsecs_end_handler),
0))
{
return NULL;
}
return(top_level);
}
@ -617,18 +621,15 @@ generic_guid_end_handler(gpointer data_for_children,
sixtp*
generic_guid_parser_new(void)
{
sixtp *top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
sixtp_set_chars(top_level, generic_accumulate_chars);
sixtp_set_cleanup_chars(top_level, sixtp_child_free_data);
sixtp_set_chars_fail(top_level, sixtp_child_free_data);
sixtp_set_end(top_level, generic_guid_end_handler);
sixtp_set_result_fail(top_level, sixtp_child_free_data);
sixtp_set_cleanup_result(top_level, sixtp_child_free_data);
return(top_level);
return sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
SIXTP_END_HANDLER_ID, generic_guid_end_handler,
SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
SIXTP_NO_MORE_HANDLERS);
}
/****************************************************************************/
@ -683,54 +684,27 @@ generic_gnc_numeric_end_handler(gpointer data_for_children,
sixtp*
generic_gnc_numeric_parser_new(void)
{
sixtp *top_level = sixtp_new();
g_return_val_if_fail(top_level, NULL);
sixtp_set_chars(top_level, generic_accumulate_chars);
sixtp_set_cleanup_chars(top_level, sixtp_child_free_data);
sixtp_set_chars_fail(top_level, sixtp_child_free_data);
sixtp_set_end(top_level, generic_gnc_numeric_end_handler);
sixtp_set_result_fail(top_level, sixtp_child_free_data);
sixtp_set_cleanup_result(top_level, sixtp_child_free_data);
return(top_level);
return sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
SIXTP_END_HANDLER_ID, generic_gnc_numeric_end_handler,
SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
SIXTP_NO_MORE_HANDLERS);
}
/***************************************************************************/
sixtp*
setup_restorer(sixtp *parent,
sixtp_start_handler starter,
sixtp_end_handler ender,
sixtp_fail_handler failer,
sixtp_after_child_handler afchilder)
{
sixtp *ret;
ret = sixtp_new();
g_return_val_if_fail(ret, NULL);
sixtp_set_start(ret, starter);
sixtp_set_chars(ret, allow_and_ignore_only_whitespace);
sixtp_set_end(ret, ender);
sixtp_set_fail(ret, failer);
sixtp_set_after_child(ret, afchilder);
sixtp_add_sub_parser(parent, "restore", ret);
return ret;
}
sixtp*
restore_char_generator(sixtp_end_handler ender)
{
sixtp *ret = sixtp_new();
g_return_val_if_fail(ret, NULL);
sixtp_set_chars(ret, generic_accumulate_chars);
sixtp_set_end(ret, ender);
sixtp_set_cleanup_chars(ret, sixtp_child_free_data);
sixtp_set_chars_fail(ret, sixtp_child_free_data);
return ret;
return sixtp_set_any(
sixtp_new(), FALSE,
SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
SIXTP_END_HANDLER_ID, ender,
SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
SIXTP_NO_MORE_HANDLERS);
}

View File

@ -100,12 +100,6 @@ gboolean generic_gnc_numeric_end_handler(
sixtp* generic_gnc_numeric_parser_new(void);
sixtp* setup_restorer(sixtp *parent,
sixtp_start_handler starter,
sixtp_end_handler ender,
sixtp_fail_handler failer,
sixtp_after_child_handler afchilder);
sixtp* restore_char_generator(sixtp_end_handler ender);

View File

@ -1,3 +1,7 @@
#include <glib.h>
#include <stdarg.h>
#include "sixtp.h"
#include "sixtp-stack.h"
@ -106,6 +110,89 @@ sixtp_new(void) {
return(s);
}
sixtp*
sixtp_set_any(sixtp *tochange, int cleanup, ...)
{
va_list ap;
sixtp_handler_type type;
va_start(ap, cleanup);
if(!tochange)
{
g_warning("Null tochange passed\n");
return NULL;
}
do
{
type = va_arg(ap, sixtp_handler_type);
switch(type)
{
case SIXTP_NO_MORE_HANDLERS:
va_end(ap);
return tochange;
case SIXTP_START_HANDLER_ID:
sixtp_set_start(tochange, va_arg(ap, sixtp_start_handler));
break;
case SIXTP_BEFORE_CHILD_HANDLER_ID:
sixtp_set_before_child(tochange,
va_arg(ap, sixtp_before_child_handler));
break;
case SIXTP_AFTER_CHILD_HANDLER_ID:
sixtp_set_after_child(tochange,
va_arg(ap, sixtp_after_child_handler));
break;
case SIXTP_END_HANDLER_ID:
sixtp_set_end(tochange, va_arg(ap, sixtp_end_handler));
break;
case SIXTP_CHARACTERS_HANDLER_ID:
sixtp_set_chars(tochange, va_arg(ap, sixtp_characters_handler));
break;
case SIXTP_FAIL_HANDLER_ID:
sixtp_set_fail(tochange, va_arg(ap, sixtp_fail_handler));
break;
case SIXTP_CLEANUP_RESULT_ID:
sixtp_set_cleanup_result(tochange,
va_arg(ap, sixtp_result_handler));
break;
case SIXTP_CLEANUP_CHARS_ID:
sixtp_set_cleanup_chars(tochange,
va_arg(ap, sixtp_result_handler));
break;
case SIXTP_RESULT_FAIL_ID:
sixtp_set_result_fail(tochange, va_arg(ap, sixtp_result_handler));
break;
case SIXTP_CHARS_FAIL_ID:
sixtp_set_chars_fail(tochange, va_arg(ap, sixtp_result_handler));
break;
default:
va_end(ap);
g_warning("Bogus sixtp type %d\n", type);
if(cleanup)
{
sixtp_destroy(tochange);
}
return NULL;
}
} while(1);
va_end(ap);
return tochange;
}
sixtp*
sixtp_new_full(sixtp_start_handler starter,
sixtp_before_child_handler cdbeforer,
@ -196,6 +283,67 @@ sixtp_add_sub_parser(sixtp *parser, const gchar* tag, sixtp *sub_parser) {
return(TRUE);
}
/*
* This is a bit complex because of having to make sure to
* cleanup things we haven't looked at on an error condition
*/
sixtp*
sixtp_add_some_sub_parsers(sixtp *tochange, int cleanup, ...)
{
int have_error;
va_list ap;
char *tag;
sixtp *handler;
va_start(ap, cleanup);
have_error = 0;
if(!tochange)
{
have_error = 1;
}
do
{
tag = va_arg(ap, char*);
if(!tag)
{
break;
}
handler = va_arg(ap, sixtp*);
if(!handler)
{
g_warning("Handler for tag %s is null\n", tag);
if(cleanup)
{
sixtp_destroy(tochange);
tochange = NULL;
have_error = 1;
}
else
{
va_end(ap);
return NULL;
}
}
if (have_error)
{
sixtp_destroy(handler);
}
else
{
sixtp_add_sub_parser(tochange, tag, handler);
}
} while (1);
va_end(ap);
return tochange;
}
/************************************************************************/
void

View File

@ -6,6 +6,8 @@
#include <glib.h>
#include <stdio.h>
#include <stdarg.h>
#ifdef HAVE_XML_VERSION_HEADER
#include <libxml/xmlversion.h>
#endif
@ -112,6 +114,25 @@ typedef struct sixtp {
GHashTable *children;
} sixtp;
typedef enum {
SIXTP_NO_MORE_HANDLERS,
SIXTP_START_HANDLER_ID,
SIXTP_BEFORE_CHILD_HANDLER_ID,
SIXTP_AFTER_CHILD_HANDLER_ID,
SIXTP_END_HANDLER_ID,
SIXTP_CHARACTERS_HANDLER_ID,
SIXTP_FAIL_HANDLER_ID,
SIXTP_CLEANUP_RESULT_ID,
SIXTP_CLEANUP_CHARS_ID,
SIXTP_RESULT_FAIL_ID,
SIXTP_CHARS_FAIL_ID,
} sixtp_handler_type;
typedef enum {
SIXTP_CHILD_RESULT_CHARS,
SIXTP_CHILD_RESULT_NODE
@ -160,6 +181,9 @@ void sixtp_set_fail(sixtp *parser, sixtp_fail_handler handler);
void sixtp_set_result_fail(sixtp *parser, sixtp_result_handler handler);
void sixtp_set_chars_fail(sixtp *parser, sixtp_result_handler handler);
sixtp* sixtp_set_any(sixtp *tochange, gboolean cleanup, ...);
sixtp* sixtp_add_some_sub_parsers(sixtp *tochange, gboolean cleanup, ...);
gboolean sixtp_add_sub_parser(sixtp *parser, const gchar* tag,
sixtp *sub_parser);

View File

@ -59,6 +59,8 @@ window_destroy_cb (GtkObject *object, gpointer data)
gnc_unregister_gui_component_by_data (DIALOG_TAX_INFO_CM_CLASS, ti_dialog);
g_free (ti_dialog);
return 1;
}
static void

View File

@ -59,6 +59,8 @@ window_destroy_cb (GtkObject *object, gpointer data)
gnc_unregister_gui_component_by_data (DRUID_STOCK_SPLIT_CM_CLASS, info);
g_free (info);
return 1;
}
static int

View File

@ -1052,6 +1052,8 @@ gnucash_sheet_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
(widget, event);
item_edit_focus_in (ITEM_EDIT(sheet->item_editor));
return 1;
}
static gboolean
@ -1064,6 +1066,8 @@ gnucash_sheet_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
(widget, event);
item_edit_focus_out (ITEM_EDIT(sheet->item_editor));
return 1;
}
static void