mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
James LewisMoss's xml patch.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3643 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
520d406352
commit
85a79ab409
4
debian/rules
vendored
4
debian/rules
vendored
@ -19,7 +19,7 @@ configure: configure.in
|
|||||||
Makefile: Makefile.in configure
|
Makefile: Makefile.in configure
|
||||||
dh_testdir
|
dh_testdir
|
||||||
$(checkdir)
|
$(checkdir)
|
||||||
./configure --prefix=/usr \
|
./autogen.sh --prefix=/usr \
|
||||||
--sysconfdir=/etc \
|
--sysconfdir=/etc \
|
||||||
--infodir=/usr/share/info \
|
--infodir=/usr/share/info \
|
||||||
--mandir=/usr/share/man
|
--mandir=/usr/share/man
|
||||||
@ -29,7 +29,7 @@ build-stamp: Makefile
|
|||||||
dh_testdir
|
dh_testdir
|
||||||
$(checkdir)
|
$(checkdir)
|
||||||
make
|
make
|
||||||
touch build-stamp
|
# touch build-stamp
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
dh_testdir
|
dh_testdir
|
||||||
|
@ -20,6 +20,7 @@ libgncengine_la_SOURCES = \
|
|||||||
TransLog.c \
|
TransLog.c \
|
||||||
date.c \
|
date.c \
|
||||||
GNCId.c \
|
GNCId.c \
|
||||||
|
gnc-account-xml-v2.c \
|
||||||
guid.c \
|
guid.c \
|
||||||
io-gncbin-r.c \
|
io-gncbin-r.c \
|
||||||
io-gncxml-r.c \
|
io-gncxml-r.c \
|
||||||
@ -33,6 +34,8 @@ libgncengine_la_SOURCES = \
|
|||||||
gnc-engine-util.c \
|
gnc-engine-util.c \
|
||||||
gnc-event.c \
|
gnc-event.c \
|
||||||
gnc-numeric.c \
|
gnc-numeric.c \
|
||||||
|
sixtp-dom-generators.c \
|
||||||
|
sixtp-dom-parsers.c \
|
||||||
sixtp-kvp-parser.c \
|
sixtp-kvp-parser.c \
|
||||||
sixtp-stack.c \
|
sixtp-stack.c \
|
||||||
sixtp-utils.c \
|
sixtp-utils.c \
|
||||||
@ -80,6 +83,8 @@ noinst_HEADERS = \
|
|||||||
gnc-event-p.h \
|
gnc-event-p.h \
|
||||||
gnc-numeric.h \
|
gnc-numeric.h \
|
||||||
gnc-xml-helper.h \
|
gnc-xml-helper.h \
|
||||||
|
sixtp-dom-generators.h \
|
||||||
|
sixtp-dom-parsers.h \
|
||||||
sixtp-parsers.h \
|
sixtp-parsers.h \
|
||||||
sixtp-writers.h \
|
sixtp-writers.h \
|
||||||
sixtp-stack.h \
|
sixtp-stack.h \
|
||||||
|
220
src/engine/gnc-account-xml-v2.c
Normal file
220
src/engine/gnc-account-xml-v2.c
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
#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-dom-parsers.h"
|
||||||
|
#include "AccountP.h"
|
||||||
|
#include "Account.h"
|
||||||
|
#include "Group.h"
|
||||||
|
|
||||||
|
xmlNodePtr
|
||||||
|
gnc_account_dom_tree_create(Account *act)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
static gboolean
|
||||||
|
account_name_handler (xmlNodePtr node, Account* act)
|
||||||
|
{
|
||||||
|
if(node->content != NULL)
|
||||||
|
{
|
||||||
|
xaccAccountSetName(act, node->xmlChildrenNode->content);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
account_id_handler (xmlNodePtr node, Account* act)
|
||||||
|
{
|
||||||
|
xaccAccountSetGUID(act, dom_tree_to_guid(node));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
account_type_handler (xmlNodePtr node, Account* act)
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
|
||||||
|
xaccAccountStringToType(node->childs->content, &type);
|
||||||
|
xaccAccountSetType(act, type);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
account_currency_handler (xmlNodePtr node, Account* act)
|
||||||
|
{
|
||||||
|
xaccAccountSetCurrency(act, dom_tree_to_gnc_commodity(node));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
account_security_handler (xmlNodePtr node, Account* act)
|
||||||
|
{
|
||||||
|
xaccAccountSetCurrency(act, dom_tree_to_gnc_commodity(node));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
account_slots_handler (xmlNodePtr node, Account* act)
|
||||||
|
{
|
||||||
|
return dom_tree_handle_kvp(act->kvp_data, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
account_parent_handler (xmlNodePtr node, Account* act)
|
||||||
|
{
|
||||||
|
Account *parent;
|
||||||
|
GUID *gid = dom_tree_to_guid(node);
|
||||||
|
|
||||||
|
parent = xaccAccountLookup(gid);
|
||||||
|
|
||||||
|
xaccAccountInsertSubAccount(parent, act);
|
||||||
|
|
||||||
|
xaccGUIDFree(gid);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dom_handlers
|
||||||
|
{
|
||||||
|
char *tag;
|
||||||
|
|
||||||
|
gboolean (*handler) (xmlNodePtr, Account*);
|
||||||
|
|
||||||
|
int required;
|
||||||
|
int gotten;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct dom_handlers account_handlers_v2[] = {
|
||||||
|
{ "act:name", account_name_handler, 1, 0 },
|
||||||
|
{ "act:id", account_id_handler, 1, 0 },
|
||||||
|
{ "act:type", account_type_handler, 1, 0 },
|
||||||
|
{ "act:currency", account_currency_handler, 1, 0 },
|
||||||
|
{ "act:security", account_security_handler, 0, 0 },
|
||||||
|
{ "act:slots", account_slots_handler, 0, 0 },
|
||||||
|
{ "act:parent", account_parent_handler, 0, 0 },
|
||||||
|
{ NULL, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_handlers(struct dom_handlers *handler_ptr)
|
||||||
|
{
|
||||||
|
while(handler_ptr->tag != NULL)
|
||||||
|
{
|
||||||
|
handler_ptr->gotten = 0;
|
||||||
|
|
||||||
|
handler_ptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
all_required_gotten_p(struct dom_handlers *handler_ptr)
|
||||||
|
{
|
||||||
|
while(handler_ptr->tag != NULL)
|
||||||
|
{
|
||||||
|
if(handler_ptr->required && ! handler_ptr->gotten)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
handler_ptr++;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gnc_xml_set_account_data(const gchar* tag, xmlNodePtr node, Account *acc,
|
||||||
|
struct dom_handlers *handler_ptr)
|
||||||
|
{
|
||||||
|
while(handler_ptr->tag)
|
||||||
|
{
|
||||||
|
if(strcmp(tag, handler_ptr->tag) == 0)
|
||||||
|
{
|
||||||
|
(handler_ptr->handler)(node, acc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
handler_ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!handler_ptr->tag)
|
||||||
|
{
|
||||||
|
g_warning("Unhandled account tag: %s\n", tag);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gnc_account_end_handler(gpointer data_for_children,
|
||||||
|
GSList* data_from_children, GSList* sibling_data,
|
||||||
|
gpointer parent_data, gpointer global_data,
|
||||||
|
gpointer *result, const gchar *tag)
|
||||||
|
{
|
||||||
|
int successful;
|
||||||
|
Account *acc;
|
||||||
|
xmlNodePtr achild;
|
||||||
|
xmlNodePtr tree = (xmlNodePtr)data_for_children;
|
||||||
|
|
||||||
|
successful = TRUE;
|
||||||
|
|
||||||
|
acc = xaccMallocAccount();
|
||||||
|
g_return_val_if_fail(acc, FALSE);
|
||||||
|
xaccAccountBeginEdit(acc);
|
||||||
|
|
||||||
|
achild = tree->xmlChildrenNode;
|
||||||
|
|
||||||
|
set_handlers(account_handlers_v2);
|
||||||
|
|
||||||
|
while(!achild)
|
||||||
|
{
|
||||||
|
if(!gnc_xml_set_account_data(achild->name, achild, acc,
|
||||||
|
account_handlers_v2))
|
||||||
|
{
|
||||||
|
successful = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
achild = achild->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
xaccAccountCommitEdit(acc);
|
||||||
|
|
||||||
|
if(!all_required_gotten_p(account_handlers_v2))
|
||||||
|
{
|
||||||
|
successful = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!successful)
|
||||||
|
{
|
||||||
|
xaccFreeAccount(acc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!xaccAccountGetParent(acc))
|
||||||
|
{
|
||||||
|
/* FIXME: something like this */
|
||||||
|
/* xaccGroupInsertAccount(global_data->accountgroup, acc); */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlFreeNode(data_for_children);
|
||||||
|
|
||||||
|
return successful;
|
||||||
|
}
|
||||||
|
|
||||||
|
sixtp*
|
||||||
|
gnc_account_sixtp_parser_create()
|
||||||
|
{
|
||||||
|
return sixtp_dom_parser_new(gnc_account_end_handler);
|
||||||
|
}
|
31
src/engine/sixtp-dom-generators.c
Normal file
31
src/engine/sixtp-dom-generators.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "gnc-xml-helper.h"
|
||||||
|
|
||||||
|
#include "sixtp-dom-generators.h"
|
||||||
|
#include "GNCId.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmlNodePtr
|
||||||
|
guid_to_dom_tree(GUID* gid)
|
||||||
|
{
|
||||||
|
char *guid_str;
|
||||||
|
xmlNodePtr ret;
|
||||||
|
|
||||||
|
ret = xmlNewNode(NULL, "test-guid");
|
||||||
|
|
||||||
|
xmlSetProp(ret, "type", "guid");
|
||||||
|
|
||||||
|
guid_str = guid_to_string(gid);
|
||||||
|
if (!guid_str)
|
||||||
|
{
|
||||||
|
printf("FAILURE: guid_to_string failed\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlNodeAddContent(ret, guid_str);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
16
src/engine/sixtp-dom-generators.h
Normal file
16
src/engine/sixtp-dom-generators.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef _SIXTP_DOM_GENERATORS_H_
|
||||||
|
#define _SIXTP_DOM_GENERATORS_H_
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "gnc-xml-helper.h"
|
||||||
|
|
||||||
|
#include "sixtp-dom-generators.h"
|
||||||
|
#include "GNCId.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmlNodePtr guid_to_dom_tree(GUID* gid);
|
||||||
|
|
||||||
|
#endif /* _SIXTP_DOM_GENERATORS_H_ */
|
61
src/engine/sixtp-dom-parsers.c
Normal file
61
src/engine/sixtp-dom-parsers.c
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "gnc-xml-helper.h"
|
||||||
|
|
||||||
|
#include "sixtp-dom-parsers.h"
|
||||||
|
#include "GNCId.h"
|
||||||
|
|
||||||
|
GUID*
|
||||||
|
dom_tree_to_guid(xmlNodePtr node)
|
||||||
|
{
|
||||||
|
if(!node->properties)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcmp(node->properties->name, "type") != 0)
|
||||||
|
{
|
||||||
|
g_warning("Unknown attribute for id tag: %s\n",
|
||||||
|
node->properties->name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
char *type = node->properties->val->content;
|
||||||
|
if(strcmp("guid", type) == 0)
|
||||||
|
{
|
||||||
|
GUID *gid = g_new(GUID, 1);
|
||||||
|
string_to_guid(node->xmlChildrenNode->content, gid);
|
||||||
|
return gid;
|
||||||
|
}
|
||||||
|
else if(strcmp("new", type) == 0)
|
||||||
|
{
|
||||||
|
/* FIXME: handle this case */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_warning("Unknown type %s for attribute type for tag %s",
|
||||||
|
type, node->properties->name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gnc_commodity*
|
||||||
|
dom_tree_to_gnc_commodity(xmlNodePtr node)
|
||||||
|
{
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
dom_tree_handle_kvp(kvp_frame* frame, xmlNodePtr node)
|
||||||
|
{
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
21
src/engine/sixtp-dom-parsers.h
Normal file
21
src/engine/sixtp-dom-parsers.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef _SIXTP_DOM_PARSERS_H_
|
||||||
|
#define _SIXTP_DOM_PARSERS_H_
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "gnc-xml-helper.h"
|
||||||
|
|
||||||
|
#include "gnc-commodity.h"
|
||||||
|
#include "kvp_frame.h"
|
||||||
|
|
||||||
|
#include "GNCId.h"
|
||||||
|
|
||||||
|
GUID* dom_tree_to_guid(xmlNodePtr node);
|
||||||
|
|
||||||
|
gnc_commodity* dom_tree_to_gnc_commodity(xmlNodePtr node);
|
||||||
|
|
||||||
|
gboolean dom_tree_handle_kvp(kvp_frame* frame, xmlNodePtr node);
|
||||||
|
|
||||||
|
#endif /* _SIXTP_DOM_PARSERS_H_ */
|
@ -59,8 +59,8 @@ static gboolean dom_chars_handler(
|
|||||||
{
|
{
|
||||||
if(length > 0 && !is_whitespace(text, length))
|
if(length > 0 && !is_whitespace(text, length))
|
||||||
{
|
{
|
||||||
gchar *stuff = g_strndup(text, length);
|
/* gchar *stuff = g_strndup(text, length); */
|
||||||
xmlNodeSetContent((xmlNodePtr)parent_data, stuff);
|
xmlNodeSetContentLen((xmlNodePtr)parent_data, text, length);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ sixtp_set_any(sixtp *tochange, int cleanup, ...)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
g_warning("Bogus sixtp type %d\n", type);
|
g_error("Bogus sixtp type %d\n", type);
|
||||||
if(cleanup)
|
if(cleanup)
|
||||||
{
|
{
|
||||||
sixtp_destroy(tochange);
|
sixtp_destroy(tochange);
|
||||||
@ -643,13 +643,15 @@ sixtp_parse_buffer(sixtp *sixtp,
|
|||||||
|
|
||||||
if(ctxt->data.parsing_ok)
|
if(ctxt->data.parsing_ok)
|
||||||
{
|
{
|
||||||
*parse_result = ctxt->top_frame->frame_data;
|
if(parse_result)
|
||||||
|
*parse_result = ctxt->top_frame->frame_data;
|
||||||
sixtp_context_destroy(ctxt);
|
sixtp_context_destroy(ctxt);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*parse_result = NULL;
|
if(parse_result)
|
||||||
|
*parse_result = NULL;
|
||||||
sixtp_handle_catastrophe(&ctxt->data);
|
sixtp_handle_catastrophe(&ctxt->data);
|
||||||
sixtp_context_destroy(ctxt);
|
sixtp_context_destroy(ctxt);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
(require 'hash-table)
|
(require 'hash-table)
|
||||||
|
|
||||||
|
(use-modules (ice-9 syncase))
|
||||||
|
|
||||||
(define (gnc:error->string tag args)
|
(define (gnc:error->string tag args)
|
||||||
(define (write-error port)
|
(define (write-error port)
|
||||||
(if (and (list? args) (not (null? args)))
|
(if (and (list? args) (not (null? args)))
|
||||||
@ -41,7 +43,9 @@
|
|||||||
(define gnc:gettext gnc:gettext-helper)
|
(define gnc:gettext gnc:gettext-helper)
|
||||||
(define gnc:_ gnc:gettext)
|
(define gnc:_ gnc:gettext)
|
||||||
(define _ gnc:gettext)
|
(define _ gnc:gettext)
|
||||||
(define (N_ x) x)
|
(define-syntax N_
|
||||||
|
(syntax-rules ()
|
||||||
|
((_ x) x)))
|
||||||
|
|
||||||
|
|
||||||
;; This database can be used to store and retrieve translatable
|
;; This database can be used to store and retrieve translatable
|
||||||
|
Loading…
Reference in New Issue
Block a user