Line data Source code
1 : /********************************************************************\
2 : * io-utils.c -- implementation for gnucash file i/o utils *
3 : * *
4 : * Copyright (C) 2001 James LewisMoss <dres@debian.org> *
5 : * *
6 : * This program is free software; you can redistribute it and/or *
7 : * modify it under the terms of the GNU General Public License as *
8 : * published by the Free Software Foundation; either version 2 of *
9 : * the License, or (at your option) any later version. *
10 : * *
11 : * This program is distributed in the hope that it will be useful, *
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 : * GNU General Public License for more details. *
15 : * *
16 : * You should have received a copy of the GNU General Public License*
17 : * along with this program; if not, contact: *
18 : * *
19 : * Free Software Foundation Voice: +1-617-542-5942 *
20 : * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21 : * Boston, MA 02110-1301, USA gnu@gnu.org *
22 : * *
23 : \********************************************************************/
24 : #include <glib.h>
25 :
26 : #include <config.h>
27 :
28 : #include <stdio.h>
29 :
30 : #include "gnc-xml.h"
31 : #include "io-utils.h"
32 : #include "sixtp.h"
33 :
34 : static gboolean
35 232 : write_one_account (FILE* out,
36 : Account* account,
37 : sixtp_gdv2* gd,
38 : gboolean allow_incompat)
39 : {
40 : xmlNodePtr accnode;
41 :
42 : accnode =
43 232 : gnc_account_dom_tree_create (account, gd && gd->exporting, allow_incompat);
44 :
45 232 : xmlElemDump (out, NULL, accnode);
46 232 : xmlFreeNode (accnode);
47 :
48 232 : g_return_val_if_fail(gd, FALSE);
49 :
50 232 : if (ferror (out) || fprintf (out, "\n") < 0)
51 0 : return FALSE;
52 :
53 232 : gd->counter.accounts_loaded++;
54 232 : sixtp_run_callback (gd, "account");
55 232 : return TRUE;
56 : }
57 :
58 : gboolean
59 6 : write_account_tree (FILE* out, Account* root, sixtp_gdv2* gd)
60 : {
61 : GList* descendants, *node;
62 6 : gboolean allow_incompat = TRUE;
63 6 : gboolean success = TRUE;
64 :
65 6 : if (allow_incompat)
66 6 : if (!write_one_account (out, root, gd, allow_incompat))
67 0 : return FALSE;
68 :
69 6 : descendants = gnc_account_get_descendants (root);
70 458 : for (node = descendants; node; node = g_list_next (node))
71 : {
72 226 : if (!write_one_account (out, static_cast<Account*> (node->data),
73 : gd, allow_incompat))
74 : {
75 0 : success = FALSE;
76 0 : break;
77 : }
78 : }
79 :
80 6 : g_list_free (descendants);
81 6 : return success;
82 : }
83 :
84 : gboolean
85 4 : write_accounts (FILE* out, QofBook* book, sixtp_gdv2* gd)
86 : {
87 4 : return write_account_tree (out, gnc_book_get_root_account (book), gd);
88 : }
|