mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
turn on book support in the file backend
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6441 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
6b2a678e53
commit
50d07c4a17
@ -41,10 +41,12 @@
|
|||||||
#include "gnc-xml.h"
|
#include "gnc-xml.h"
|
||||||
#include "io-gncxml-gen.h"
|
#include "io-gncxml-gen.h"
|
||||||
#include "io-gncxml-v2.h"
|
#include "io-gncxml-v2.h"
|
||||||
|
#include "io-utils.h"
|
||||||
|
|
||||||
#include "sixtp-dom-parsers.h"
|
#include "sixtp-dom-parsers.h"
|
||||||
#include "gnc-book-p.h"
|
#include "gnc-book-p.h"
|
||||||
#include "gnc-book.h"
|
#include "gnc-book.h"
|
||||||
|
#include "gnc-engine-util.h"
|
||||||
#include "Group.h"
|
#include "Group.h"
|
||||||
|
|
||||||
const gchar *book_version_string = "2.0.0";
|
const gchar *book_version_string = "2.0.0";
|
||||||
@ -54,6 +56,7 @@ const gchar *book_version_string = "2.0.0";
|
|||||||
#define book_id_string "book:id"
|
#define book_id_string "book:id"
|
||||||
#define book_slots_string "book:slots"
|
#define book_slots_string "book:slots"
|
||||||
|
|
||||||
|
static short module = MOD_IO;
|
||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
|
|
||||||
@ -246,6 +249,50 @@ gnc_book_end_handler(gpointer data_for_children,
|
|||||||
return book != NULL;
|
return book != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gnc_book_id_end_handler(gpointer data_for_children,
|
||||||
|
GSList* data_from_children, GSList* sibling_data,
|
||||||
|
gpointer parent_data, gpointer global_data,
|
||||||
|
gpointer *result, const gchar *tag)
|
||||||
|
{
|
||||||
|
gboolean successful;
|
||||||
|
xmlNodePtr tree = (xmlNodePtr)data_for_children;
|
||||||
|
gxpf_data *gdata = (gxpf_data*)global_data;
|
||||||
|
GNCBook *book = gdata->bookdata;
|
||||||
|
|
||||||
|
if(parent_data) { return TRUE; }
|
||||||
|
if(!tag) { return TRUE; }
|
||||||
|
|
||||||
|
g_return_val_if_fail(tree, FALSE);
|
||||||
|
|
||||||
|
successful = book_id_handler (tree, book);
|
||||||
|
xmlFreeNode(tree);
|
||||||
|
|
||||||
|
return successful;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gnc_book_slots_end_handler(gpointer data_for_children,
|
||||||
|
GSList* data_from_children, GSList* sibling_data,
|
||||||
|
gpointer parent_data, gpointer global_data,
|
||||||
|
gpointer *result, const gchar *tag)
|
||||||
|
{
|
||||||
|
gboolean successful;
|
||||||
|
xmlNodePtr tree = (xmlNodePtr)data_for_children;
|
||||||
|
gxpf_data *gdata = (gxpf_data*)global_data;
|
||||||
|
GNCBook *book = gdata->bookdata;
|
||||||
|
|
||||||
|
if(parent_data) { return TRUE; }
|
||||||
|
if(!tag) { return TRUE; }
|
||||||
|
|
||||||
|
g_return_val_if_fail(tree, FALSE);
|
||||||
|
|
||||||
|
successful = book_slots_handler (tree, book);
|
||||||
|
xmlFreeNode(tree);
|
||||||
|
|
||||||
|
return successful;
|
||||||
|
}
|
||||||
|
|
||||||
GNCBook*
|
GNCBook*
|
||||||
dom_tree_to_book (xmlNodePtr node, GNCBook *book)
|
dom_tree_to_book (xmlNodePtr node, GNCBook *book)
|
||||||
{
|
{
|
||||||
@ -255,6 +302,7 @@ dom_tree_to_book (xmlNodePtr node, GNCBook *book)
|
|||||||
book);
|
book);
|
||||||
if (!successful)
|
if (!successful)
|
||||||
{
|
{
|
||||||
|
PERR ("failed to parse book");
|
||||||
book = NULL;
|
book = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,3 +314,16 @@ gnc_book_sixtp_parser_create(void)
|
|||||||
{
|
{
|
||||||
return sixtp_dom_parser_new(gnc_book_end_handler, NULL, NULL);
|
return sixtp_dom_parser_new(gnc_book_end_handler, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sixtp*
|
||||||
|
gnc_book_id_sixtp_parser_create(void)
|
||||||
|
{
|
||||||
|
return sixtp_dom_parser_new(gnc_book_id_end_handler, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
sixtp*
|
||||||
|
gnc_book_slots_sixtp_parser_create(void)
|
||||||
|
{
|
||||||
|
return sixtp_dom_parser_new(gnc_book_slots_end_handler, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ sixtp* gnc_account_sixtp_parser_create(void);
|
|||||||
|
|
||||||
xmlNodePtr gnc_book_dom_tree_create(GNCBook *book);
|
xmlNodePtr gnc_book_dom_tree_create(GNCBook *book);
|
||||||
sixtp* gnc_book_sixtp_parser_create(void);
|
sixtp* gnc_book_sixtp_parser_create(void);
|
||||||
|
sixtp* gnc_book_id_sixtp_parser_create(void);
|
||||||
|
sixtp* gnc_book_slots_sixtp_parser_create(void);
|
||||||
|
|
||||||
xmlNodePtr gnc_commodity_dom_tree_create(const gnc_commodity *com);
|
xmlNodePtr gnc_commodity_dom_tree_create(const gnc_commodity *com);
|
||||||
sixtp* gnc_commodity_sixtp_parser_create(void);
|
sixtp* gnc_commodity_sixtp_parser_create(void);
|
||||||
|
@ -51,6 +51,7 @@ static short module = MOD_IO;
|
|||||||
|
|
||||||
|
|
||||||
#define GNC_V2_STRING "gnc-v2"
|
#define GNC_V2_STRING "gnc-v2"
|
||||||
|
const gchar *book_version_string;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
run_callback(sixtp_gdv2 *data, const char *type)
|
run_callback(sixtp_gdv2 *data, const char *type)
|
||||||
@ -384,7 +385,7 @@ gnc_counter_end_handler(gpointer data_for_children,
|
|||||||
strval = dom_tree_to_text(tree);
|
strval = dom_tree_to_text(tree);
|
||||||
if(!string_to_gint64(strval, &val))
|
if(!string_to_gint64(strval, &val))
|
||||||
{
|
{
|
||||||
PWARN("string_to_gint64 failed with input: %s",
|
PERR ("string_to_gint64 failed with input: %s",
|
||||||
strval ? strval : "(null)");
|
strval ? strval : "(null)");
|
||||||
g_free (strval);
|
g_free (strval);
|
||||||
xmlFree (type);
|
xmlFree (type);
|
||||||
@ -414,7 +415,7 @@ gnc_counter_end_handler(gpointer data_for_children,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PWARN("Unknown type: %s",
|
PERR("Unknown type: %s",
|
||||||
type ? type : "(null)");
|
type ? type : "(null)");
|
||||||
xmlFree (type);
|
xmlFree (type);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -450,6 +451,8 @@ print_counter_data(load_counter data)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *BOOK_TAG = "gnc:book";
|
static const char *BOOK_TAG = "gnc:book";
|
||||||
|
static const char *BOOK_ID_TAG = "book:id";
|
||||||
|
static const char *BOOK_SLOTS_TAG = "book:slots";
|
||||||
static const char *ACCOUNT_TAG = "gnc:account";
|
static const char *ACCOUNT_TAG = "gnc:account";
|
||||||
static const char *PRICEDB_TAG = "gnc:pricedb";
|
static const char *PRICEDB_TAG = "gnc:pricedb";
|
||||||
static const char *COMMODITY_TAG = "gnc:commodity";
|
static const char *COMMODITY_TAG = "gnc:commodity";
|
||||||
@ -502,13 +505,13 @@ generic_callback(const char *tag, gpointer globaldata, gpointer data)
|
|||||||
if(safe_strcmp(tag, BOOK_TAG) == 0)
|
if(safe_strcmp(tag, BOOK_TAG) == 0)
|
||||||
{
|
{
|
||||||
add_book_local(gd, (GNCBook*)data);
|
add_book_local(gd, (GNCBook*)data);
|
||||||
|
book_callback(tag, globaldata, data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// PWARN ("importing pre-book-style XML data file");
|
// PWARN ("importing pre-book-style XML data file");
|
||||||
|
book_callback(tag, globaldata, data);
|
||||||
}
|
}
|
||||||
// xxx move me ...
|
|
||||||
book_callback(tag, globaldata, data);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,6 +524,7 @@ gnc_session_load_from_xml_file_v2(
|
|||||||
sixtp_gdv2 *gd;
|
sixtp_gdv2 *gd;
|
||||||
sixtp *top_parser;
|
sixtp *top_parser;
|
||||||
sixtp *main_parser;
|
sixtp *main_parser;
|
||||||
|
sixtp *book_parser;
|
||||||
|
|
||||||
gd = g_new0(sixtp_gdv2, 1);
|
gd = g_new0(sixtp_gdv2, 1);
|
||||||
|
|
||||||
@ -544,6 +548,7 @@ gnc_session_load_from_xml_file_v2(
|
|||||||
|
|
||||||
top_parser = sixtp_new();
|
top_parser = sixtp_new();
|
||||||
main_parser = sixtp_new();
|
main_parser = sixtp_new();
|
||||||
|
book_parser = sixtp_new();
|
||||||
|
|
||||||
if(!sixtp_add_some_sub_parsers(
|
if(!sixtp_add_some_sub_parsers(
|
||||||
top_parser, TRUE,
|
top_parser, TRUE,
|
||||||
@ -556,6 +561,27 @@ gnc_session_load_from_xml_file_v2(
|
|||||||
if(!sixtp_add_some_sub_parsers(
|
if(!sixtp_add_some_sub_parsers(
|
||||||
main_parser, TRUE,
|
main_parser, TRUE,
|
||||||
COUNT_DATA_TAG, gnc_counter_sixtp_parser_create(),
|
COUNT_DATA_TAG, gnc_counter_sixtp_parser_create(),
|
||||||
|
BOOK_TAG, book_parser,
|
||||||
|
|
||||||
|
/* the following are present here only to support
|
||||||
|
* the older, pre-book format. Basically, the top-level
|
||||||
|
* book is implicit. */
|
||||||
|
PRICEDB_TAG, gnc_pricedb_sixtp_parser_create(),
|
||||||
|
COMMODITY_TAG, gnc_commodity_sixtp_parser_create(),
|
||||||
|
ACCOUNT_TAG, gnc_account_sixtp_parser_create(),
|
||||||
|
TRANSACTION_TAG, gnc_transaction_sixtp_parser_create(),
|
||||||
|
SCHEDXACTION_TAG, gnc_schedXaction_sixtp_parser_create(),
|
||||||
|
TEMPLATE_TRANSACTION_TAG, gnc_template_transaction_sixtp_parser_create(),
|
||||||
|
NULL, NULL))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!sixtp_add_some_sub_parsers(
|
||||||
|
book_parser, TRUE,
|
||||||
|
BOOK_ID_TAG, gnc_book_id_sixtp_parser_create(),
|
||||||
|
BOOK_SLOTS_TAG, gnc_book_slots_sixtp_parser_create(),
|
||||||
|
COUNT_DATA_TAG, gnc_counter_sixtp_parser_create(),
|
||||||
PRICEDB_TAG, gnc_pricedb_sixtp_parser_create(),
|
PRICEDB_TAG, gnc_pricedb_sixtp_parser_create(),
|
||||||
COMMODITY_TAG, gnc_commodity_sixtp_parser_create(),
|
COMMODITY_TAG, gnc_commodity_sixtp_parser_create(),
|
||||||
ACCOUNT_TAG, gnc_account_sixtp_parser_create(),
|
ACCOUNT_TAG, gnc_account_sixtp_parser_create(),
|
||||||
@ -672,6 +698,61 @@ compare_commodity_ids(gconstpointer a, gconstpointer b)
|
|||||||
gnc_commodity_get_mnemonic(cb)));
|
gnc_commodity_get_mnemonic(cb)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void write_pricedb (FILE *out, GNCBook *book);
|
||||||
|
static void write_transactions (FILE *out, GNCBook *book);
|
||||||
|
static void write_template_transaction_data (FILE *out, GNCBook *book);
|
||||||
|
static void write_schedXactions(FILE *out, GNCBook *book);
|
||||||
|
|
||||||
|
static void
|
||||||
|
write_book(FILE *out, GNCBook *book)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
|
||||||
|
/* We can't just blast out the dom tree, because the dom tree
|
||||||
|
* doesn't have the books, transactions, etc underneath it.
|
||||||
|
* But that is just as well, since I think the performance
|
||||||
|
* will be much better if we write out as we go along
|
||||||
|
*/
|
||||||
|
xmlNodePtr node;
|
||||||
|
|
||||||
|
node = gnc_book_dom_tree_create(book);
|
||||||
|
|
||||||
|
if(!node)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlElemDump(out, NULL, node);
|
||||||
|
fprintf(out, "\n");
|
||||||
|
|
||||||
|
xmlFreeNode(node);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
fprintf( out, "<%s version=\"%s\">\n", BOOK_TAG, book_version_string );
|
||||||
|
write_book_parts (out, book);
|
||||||
|
|
||||||
|
write_counts(out,
|
||||||
|
"commodity",
|
||||||
|
gnc_commodity_table_get_size(
|
||||||
|
gnc_book_get_commodity_table(book)),
|
||||||
|
"account",
|
||||||
|
xaccGroupGetNumSubAccounts(gnc_book_get_group(book)),
|
||||||
|
"transaction",
|
||||||
|
gnc_book_count_transactions(book),
|
||||||
|
"schedxaction",
|
||||||
|
g_list_length( gnc_book_get_schedxactions(book) ),
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
write_commodities(out, book);
|
||||||
|
write_pricedb(out, book);
|
||||||
|
write_accounts(out, book);
|
||||||
|
write_transactions(out, book);
|
||||||
|
write_template_transaction_data(out, book);
|
||||||
|
write_schedXactions(out, book);
|
||||||
|
|
||||||
|
fprintf( out, "</%s>\n", BOOK_TAG );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
write_commodities(FILE *out, GNCBook *book)
|
write_commodities(FILE *out, GNCBook *book)
|
||||||
{
|
{
|
||||||
@ -828,28 +909,10 @@ gnc_book_write_to_xml_filehandle_v2(GNCBook *book, FILE *out)
|
|||||||
write_v2_header (out);
|
write_v2_header (out);
|
||||||
|
|
||||||
write_counts(out,
|
write_counts(out,
|
||||||
"commodity",
|
"book", 1,
|
||||||
gnc_commodity_table_get_size(
|
|
||||||
gnc_book_get_commodity_table(book)),
|
|
||||||
"account",
|
|
||||||
xaccGroupGetNumSubAccounts(gnc_book_get_group(book)),
|
|
||||||
"transaction",
|
|
||||||
gnc_book_count_transactions(book),
|
|
||||||
"schedxaction",
|
|
||||||
g_list_length( gnc_book_get_schedxactions(book) ),
|
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
write_commodities(out, book);
|
write_book(out, book);
|
||||||
|
|
||||||
write_pricedb(out, book);
|
|
||||||
|
|
||||||
write_accounts(out, book);
|
|
||||||
|
|
||||||
write_transactions(out, book);
|
|
||||||
|
|
||||||
write_template_transaction_data(out, book);
|
|
||||||
|
|
||||||
write_schedXactions(out, book);
|
|
||||||
|
|
||||||
fprintf(out, "</" GNC_V2_STRING ">\n\n");
|
fprintf(out, "</" GNC_V2_STRING ">\n\n");
|
||||||
|
|
||||||
@ -861,6 +924,7 @@ gnc_book_write_accounts_to_xml_filehandle_v2(GNCBook *book, FILE *out)
|
|||||||
{
|
{
|
||||||
if (!out) return FALSE;
|
if (!out) return FALSE;
|
||||||
|
|
||||||
|
PWARN ("huhhhh ???? Who is using this thing ??? \n");
|
||||||
write_v2_header (out);
|
write_v2_header (out);
|
||||||
|
|
||||||
write_counts(out,
|
write_counts(out,
|
||||||
|
Loading…
Reference in New Issue
Block a user