diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | src/main.cc | 30 | ||||
-rw-r--r-- | src/output.cc | 12 | ||||
-rw-r--r-- | src/output.h | 18 | ||||
-rw-r--r-- | test/regress/205.test | 4 |
5 files changed, 31 insertions, 36 deletions
diff --git a/Makefile.am b/Makefile.am index 3053e58f..1a0c3031 100644 --- a/Makefile.am +++ b/Makefile.am @@ -155,7 +155,7 @@ bin_PROGRAMS = ledger ledger_CPPFLAGS = $(libledger_la_CPPFLAGS) ledger_SOURCES = src/main.cc lib/fdstream.h ledger_LDADD = $(LIBOBJS) libamounts.la libledger.la -ledger_LDFLAGS = -static +ledger_LDFLAGS = info_TEXINFOS = doc/ledger.texi @@ -229,7 +229,6 @@ TESTS = if HAVE_PYTHON TESTS += RegressionTests -XFAIL_TESTS = RegressionTests # jww (2008-08-07): for now endif if HAVE_CPPUNIT diff --git a/src/main.cc b/src/main.cc index eeff5bb7..8790fb17 100644 --- a/src/main.cc +++ b/src/main.cc @@ -150,32 +150,28 @@ namespace ledger { return final_value_expr; } - template <class Formatter = format_xacts, + template <class Type = xact_t, class handler_ptr = xact_handler_ptr, void (report_t::*report_method)(handler_ptr) = &report_t::xacts_report> class reporter { - string format_name; + shared_ptr<item_handler<Type> > handler; public: - reporter(const string& _format_name) - : format_name(_format_name) {} + reporter(item_handler<Type> * _handler) + : handler(_handler) {} value_t operator()(call_scope_t& args) { - report_t& report(find_scope<report_t>(args)); - var_t<string> format(args, format_name); - - if (! report.format_string.empty()) - *format = report.format_string; + report_t& report(find_scope<report_t>(args)); if (args.value().size() > 0) report.append_predicate (args_to_predicate(args.value().as_sequence().begin(), args.value().as_sequence().end())); - (report.*report_method)(handler_ptr(new Formatter(report, *format))); + (report.*report_method)(handler_ptr(handler)); return true; } @@ -403,15 +399,17 @@ namespace ledger { function_t command; if (verb == "register" || verb == "reg" || verb == "r") - command = reporter<>("register_format"); + command = reporter<>(new format_xacts(report, session.register_format)); else if (verb == "print" || verb == "p") - command = reporter<>("print_format"); + command = reporter<>(new format_xacts(report, session.print_format)); else if (verb == "balance" || verb == "bal" || verb == "b") - command = reporter<format_accounts, acct_handler_ptr, - &report_t::accounts_report>("balance_format"); + command = reporter<account_t, acct_handler_ptr, + &report_t::accounts_report> + (new format_accounts(report, session.balance_format)); else if (verb == "equity") - command = reporter<format_equity, acct_handler_ptr, - &report_t::accounts_report>("print_format"); + command = reporter<account_t, acct_handler_ptr, + &report_t::accounts_report> + (new format_equity(report, session.print_format)); #if 0 else if (verb == "entry") command = entry_command(); diff --git a/src/output.cc b/src/output.cc index b05f5815..e3b31df4 100644 --- a/src/output.cc +++ b/src/output.cc @@ -138,22 +138,18 @@ void format_accounts::flush() { std::ostream& out(*report.output_stream); -#if 0 - // jww (2008-08-02): I need access to the output formatter before this is - // going to work. if (print_final_total) { assert(out); - assert(account_has_xdata(*session.master)); + assert(report.session.master->has_xdata()); - account_xdata_t& xdata(account_xdata(*session.master)); + account_t::xdata_t& xdata(report.session.master->xdata()); - if (! show_collapsed && xdata.total) { + if (! report.show_collapsed && xdata.total) { out << "--------------------\n"; xdata.value = xdata.total; - handler->format.format(out, *session.master); + format.format(out, *report.session.master); } } -#endif out.flush(); } diff --git a/src/output.h b/src/output.h index 885b8bc9..3fe1ce71 100644 --- a/src/output.h +++ b/src/output.h @@ -90,22 +90,24 @@ private: class format_accounts : public item_handler<account_t> { protected: - report_t& report; - + report_t& report; + format_t format; item_predicate<account_t> disp_pred; + bool print_final_total; bool disp_subaccounts_p(account_t& account, account_t *& to_show); bool display_account(account_t& account); public: - format_t format; - format_accounts(report_t& _report, const string& _format, - const string& display_predicate = "" /*, - const bool print_final_total = true */) - : report(_report), disp_pred(display_predicate), format(_format) { - TRACE_CTOR(format_accounts, "report&, const string&, const string&"); + const string& display_predicate = "", + const bool _print_final_total = true) + : report(_report), format(_format), disp_pred(display_predicate), + print_final_total(_print_final_total) + { + TRACE_CTOR(format_accounts, + "report&, const string&, const string&, const bool"); } virtual ~format_accounts() { TRACE_DTOR(format_accounts); diff --git a/test/regress/205.test b/test/regress/205.test index 0ad16aad..2de1f78e 100644 --- a/test/regress/205.test +++ b/test/regress/205.test @@ -4,8 +4,8 @@ bal Assets:Investments:Vanguard:VMMXX 0.350 VMMXX @ $1.00 Income:Dividends:Vanguard:VMMXX $-0.35 >>>1 - 0.350 VMMXX Assets - $-0.35 Income + 0.350 VMMXX Assets:Investments:Vanguard:VMMXX + $-0.35 Income:Dividends:Vanguard:VMMXX -------------------- $-0.35 0.350 VMMXX |