mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* src/test/test-xml-account.c (delete_random_account): new func to cleanup commodities not generally freed at xaccAccountDestroy. (node_and_account_equal): complete func to compare account and the dom tree created. Looks good except for some warnings from dom_tree_to_text. * src/test/test-stuff.c (equals_node_val_vs_commodity): new func. (equals_node_val_vs_guid): New func. (equals_node_val_vs_string): new func. * src/engine/gnc-account-xml-v2.c (account_code_handler): Add func. (account_description_handler): Add func. Oops forgot a couple. (gnc_account_dom_tree_create): Move all string tags in file to const gchar*s. (account_slots_handler): Complete func. * make-gnucash-patch.in: Test to see if makepatch exists. * src/engine/sixtp-dom-parsers.c (dom_tree_to_text): same as below. Add NULL tests for arguments. Affected many functions in this file. * src/engine/gnc-pricedb-xml-v1.c (price_parse_xml_sub_node): Same as below. * src/engine/gnc-commodity-xml-v2.c (set_commodity_value): Convert dom_tree_to_text to act as rest looking at children on it's own. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3718 57a11ea4-9604-0410-9ed3-97b8803252fd
157 lines
3.4 KiB
C
157 lines
3.4 KiB
C
#include "config.h"
|
|
|
|
#include <glib.h>
|
|
#include <string.h>
|
|
|
|
#include "gnc-xml-helper.h"
|
|
|
|
#include "sixtp.h"
|
|
#include "sixtp-utils.h"
|
|
#include "sixtp-parsers.h"
|
|
#include "sixtp-utils.h"
|
|
#include "sixtp-dom-parsers.h"
|
|
#include "sixtp-dom-generators.h"
|
|
|
|
#include "gnc-xml.h"
|
|
#include "gnc-engine-util.h"
|
|
|
|
#include "sixtp-dom-parsers.h"
|
|
#include "AccountP.h"
|
|
#include "Account.h"
|
|
#include "Group.h"
|
|
|
|
const gchar *commodity_version_string = "2.0.0";
|
|
|
|
xmlNodePtr
|
|
gnc_commodity_dom_tree_create(const gnc_commodity *com)
|
|
{
|
|
xmlNodePtr ret;
|
|
|
|
ret = xmlNewNode(NULL, "gnc:commodity");
|
|
|
|
xmlSetProp(ret, "version", commodity_version_string);
|
|
|
|
xmlNewChild(ret, NULL, "cmdty:space", gnc_commodity_get_namespace(com));
|
|
xmlNewChild(ret, NULL, "cmdty:id", gnc_commodity_get_mnemonic(com));
|
|
|
|
if(gnc_commodity_get_fullname(com))
|
|
{
|
|
xmlNewChild(ret, NULL, "cmdty:name", gnc_commodity_get_fullname(com));
|
|
}
|
|
|
|
if(gnc_commodity_get_exchange_code(com))
|
|
{
|
|
xmlNewChild(ret, NULL, "cmdty:xcode",
|
|
gnc_commodity_get_exchange_code(com));
|
|
}
|
|
|
|
{
|
|
gchar *text;
|
|
text = g_strdup_printf("%d", gnc_commodity_get_fraction(com));
|
|
xmlNewChild(ret, NULL, "cmdty:fraction", text);
|
|
g_free(text);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
/***********************************************************************/
|
|
|
|
struct com_char_handler
|
|
{
|
|
gchar *tag;
|
|
void(*func)(gnc_commodity *com, const char*val);
|
|
};
|
|
|
|
struct com_char_handler com_handlers[] = {
|
|
{ "cmdty:space", gnc_commodity_set_namespace },
|
|
{ "cmdty:id", gnc_commodity_set_mnemonic },
|
|
{ "cmdty:name", gnc_commodity_set_fullname },
|
|
{ "cmdty:xcode", gnc_commodity_set_exchange_code },
|
|
{ 0, 0 }
|
|
};
|
|
|
|
static gboolean
|
|
string_to_integer(const char *content, gint64 *to)
|
|
{
|
|
if(sscanf(content, "%lld", to) == 1)
|
|
{
|
|
return TRUE;
|
|
}
|
|
else
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
static void
|
|
set_commodity_value(xmlNodePtr node, gnc_commodity* com)
|
|
{
|
|
if(safe_strcmp(node->name, "cmdty:fraction"))
|
|
{
|
|
gint64 val;
|
|
if(string_to_integer(node->xmlChildrenNode->content, &val))
|
|
{
|
|
gnc_commodity_set_fraction(com, val);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
struct com_char_handler *mark;
|
|
|
|
for(mark = com_handlers; mark->tag; mark++)
|
|
{
|
|
if(safe_strcmp(mark->tag, node->name))
|
|
{
|
|
gchar* val = dom_tree_to_text(node);
|
|
(mark->func)(com, val);
|
|
g_free(val);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static gboolean
|
|
valid_commodity(gnc_commodity *com)
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
static gboolean
|
|
gnc_commodity_end_handler(gpointer data_for_children,
|
|
GSList* data_from_children, GSList* sibling_data,
|
|
gpointer parent_data, gpointer global_data,
|
|
gpointer *result, const gchar *tag)
|
|
{
|
|
gnc_commodity *com;
|
|
xmlNodePtr achild;
|
|
xmlNodePtr tree = (xmlNodePtr)data_for_children;
|
|
|
|
if(parent_data)
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
com = gnc_commodity_new(NULL, NULL, NULL, NULL, 0);
|
|
|
|
for(achild = tree->xmlChildrenNode; achild; achild = achild->next)
|
|
{
|
|
set_commodity_value(achild, com);
|
|
}
|
|
|
|
if(!valid_commodity(com))
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
sixtp*
|
|
gnc_commodity_sixtp_parser_create(void)
|
|
{
|
|
return sixtp_dom_parser_new(gnc_commodity_end_handler, NULL, NULL);
|
|
}
|