Skip to content

Commit

Permalink
Part Bug fix for 729476, this changes the line endings to \r\n to mak…
Browse files Browse the repository at this point in the history
…e it more compatible with CSV format.
  • Loading branch information
Bob-IT authored and gjanssens committed Sep 26, 2014
1 parent 2b6a6d8 commit ba1f8cb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
18 changes: 17 additions & 1 deletion src/import-export/csv-exp/csv-transactions-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ void account_splits (CsvExportInfo *info, Account *acc, FILE *fh )
g_free (part1);

/* From Number Only */
#ifdef G_OS_WIN32
part1 = g_strconcat (part2, "", mid_sep, "", mid_sep, "", end_sep, "\n", NULL);
#else
part1 = g_strconcat (part2, "", mid_sep, "", mid_sep, "", end_sep, "\r\n", NULL);
#endif
g_free (part2);

/* Write to file */
Expand Down Expand Up @@ -346,9 +350,17 @@ void account_splits (CsvExportInfo *info, Account *acc, FILE *fh )
split_amount = xaccPrintAmount (xaccSplitGetSharePrice (t_split), gnc_split_amount_print_info (t_split, FALSE));
str_temp = csv_txn_test_field_string (info, split_amount);
if (xaccSplitGetAccount (t_split) == acc)
#ifdef G_OS_WIN32
part2 = g_strconcat (part1, str_temp, mid_sep, end_sep, "\n", NULL);
else
#else
part2 = g_strconcat (part1, str_temp, mid_sep, end_sep, "\r\n", NULL);
#endif
else
#ifdef G_OS_WIN32
part2 = g_strconcat (part1, mid_sep, str_temp, end_sep, "\n", NULL);
#else
part2 = g_strconcat (part1, mid_sep, str_temp, end_sep, "\r\n", NULL);
#endif
g_free (str_temp);
g_free (part1);

Expand Down Expand Up @@ -415,7 +427,11 @@ void csv_transactions_export (CsvExportInfo *info)
_("To With Sym"), mid_sep, _("From With Sym"), mid_sep,
_("To Num."), mid_sep, _("From Num."), mid_sep,
_("To Rate/Price"), mid_sep, _("From Rate/Price"),
#ifdef G_OS_WIN32
end_sep, "\n", NULL);
#else
end_sep, "\r\n", NULL);
#endif
DEBUG("Header String: %s", header);

/* Write header line */
Expand Down
23 changes: 17 additions & 6 deletions src/import-export/csv-exp/csv-tree-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,19 @@ void csv_tree_export (CsvExportInfo *info)
}

/* Header string, 'eol = end of line marker' */
header = g_strconcat ( end_sep, _("type"), mid_sep, _("full_name"), mid_sep,
_("name"), mid_sep, _("code"), mid_sep,
_("description"), mid_sep, _("color"), mid_sep, _("notes"), mid_sep,
_("commoditym"), mid_sep, _("commodityn"), mid_sep,
_("hidden"), mid_sep, _("tax"), mid_sep, _("place_holder"), mid_sep,
_("#eol"), end_sep, "\n", NULL);
#ifdef G_OS_WIN32
header = g_strconcat (end_sep, _("type"), mid_sep, _("full_name"), mid_sep, _("name"), mid_sep,
_("code"), mid_sep, _("description"), mid_sep, _("color"), mid_sep,
_("notes"), mid_sep, _("commoditym"), mid_sep, _("commodityn"), mid_sep,
_("hidden"), mid_sep, _("tax"), mid_sep, _("place_holder"), mid_sep, _("#eol"),
end_sep, "\n", NULL);
#else
header = g_strconcat (end_sep, _("type"), mid_sep, _("full_name"), mid_sep, _("name"), mid_sep,
_("code"), mid_sep, _("description"), mid_sep, _("color"), mid_sep,
_("notes"), mid_sep, _("commoditym"), mid_sep, _("commodityn"), mid_sep,
_("hidden"), mid_sep, _("tax"), mid_sep, _("place_holder"), mid_sep, _("#eol"),
end_sep, "\r\n", NULL);
#endif
DEBUG("Header String: %s", header);

/* Write header line */
Expand Down Expand Up @@ -229,7 +236,11 @@ void csv_tree_export (CsvExportInfo *info)
g_free (part2);
/* Place Holder / end of line marker */
currentSel = xaccAccountGetPlaceholder (acc) ? "T" : "F" ;
#ifdef G_OS_WIN32
part2 = g_strconcat (part1, currentSel, mid_sep, _("#eol"), end_sep, "\n", NULL);
#else
part2 = g_strconcat (part1, currentSel, mid_sep, _("#eol"), end_sep, "\r\n", NULL);
#endif
g_free (part1);

DEBUG("Account String: %s", part2);
Expand Down
10 changes: 9 additions & 1 deletion src/import-export/csv-imp/csv-account-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ csv_import_read_file (const gchar *filename, const gchar *parser_regexp,
}

/* Setup the two different line endings */
#ifdef G_OS_WIN32
end1 = g_strconcat (_("#eol"),"\"\n", NULL);
end2 = g_strconcat (_("#eol"),"\n", NULL);
#else
end1 = g_strconcat (_("#eol"),"\"\r\n", NULL);
end2 = g_strconcat (_("#eol"),"\r\n", NULL);
#endif

// start the import
#define buffer_size 1000
Expand Down Expand Up @@ -154,11 +159,14 @@ csv_import_read_file (const gchar *filename, const gchar *parser_regexp,
break; // eof
}

// now strip the '\n' from the end of the line
// now strip the '\r\n' from the end of the line
l = strlen (currentline);
if ((l > 0) && (currentline[l - 1] == '\n'))
currentline[l - 1] = 0;

if ((l > 0) && (currentline[l - 2] == '\r'))
currentline[l - 2] = 0;

// convert line from locale into utf8
line_utf8 = g_locale_to_utf8 (currentline, -1, NULL, NULL, NULL);

Expand Down

0 comments on commit ba1f8cb

Please sign in to comment.