gnucash/src/backend/file/sixtp-to-dom-parser.c

134 lines
4.3 KiB
C
Raw Normal View History

/********************************************************************
* sixtp-to-dom-parser.c *
* Copyright 2001 Gnumatic, Inc. *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
* *
********************************************************************/
#include "config.h"
#include <glib.h>
#include <ctype.h>
#include "sixtp-parsers.h"
#include "sixtp-utils.h"
#include "sixtp.h"
static xmlNsPtr global_namespace = NULL;
/* Don't pass anything in the data_for_children value to this
function. It'll cause a segfault */
static gboolean dom_start_handler(
GSList* sibling_data, gpointer parent_data, gpointer global_data,
gpointer *data_for_children, gpointer *result, const gchar *tag,
gchar **attrs)
{
xmlNodePtr thing;
gchar** atptr = attrs;
if(parent_data == NULL)
{
thing = xmlNewNode(global_namespace, BAD_CAST tag);
/* only publish the result if we're the parent */
*result = thing;
}
else
{
thing = xmlNewChild((xmlNodePtr) parent_data,
global_namespace,
BAD_CAST tag,
NULL);
*result = NULL;
}
*data_for_children = thing;
if(attrs != NULL)
{
while(*atptr != 0)
{
xmlSetProp(thing, BAD_CAST atptr[0], BAD_CAST atptr[1]);
atptr += 2;
}
}
return TRUE;
}
static void
dom_fail_handler(gpointer data_for_children,
GSList* data_from_children,
GSList* sibling_data,
gpointer parent_data,
gpointer global_data,
gpointer *result,
const gchar *tag)
{
if(*result) xmlFreeNode(*result);
}
static gboolean dom_chars_handler(
GSList *sibling_data, gpointer parent_data, gpointer global_data,
gpointer *result, const char *text, int length)
{
2001-10-11 Dave Peticolas <dave@krondo.com> * src/register/register-core/table-allgui.c (gnc_table_traverse_update): remove assert * src/import-export/binary-import/druid-commodity.c: use g_assert * src/guile/gnucash.c.in (gnc_main): use g_assert * src/gnome-utils/gnc-account-tree.c: remove asserts * src/gnome/dialog-fincalc.c (normalize_period): remove asserts * src/gnome/dialog-find-transactions.c: remove asserts * src/gnome/dialog-scheduledxaction.c: remove asserts * src/gnome/reconcile-list.c: remove asserts * src/gnome/window-register.c: remove asserts * src/engine/Account.c: remove asserts * src/engine/Group.c: remove asserts * src/engine/Query.c:remove asserts * src/engine/TransLog.c: remove asserts * src/engine/Transaction.c: remove asserts * src/engine/gnc-engine-util.h: don't include assert.h * src/engine/gnc-engine.c: remove asserts * src/engine/gnc-numeric.c: remove asserts * src/engine/gnc-pricedb.c (gnc_price_unref): remove asserts * src/engine/messages.c: remove asserts * src/backend/file/test/test-xml-account.c: fix text handling * src/backend/file/test/test-xml-commodity.c: fix text handling * src/backend/file/test/test-xml-transaction.c: fix text handling * src/backend/file/gnc-freqspec-xml-v2.c: fix text handling * src/backend/file/gnc-pricedb-xml-v2.c: fix text handling * src/backend/file/gnc-schedxaction-xml-v2.c: fix text handling * src/backend/file/gnc-transaction-xml-v2.c: fix text handling * src/backend/file/io-gncxml-v1.c: fix text handling * src/backend/file/sixtp-dom-parsers.c: fix text handling * src/backend/file/sixtp-to-dom-parser.c (dom_chars_handler): don't ignore whitespace. This fixes text handling for strings like "< <" * src/app-utils/gnc-ui-util.c: remove asserts * src/app-utils/option-util.c: remove asserts git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5576 57a11ea4-9604-0410-9ed3-97b8803252fd
2001-10-11 06:35:50 -05:00
if(length > 0)
{
xmlNodeAddContentLen((xmlNodePtr)parent_data, BAD_CAST text, length);
}
return TRUE;
}
sixtp *
sixtp_dom_parser_new(sixtp_end_handler ender,
sixtp_result_handler cleanup_result_by_default_func,
sixtp_result_handler cleanup_result_on_fail_func)
{
sixtp *top_level;
g_return_val_if_fail(ender, NULL);
if(!(top_level =
sixtp_set_any(sixtp_new(), FALSE,
SIXTP_START_HANDLER_ID, dom_start_handler,
SIXTP_CHARACTERS_HANDLER_ID, dom_chars_handler,
SIXTP_END_HANDLER_ID, ender,
SIXTP_FAIL_HANDLER_ID, dom_fail_handler,
SIXTP_NO_MORE_HANDLERS)))
{
return NULL;
}
if(cleanup_result_by_default_func)
{
sixtp_set_cleanup_result(top_level, cleanup_result_by_default_func);
}
if(cleanup_result_by_default_func)
{
sixtp_set_result_fail(top_level, cleanup_result_on_fail_func);
}
if(!sixtp_add_sub_parser(top_level, SIXTP_MAGIC_CATCHER, top_level))
{
sixtp_destroy(top_level);
return NULL;
}
return top_level;
}