mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
James LewisMoss's xml patch.
* src/engine/gnc-commodity-xml-v2.c (gnc_commodity_end_handler): mem leak. free the node in the end handler. * src/engine/gnc-commodity.c (reset_unique_name): new func. (reset_printname): new func. (gnc_commodity_new): use new funcs (gnc_commodity_set_mnemonic): use new funcs. (gnc_commodity_set_namespace): use new funcs. (gnc_commodity_set_fullname): use new funcs. * src/engine/gnc-commodity-xml-v2.c (gnc_commodity_end_handler): Don't free commodity. That's the globaldata funcs job if it wants to. (set_commodity_value): Must remember compare equals == 0. Duh. * src/engine/sixtp.c (sixtp_parse_file): Only run end handler if parsing is already ok. * src/test/test-xml-account.c (test_generation): oops should have continued here. * src/engine/gnc-commodity-xml-v2.c (valid_commodity): Complete func. * configure.in (LIBS): disable libxml/xmlversion.h checks so we can't compile for libxml2 for now. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3723 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
b928852c24
commit
b91b75648f
26
ChangeLog
26
ChangeLog
@ -1,5 +1,31 @@
|
||||
2001-02-28 James LewisMoss <jimdres@mindspring.com>
|
||||
|
||||
* src/engine/gnc-commodity-xml-v2.c (gnc_commodity_end_handler):
|
||||
mem leak. free the node in the end handler.
|
||||
|
||||
* src/engine/gnc-commodity.c (reset_unique_name): new func.
|
||||
(reset_printname): new func.
|
||||
(gnc_commodity_new): use new funcs
|
||||
(gnc_commodity_set_mnemonic): use new funcs.
|
||||
(gnc_commodity_set_namespace): use new funcs.
|
||||
(gnc_commodity_set_fullname): use new funcs.
|
||||
|
||||
* src/engine/gnc-commodity-xml-v2.c (gnc_commodity_end_handler):
|
||||
Don't free commodity. That's the globaldata funcs job if it wants
|
||||
to.
|
||||
(set_commodity_value): Must remember compare equals == 0. Duh.
|
||||
|
||||
* src/engine/sixtp.c (sixtp_parse_file): Only run end handler if
|
||||
parsing is already ok.
|
||||
|
||||
* src/test/test-xml-account.c (test_generation): oops should have
|
||||
continued here.
|
||||
|
||||
* src/engine/gnc-commodity-xml-v2.c (valid_commodity): Complete func.
|
||||
|
||||
* configure.in (LIBS): disable libxml/xmlversion.h checks so we can't
|
||||
compile for libxml2 for now.
|
||||
|
||||
* src/test/test-xml-account.c (node_and_account_equal): fix mem
|
||||
leak.
|
||||
(test_add_account): new func.
|
||||
|
@ -76,10 +76,10 @@ GNOME_CHECK_GUILE
|
||||
GNOME_PRINT_CHECK
|
||||
GNOME_XML_CHECK
|
||||
|
||||
AC_CHECK_HEADER(libxml/xmlversion.h, [
|
||||
HAVE_XML_VERSION_HEADER=1
|
||||
AC_DEFINE(HAVE_XML_VERSION_HEADER)
|
||||
])
|
||||
#AC_CHECK_HEADER(libxml/xmlversion.h, [
|
||||
# HAVE_XML_VERSION_HEADER=1
|
||||
# AC_DEFINE(HAVE_XML_VERSION_HEADER)
|
||||
#])
|
||||
|
||||
dnl Set of available languages.
|
||||
ALL_LINGUAS="de en_GB es fr it ja ru sv"
|
||||
|
@ -88,7 +88,7 @@ string_to_integer(const char *content, gint64 *to)
|
||||
static void
|
||||
set_commodity_value(xmlNodePtr node, gnc_commodity* com)
|
||||
{
|
||||
if(safe_strcmp(node->name, "cmdty:fraction"))
|
||||
if(safe_strcmp(node->name, "cmdty:fraction") == 0)
|
||||
{
|
||||
gint64 val;
|
||||
if(string_to_integer(node->xmlChildrenNode->content, &val))
|
||||
@ -102,7 +102,7 @@ set_commodity_value(xmlNodePtr node, gnc_commodity* com)
|
||||
|
||||
for(mark = com_handlers; mark->tag; mark++)
|
||||
{
|
||||
if(safe_strcmp(mark->tag, node->name))
|
||||
if(safe_strcmp(mark->tag, node->name) == 0)
|
||||
{
|
||||
gchar* val = dom_tree_to_text(node);
|
||||
(mark->func)(com, val);
|
||||
@ -116,6 +116,21 @@ set_commodity_value(xmlNodePtr node, gnc_commodity* com)
|
||||
static gboolean
|
||||
valid_commodity(gnc_commodity *com)
|
||||
{
|
||||
if(gnc_commodity_get_namespace(com) == NULL)
|
||||
{
|
||||
g_warning("Invalid commodity: no namespace");
|
||||
return FALSE;
|
||||
}
|
||||
if(gnc_commodity_get_mnemonic(com) == NULL)
|
||||
{
|
||||
g_warning("Invalid commodity: no mnemonic");
|
||||
return FALSE;
|
||||
}
|
||||
if(gnc_commodity_get_fraction(com) == 0)
|
||||
{
|
||||
g_warning("Invalid commodity: 0 fraction");
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -134,6 +149,15 @@ gnc_commodity_end_handler(gpointer data_for_children,
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* OK. For some messed up reason this is getting called again with a
|
||||
NULL tag. So we ignore those cases */
|
||||
if(!tag)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
g_return_val_if_fail(tree, FALSE);
|
||||
|
||||
com = gnc_commodity_new(NULL, NULL, NULL, NULL, 0);
|
||||
|
||||
@ -144,13 +168,18 @@ gnc_commodity_end_handler(gpointer data_for_children,
|
||||
|
||||
if(!valid_commodity(com))
|
||||
{
|
||||
g_warning("Invalid commodity parsed");
|
||||
xmlElemDump(stdout, NULL, tree);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
gnc_commodity_destroy(com);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
globaldata->addCommodityFunc(globaldata, com);
|
||||
|
||||
gnc_commodity_destroy(com);
|
||||
xmlFreeNode(tree);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -61,12 +61,31 @@ typedef struct _gnc_commodity_namespace gnc_commodity_namespace;
|
||||
* gnc_commodity_new
|
||||
********************************************************************/
|
||||
|
||||
static void
|
||||
reset_printname(gnc_commodity *com)
|
||||
{
|
||||
if(com->printname) { g_free(com->printname); }
|
||||
com->printname = g_strdup_printf("%s:%s (%s)",
|
||||
com->namespace,
|
||||
com->mnemonic,
|
||||
com->fullname);
|
||||
}
|
||||
|
||||
static void
|
||||
reset_unique_name(gnc_commodity *com)
|
||||
{
|
||||
if(com->unique_name) { g_free(com->unique_name); }
|
||||
com->unique_name = g_strdup_printf("%s::%s",
|
||||
com->namespace,
|
||||
com->mnemonic);
|
||||
}
|
||||
|
||||
gnc_commodity *
|
||||
gnc_commodity_new(const char * fullname,
|
||||
const char * namespace, const char * mnemonic,
|
||||
const char * exchange_code,
|
||||
int fraction) {
|
||||
|
||||
int fraction)
|
||||
{
|
||||
gnc_commodity * retval = g_new0(gnc_commodity, 1);
|
||||
|
||||
retval->fullname = g_strdup(fullname);
|
||||
@ -75,14 +94,8 @@ gnc_commodity_new(const char * fullname,
|
||||
retval->exchange_code = g_strdup(exchange_code);
|
||||
retval->fraction = fraction;
|
||||
|
||||
retval->printname = g_strdup_printf("%s:%s (%s)",
|
||||
retval->namespace,
|
||||
retval->mnemonic,
|
||||
retval->fullname);
|
||||
|
||||
retval->unique_name = g_strdup_printf("%s::%s",
|
||||
retval->namespace,
|
||||
retval->mnemonic);
|
||||
reset_printname(retval);
|
||||
reset_unique_name(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
@ -191,13 +204,8 @@ gnc_commodity_set_mnemonic(gnc_commodity * cm, const char * mnemonic) {
|
||||
g_free(cm->mnemonic);
|
||||
cm->mnemonic = g_strdup(mnemonic);
|
||||
|
||||
g_free(cm->printname);
|
||||
cm->printname = g_strdup_printf("%s:%s (%s)",
|
||||
cm->namespace, cm->mnemonic, cm->fullname);
|
||||
|
||||
g_free(cm->unique_name);
|
||||
cm->unique_name = g_strdup_printf("%s::%s",
|
||||
cm->namespace, cm->mnemonic);
|
||||
reset_printname(cm);
|
||||
reset_unique_name(cm);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@ -211,12 +219,8 @@ gnc_commodity_set_namespace(gnc_commodity * cm, const char * namespace) {
|
||||
g_free(cm->namespace);
|
||||
cm->namespace = g_strdup(namespace);
|
||||
|
||||
g_free(cm->printname);
|
||||
cm->printname = g_strdup_printf("%s:%s (%s)",
|
||||
cm->namespace, cm->mnemonic, cm->fullname);
|
||||
g_free(cm->unique_name);
|
||||
cm->unique_name = g_strdup_printf("%s::%s",
|
||||
cm->namespace, cm->mnemonic);
|
||||
reset_printname(cm);
|
||||
reset_unique_name(cm);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@ -230,9 +234,7 @@ gnc_commodity_set_fullname(gnc_commodity * cm, const char * fullname) {
|
||||
g_free(cm->fullname);
|
||||
cm->fullname = g_strdup(fullname);
|
||||
|
||||
g_free(cm->printname);
|
||||
cm->printname = g_strdup_printf("%s:%s (%s)",
|
||||
cm->namespace, cm->mnemonic, cm->fullname);
|
||||
reset_printname(cm);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
|
@ -605,10 +605,9 @@ sixtp_parse_file(sixtp *sixtp,
|
||||
|
||||
xmlSAXUserParseFile(&ctxt->handler, &ctxt->data, filename);
|
||||
|
||||
sixtp_context_run_end_handler(ctxt);
|
||||
|
||||
if(ctxt->data.parsing_ok)
|
||||
{
|
||||
sixtp_context_run_end_handler(ctxt);
|
||||
if(parse_result)
|
||||
*parse_result = ctxt->top_frame->frame_data;
|
||||
sixtp_context_destroy(ctxt);
|
||||
|
Loading…
Reference in New Issue
Block a user