From b7777eac684f5f2b20208a49ece118defe82c342 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 7 Aug 2004 22:25:12 -0400 Subject: [PATCH] got entry working again --- amount.cc | 8 ++++++++ amount.h | 7 +++++++ format.h | 2 +- main.cc | 46 ++++++++++++++++++++++------------------------ 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/amount.cc b/amount.cc index 368a366d..9a88db38 100644 --- a/amount.cc +++ b/amount.cc @@ -144,6 +144,14 @@ amount_t& amount_t::operator=(const std::string& value) return *this; } +amount_t& amount_t::operator=(const char * value) +{ + std::string valstr(value); + std::istringstream str(valstr); + parse(str); + return *this; +} + // assignment operator amount_t& amount_t::operator=(const amount_t& amt) { diff --git a/amount.h b/amount.h index bfcea2c2..f2d44010 100644 --- a/amount.h +++ b/amount.h @@ -45,6 +45,12 @@ class amount_t std::istringstream str(value); str >> *this; } + amount_t(const char * value) { + _init(); + std::string valstr(value); + std::istringstream str(valstr); + str >> *this; + } amount_t(const bool value); amount_t(const int value); amount_t(const unsigned int value); @@ -59,6 +65,7 @@ class amount_t // assignment operator amount_t& operator=(const amount_t& amt); amount_t& operator=(const std::string& value); + amount_t& operator=(const char * value); amount_t& operator=(const bool value); amount_t& operator=(const int value); amount_t& operator=(const unsigned int value); diff --git a/format.h b/format.h index 3077b739..172f9a85 100644 --- a/format.h +++ b/format.h @@ -105,7 +105,7 @@ class format_transaction format_transaction(std::ostream& _output_stream, const format_t& _first_line_format, const format_t& _next_lines_format, - const node_t * display_predicate, + const node_t * display_predicate = NULL, #ifdef COLLAPSED_REGISTER const bool _collapsed = false, #endif diff --git a/main.cc b/main.cc index 5a8cd8b9..eaa4afd7 100644 --- a/main.cc +++ b/main.cc @@ -491,7 +491,7 @@ int main(int argc, char * argv[]) // Process the remaining command-line arguments std::auto_ptr new_entry; - if (command == "entry") { + if (command == "e") { new_entry.reset(journal->derive_entry(argc - index, &argv[index])); } else { // Treat the remaining command-line arguments as regular @@ -636,8 +636,18 @@ int main(int argc, char * argv[]) else f = print_fmt.c_str(); + std::string first_line_format; + std::string next_lines_format; + + if (const char * p = std::strstr(f, "%/")) { + first_line_format = std::string(f, 0, p - f); + next_lines_format = std::string(p + 2); + } else { + first_line_format = next_lines_format = f; + } + if (command == "b") { - format_t format(f); + format_t format(first_line_format); format_account formatter(std::cout, format, display_predicate.get()); walk_accounts(journal->master, formatter, predicate.get(), xact_display_flags, show_subtotals, show_expanded ? 0 : 1, @@ -652,38 +662,26 @@ int main(int argc, char * argv[]) } } else if (command == "E") { - std::string first_line_format; - std::string next_lines_format; - - if (const char * p = std::strstr(f, "%/")) { - first_line_format = std::string(f, 0, p - f); - next_lines_format = std::string(p + 2); - } else { - first_line_format = next_lines_format = f; - } - format_t format(first_line_format); format_t nformat(next_lines_format); - format_equity formatter(std::cout, format, nformat, display_predicate.get()); walk_accounts(journal->master, formatter, predicate.get(), xact_display_flags, true, 0, sort_order.get()); } - else { - std::string first_line_format; - std::string next_lines_format; - - if (const char * p = std::strstr(f, "%/")) { - first_line_format = std::string(f, 0, p - f); - next_lines_format = std::string(p + 2); - } else { - first_line_format = next_lines_format = f; - } - + else if (command == "e") { format_t format(first_line_format); format_t nformat(next_lines_format); + format_transaction formatter(std::cout, format, nformat); + for (transactions_list::iterator i = new_entry->transactions.begin(); + i != new_entry->transactions.end(); + i++) + handle_transaction(*i, formatter, xact_display_flags); + } + else { + format_t format(first_line_format); + format_t nformat(next_lines_format); format_transaction formatter(std::cout, format, nformat, display_predicate.get(), #ifdef COLLAPSED_REGISTER