GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
io-utils.c
1 /********************************************************************\
2  * io-utils.c -- implementation for gnucash file i/o utils *
3  * *
4  * Copyright (C) 2001 James LewisMoss <[email protected]> *
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 [email protected] *
22  * *
23 \********************************************************************/
24 
25 #include "config.h"
26 
27 #include <stdio.h>
28 
29 #include <glib.h>
30 
31 #include "gnc-xml.h"
32 #include "gnc-xml.h"
33 #include "io-utils.h"
34 
35 /*
36  <!-- Local variables: -->
37  <!-- mode: C -->
38  <!-- End: -->
39 */
40 
41 static const gchar *emacs_trailer =
42  "<!-- Local variables: -->\n"
43  "<!-- mode: xml -->\n"
44  "<!-- End: -->\n";
45 
46 
47 gboolean
48 write_emacs_trailer(FILE *out)
49 {
50  return fprintf(out, "%s", emacs_trailer) >= 0;
51 }
52 
53 static gboolean
54 write_one_account(FILE *out,
55  Account *account,
56  sixtp_gdv2 *gd,
57  gboolean allow_incompat)
58 {
59  xmlNodePtr accnode;
60 
61  accnode =
62  gnc_account_dom_tree_create(account, gd && gd->exporting, allow_incompat);
63 
64  xmlElemDump(out, NULL, accnode);
65  xmlFreeNode(accnode);
66 
67  if (ferror(out) || fprintf(out, "\n") < 0)
68  return FALSE;
69 
70  gd->counter.accounts_loaded++;
71  run_callback(gd, "account");
72  return TRUE;
73 }
74 
75 gboolean
76 write_account_tree(FILE *out, Account *root, sixtp_gdv2 *gd)
77 {
78  GList *descendants, *node;
79  gboolean allow_incompat = TRUE;
80  gboolean success = TRUE;
81 
82  if (allow_incompat)
83  if (!write_one_account(out, root, gd, allow_incompat))
84  return FALSE;
85 
86  descendants = gnc_account_get_descendants(root);
87  for (node = descendants; node; node = g_list_next(node))
88  {
89  if (!write_one_account(out, node->data, gd, allow_incompat))
90  {
91  success = FALSE;
92  break;
93  }
94  }
95 
96  g_list_free(descendants);
97  return success;
98 }
99 
100 gboolean
101 write_accounts(FILE *out, QofBook *book, sixtp_gdv2 *gd)
102 {
103  return write_account_tree(out, gnc_book_get_root_account(book), gd);
104 }
GList * gnc_account_get_descendants(const Account *account)
Definition: Account.c:2755
void run_callback(sixtp_gdv2 *data, const char *type)
Definition: io-gncxml-v2.c:109