Refactor OS-specific ifdef to reduce code duplication

Which results in reduced risk on typos in either branch
This commit is contained in:
Geert Janssens 2014-09-25 21:17:19 +02:00
parent ea03301651
commit 0c31c62753
2 changed files with 23 additions and 34 deletions

View File

@ -42,6 +42,15 @@
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_ASSISTANT;
/* CSV spec requires CRLF line endings. Tweak the end-of-line string so this
* true for each platform */
#ifdef G_OS_WIN32
# define EOLSTR "\n"
#else
# define EOLSTR "\r\n"
#endif
/*******************************************************************/
/*******************************************************
@ -256,11 +265,7 @@ 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
part1 = g_strconcat (part2, "", mid_sep, "", mid_sep, "", end_sep, EOLSTR, NULL);
g_free (part2);
/* Write to file */
@ -350,17 +355,9 @@ 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
part2 = g_strconcat (part1, str_temp, mid_sep, end_sep, "\r\n", NULL);
#endif
part2 = g_strconcat (part1, str_temp, mid_sep, end_sep, EOLSTR, NULL);
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
part2 = g_strconcat (part1, mid_sep, str_temp, end_sep, EOLSTR, NULL);
g_free (str_temp);
g_free (part1);
@ -427,11 +424,7 @@ 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
end_sep, EOLSTR, NULL);
DEBUG("Header String: %s", header);
/* Write header line */

View File

@ -38,6 +38,14 @@
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_ASSISTANT;
/* CSV spec requires CRLF line endings. Tweak the end-of-line string so this
* true for each platform */
#ifdef G_OS_WIN32
# define EOLSTR "\n"
#else
# define EOLSTR "\r\n"
#endif
/******************************************************************/
/*******************************************************
@ -144,19 +152,11 @@ void csv_tree_export (CsvExportInfo *info)
}
/* Header string, 'eol = end of line marker' */
#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
end_sep, EOLSTR, NULL);
DEBUG("Header String: %s", header);
/* Write header line */
@ -236,11 +236,7 @@ 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
part2 = g_strconcat (part1, currentSel, mid_sep, _("#eol"), end_sep, EOLSTR, NULL);
g_free (part1);
DEBUG("Account String: %s", part2);