2001-05-09 18:03:36 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* io-utils.c -- implementation for gnucash file i/o utils *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2001 James LewisMoss <dres@debian.org> *
|
|
|
|
* *
|
|
|
|
* 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 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2001-05-09 18:03:36 -05:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
2015-11-29 19:11:29 -06:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-10-26 04:14:21 -05:00
|
|
|
#include <config.h>
|
2001-09-07 16:51:13 -05:00
|
|
|
|
2001-04-13 01:54:25 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
2015-11-29 19:11:29 -06:00
|
|
|
}
|
2001-04-13 01:54:25 -05:00
|
|
|
|
2003-01-04 23:49:27 -06:00
|
|
|
#include "gnc-xml.h"
|
2001-04-13 01:54:25 -05:00
|
|
|
#include "io-utils.h"
|
2015-11-29 19:11:29 -06:00
|
|
|
#include "sixtp.h"
|
2001-05-11 17:26:44 -05:00
|
|
|
/*
|
|
|
|
<!-- Local variables: -->
|
|
|
|
<!-- mode: C -->
|
|
|
|
<!-- End: -->
|
|
|
|
*/
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
static const gchar* emacs_trailer =
|
2009-12-29 14:12:48 -06:00
|
|
|
"<!-- Local variables: -->\n"
|
|
|
|
"<!-- mode: xml -->\n"
|
|
|
|
"<!-- End: -->\n";
|
2001-04-13 01:54:25 -05:00
|
|
|
|
|
|
|
|
2010-01-31 12:37:28 -06:00
|
|
|
gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
write_emacs_trailer (FILE* out)
|
2001-04-13 01:54:25 -05:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
return fprintf (out, "%s", emacs_trailer) >= 0;
|
2001-04-13 01:54:25 -05:00
|
|
|
}
|
|
|
|
|
2010-01-31 12:37:28 -06:00
|
|
|
static gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
write_one_account (FILE* out,
|
|
|
|
Account* account,
|
|
|
|
sixtp_gdv2* gd,
|
|
|
|
gboolean allow_incompat)
|
2001-04-13 01:54:25 -05:00
|
|
|
{
|
2007-02-22 19:23:31 -06:00
|
|
|
xmlNodePtr accnode;
|
2001-04-13 01:54:25 -05:00
|
|
|
|
2007-02-22 19:23:31 -06:00
|
|
|
accnode =
|
2016-03-12 16:04:40 -06:00
|
|
|
gnc_account_dom_tree_create (account, gd && gd->exporting, allow_incompat);
|
2001-04-13 01:54:25 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlElemDump (out, NULL, accnode);
|
|
|
|
xmlFreeNode (accnode);
|
2010-01-31 12:37:28 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
if (ferror (out) || fprintf (out, "\n") < 0)
|
2010-01-31 12:37:28 -06:00
|
|
|
return FALSE;
|
|
|
|
|
2007-02-22 19:23:31 -06:00
|
|
|
gd->counter.accounts_loaded++;
|
2016-03-12 16:04:40 -06:00
|
|
|
sixtp_run_callback (gd, "account");
|
2010-01-31 12:37:28 -06:00
|
|
|
return TRUE;
|
2007-02-22 19:23:31 -06:00
|
|
|
}
|
2001-04-13 01:54:25 -05:00
|
|
|
|
2010-01-31 12:37:28 -06:00
|
|
|
gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
write_account_tree (FILE* out, Account* root, sixtp_gdv2* gd)
|
2007-02-22 19:23:31 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
GList* descendants, *node;
|
2007-05-05 12:03:42 -05:00
|
|
|
gboolean allow_incompat = TRUE;
|
2010-01-31 12:37:28 -06:00
|
|
|
gboolean success = TRUE;
|
2007-02-22 19:23:31 -06:00
|
|
|
|
|
|
|
if (allow_incompat)
|
2016-03-12 16:04:40 -06:00
|
|
|
if (!write_one_account (out, root, gd, allow_incompat))
|
2010-01-31 12:37:28 -06:00
|
|
|
return FALSE;
|
2007-02-22 19:23:31 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
descendants = gnc_account_get_descendants (root);
|
|
|
|
for (node = descendants; node; node = g_list_next (node))
|
2010-01-31 12:37:28 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
if (!write_one_account (out, static_cast<Account*> (node->data),
|
|
|
|
gd, allow_incompat))
|
2010-01-31 12:37:28 -06:00
|
|
|
{
|
|
|
|
success = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
g_list_free (descendants);
|
2010-01-31 12:37:28 -06:00
|
|
|
return success;
|
2001-04-13 01:54:25 -05:00
|
|
|
}
|
|
|
|
|
2010-01-31 12:37:28 -06:00
|
|
|
gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
write_accounts (FILE* out, QofBook* book, sixtp_gdv2* gd)
|
2001-04-13 01:54:25 -05:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
return write_account_tree (out, gnc_book_get_root_account (book), gd);
|
2001-04-13 01:54:25 -05:00
|
|
|
}
|