30 #include <glib/gi18n.h>
31 #include <glib/gstdio.h>
46 # define EOLSTR "\r\n"
58 gboolean write_line_to_file (FILE *fh,
char * line)
61 DEBUG(
"Account String: %s", line);
65 written = fwrite (line, 1, len, fh);
79 gchar *csv_test_field_string (
CsvExportInfo *info,
const gchar *string_in)
81 gboolean need_quote = FALSE;
87 parts = g_strsplit (string_in,
"\"", -1);
88 string_parts = g_strjoinv (
"\"\"", parts);
93 if (g_strrstr (string_parts, info->separator_str) != NULL)
95 if (g_strrstr (string_parts,
"\n") != NULL)
97 if (g_strrstr (string_parts,
"\"") != NULL)
100 if (!info->use_quotes && need_quote)
101 string_out = g_strconcat (
"\"", string_parts,
"\"", NULL);
103 string_out = g_strdup (string_parts);
105 g_free (string_parts);
122 DEBUG(
"File name is : %s", info->file_name);
125 root = gnc_book_get_root_account (gnc_get_current_book());
127 info->failed = FALSE;
130 fh = g_fopen (info->file_name,
"w");
136 const gchar *currentSel;
143 if (info->use_quotes)
146 mid_sep = g_strconcat (
"\"", info->separator_str,
"\"", NULL);
151 mid_sep = g_strconcat (info->separator_str, NULL);
155 header = g_strconcat (end_sep, _(
"type"), mid_sep, _(
"full_name"), mid_sep, _(
"name"), mid_sep,
156 _(
"code"), mid_sep, _(
"description"), mid_sep, _(
"color"), mid_sep,
157 _(
"notes"), mid_sep, _(
"commoditym"), mid_sep, _(
"commodityn"), mid_sep,
158 _(
"hidden"), mid_sep, _(
"tax"), mid_sep, _(
"place_holder"), end_sep, EOLSTR, NULL);
159 DEBUG(
"Header String: %s", header);
162 if (!write_line_to_file (fh, header))
172 for (ptr = accts, i = 0; ptr; ptr = g_list_next (ptr), i++)
174 gchar *fullname = NULL;
175 gchar *str_temp = NULL;
180 part1 = g_strconcat (end_sep, currentSel, mid_sep, NULL);
183 str_temp = csv_test_field_string (info, fullname);
184 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
190 str_temp = csv_test_field_string (info, currentSel);
191 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
196 str_temp = csv_test_field_string (info, currentSel);
197 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
202 str_temp = csv_test_field_string (info, currentSel);
203 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
208 part2 = g_strconcat (part1, currentSel, mid_sep, NULL);
212 str_temp = csv_test_field_string (info, currentSel);
213 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
218 str_temp = csv_test_field_string (info, currentSel);
219 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
224 str_temp = csv_test_field_string (info, currentSel);
225 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
230 part2 = g_strconcat (part1, currentSel, mid_sep, NULL);
234 part1 = g_strconcat (part2, currentSel, mid_sep, NULL);
238 part2 = g_strconcat (part1, currentSel, end_sep, EOLSTR, NULL);
241 DEBUG(
"Account String: %s", part2);
244 if (!write_line_to_file (fh, part2))
GList * gnc_account_get_descendants_sorted(const Account *account)
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
utility functions for the GnuCash UI
GNCAccountType xaccAccountGetType(const Account *acc)
const char * xaccAccountGetCode(const Account *acc)
#define DEBUG(format, args...)
const char * xaccAccountTypeEnumAsString(GNCAccountType type)
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
#define ENTER(format, args...)
const char * xaccAccountGetColor(const Account *acc)
gchar * gnc_account_get_full_name(const Account *account)
void csv_tree_export(CsvExportInfo *info)
const char * xaccAccountGetDescription(const Account *acc)
gboolean xaccAccountGetTaxRelated(const Account *acc)
gboolean xaccAccountGetHidden(const Account *acc)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
gboolean xaccAccountGetPlaceholder(const Account *acc)
#define LEAVE(format, args...)
const char * xaccAccountGetName(const Account *acc)
Commodity handling public routines.
const gchar * QofLogModule
const char * xaccAccountGetNotes(const Account *acc)