first pass at integrating book into file backend

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6425 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2001-12-30 17:38:01 +00:00
parent 77764be767
commit a83bda50a9
5 changed files with 63 additions and 12 deletions

View File

@ -12,6 +12,7 @@ libgncmod_backend_file_la_SOURCES = \
gncmod-backend-file.c \ gncmod-backend-file.c \
gnc-account-xml-v2.c \ gnc-account-xml-v2.c \
gnc-backend-file.c \ gnc-backend-file.c \
gnc-book-xml-v2.c \
gnc-commodity-xml-v2.c \ gnc-commodity-xml-v2.c \
gnc-freqspec-xml-v2.c \ gnc-freqspec-xml-v2.c \
gnc-pricedb-xml-v2.c \ gnc-pricedb-xml-v2.c \

View File

@ -37,6 +37,9 @@
xmlNodePtr gnc_account_dom_tree_create(Account *act); xmlNodePtr gnc_account_dom_tree_create(Account *act);
sixtp* gnc_account_sixtp_parser_create(void); sixtp* gnc_account_sixtp_parser_create(void);
xmlNodePtr gnc_book_dom_tree_create(GNCBook *book);
sixtp* gnc_book_sixtp_parser_create(void);
xmlNodePtr gnc_commodity_dom_tree_create(const gnc_commodity *act); xmlNodePtr gnc_commodity_dom_tree_create(const gnc_commodity *act);
sixtp* gnc_commodity_sixtp_parser_create(void); sixtp* gnc_commodity_sixtp_parser_create(void);

View File

@ -47,6 +47,9 @@
#include "io-utils.h" #include "io-utils.h"
static short module = MOD_IO;
#define GNC_V2_STRING "gnc-v2" #define GNC_V2_STRING "gnc-v2"
static void static void
@ -94,7 +97,7 @@ clear_up_account_commodity_session(
} }
else if(!gcom) else if(!gcom)
{ {
g_warning("unable to find global commodity for %s adding new", PWARN("unable to find global commodity for %s adding new",
gnc_commodity_get_unique_name(com)); gnc_commodity_get_unique_name(com));
gnc_commodity_table_insert(tbl, com); gnc_commodity_table_insert(tbl, com);
} }
@ -138,7 +141,7 @@ clear_up_account_commodity(
} }
else if(!gcom) else if(!gcom)
{ {
g_warning("unable to find global commodity for %s adding new", PWARN("unable to find global commodity for %s adding new",
gnc_commodity_get_unique_name(com)); gnc_commodity_get_unique_name(com));
gnc_commodity_table_insert(tbl, com); gnc_commodity_table_insert(tbl, com);
} }
@ -174,7 +177,7 @@ clear_up_transaction_commodity(
} }
else if(!gcom) else if(!gcom)
{ {
g_warning("unable to find global commodity for %s adding new", PWARN("unable to find global commodity for %s adding new",
gnc_commodity_get_unique_name(com)); gnc_commodity_get_unique_name(com));
gnc_commodity_table_insert(tbl, com); gnc_commodity_table_insert(tbl, com);
} }
@ -223,6 +226,15 @@ add_account_local(sixtp_gdv2 *data, Account *act)
return FALSE; return FALSE;
} }
static gboolean
add_book_local(sixtp_gdv2 *data, GNCBook *book)
{
data->counter.books_loaded++;
run_callback(data, "book");
return FALSE;
}
static gboolean static gboolean
add_commodity_local(sixtp_gdv2 *data, gnc_commodity *com) add_commodity_local(sixtp_gdv2 *data, gnc_commodity *com)
{ {
@ -372,7 +384,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))
{ {
g_warning("string_to_gint64 failed with input: %s", PWARN("string_to_gint64 failed with input: %s",
strval ? strval : "(null)"); strval ? strval : "(null)");
g_free (strval); g_free (strval);
xmlFree (type); xmlFree (type);
@ -388,6 +400,10 @@ gnc_counter_end_handler(gpointer data_for_children,
{ {
sixdata->counter.accounts_total = val; sixdata->counter.accounts_total = val;
} }
else if(safe_strcmp(type, "book") == 0)
{
sixdata->counter.books_total = val;
}
else if(safe_strcmp(type, "commodity") == 0) else if(safe_strcmp(type, "commodity") == 0)
{ {
sixdata->counter.commodities_total = val; sixdata->counter.commodities_total = val;
@ -398,7 +414,7 @@ gnc_counter_end_handler(gpointer data_for_children,
} }
else else
{ {
g_warning("Unknown type: %s", PWARN("Unknown type: %s",
type ? type : "(null)"); type ? type : "(null)");
xmlFree (type); xmlFree (type);
return FALSE; return FALSE;
@ -420,17 +436,20 @@ gnc_counter_sixtp_parser_create(void)
static void static void
print_counter_data(load_counter data) print_counter_data(load_counter data)
{ {
printf("Transactions: Total: %d, Loaded: %d\n", PINFO("Transactions: Total: %d, Loaded: %d\n",
data.transactions_total, data.transactions_loaded); data.transactions_total, data.transactions_loaded);
printf("Accounts: Total: %d, Loaded: %d\n", PINFO("Accounts: Total: %d, Loaded: %d\n",
data.accounts_total, data.accounts_loaded); data.accounts_total, data.accounts_loaded);
printf("Commodities: Total: %d, Loaded: %d\n", PINFO("Books: Total: %d, Loaded: %d\n",
data.books_total, data.books_loaded);
PINFO("Commodities: Total: %d, Loaded: %d\n",
data.commodities_total, data.commodities_loaded); data.commodities_total, data.commodities_loaded);
printf("Scheduled Tansactions: Total: %d, Loaded: %d\n", PINFO("Scheduled Tansactions: Total: %d, Loaded: %d\n",
data.schedXactions_total, data.schedXactions_loaded); data.schedXactions_total, data.schedXactions_loaded);
} }
#endif #endif
static const char *BOOK_TAG = "gnc:book";
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";
@ -440,7 +459,7 @@ static const char *SCHEDXACTION_TAG = "gnc:schedxaction";
static const char *TEMPLATE_TRANSACTION_TAG = "gnc:template-transactions"; static const char *TEMPLATE_TRANSACTION_TAG = "gnc:template-transactions";
static gboolean static gboolean
generic_callback(const char *tag, gpointer globaldata, gpointer data) book_callback(const char *tag, gpointer globaldata, gpointer data)
{ {
sixtp_gdv2 *gd = (sixtp_gdv2*)globaldata; sixtp_gdv2 *gd = (sixtp_gdv2*)globaldata;
@ -468,6 +487,28 @@ generic_callback(const char *tag, gpointer globaldata, gpointer data)
{ {
add_template_transaction_local( gd, (gnc_template_xaction_data*)data ); add_template_transaction_local( gd, (gnc_template_xaction_data*)data );
} }
else
{
PWARN ("unexpected tag %s", tag);
}
return TRUE;
}
static gboolean
generic_callback(const char *tag, gpointer globaldata, gpointer data)
{
sixtp_gdv2 *gd = (sixtp_gdv2*)globaldata;
if(safe_strcmp(tag, BOOK_TAG) == 0)
{
add_book_local(gd, (GNCBook*)data);
}
else
{
// PWARN ("importing pre-book-style XML data file");
}
// xxx move me ...
book_callback(tag, globaldata, data);
return TRUE; return TRUE;
} }
@ -488,6 +529,8 @@ gnc_session_load_from_xml_file_v2(
gd->book = book; gd->book = book;
gd->counter.accounts_loaded = 0; gd->counter.accounts_loaded = 0;
gd->counter.accounts_total = 0; gd->counter.accounts_total = 0;
gd->counter.books_loaded = 0;
gd->counter.books_total = 0;
gd->counter.commodities_loaded = 0; gd->counter.commodities_loaded = 0;
gd->counter.commodities_total = 0; gd->counter.commodities_total = 0;
gd->counter.transactions_loaded = 0; gd->counter.transactions_loaded = 0;

View File

@ -46,6 +46,9 @@ typedef struct
int accounts_total; int accounts_total;
int accounts_loaded; int accounts_loaded;
int books_total;
int books_loaded;
int commodities_total; int commodities_total;
int commodities_loaded; int commodities_loaded;
@ -74,8 +77,8 @@ typedef struct
**/ **/
typedef struct typedef struct
{ {
GList *accts; AccountList *accts;
GList *transactions; TransList *transactions;
GNCBook *book; GNCBook *book;
} gnc_template_xaction_data; } gnc_template_xaction_data;

View File

@ -69,6 +69,7 @@ kvp_value* dom_tree_to_frame_kvp_value(xmlNodePtr node);
gboolean dom_tree_to_integer(xmlNodePtr node, gint64 *daint); gboolean dom_tree_to_integer(xmlNodePtr node, gint64 *daint);
Account* dom_tree_to_account(xmlNodePtr node, GNCBook *book); Account* dom_tree_to_account(xmlNodePtr node, GNCBook *book);
GNCBook* dom_tree_to_book(xmlNodePtr node, GNCBook *book);
Transaction* dom_tree_to_transaction(xmlNodePtr node, GNCBook *book); Transaction* dom_tree_to_transaction(xmlNodePtr node, GNCBook *book);
struct dom_tree_handler struct dom_tree_handler