diff options
Diffstat (limited to 'src/report.cc')
-rw-r--r-- | src/report.cc | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/src/report.cc b/src/report.cc index 7da44f8c..b882ca92 100644 --- a/src/report.cc +++ b/src/report.cc @@ -69,18 +69,17 @@ void report_t::normalize_options(const string& verb) item_t::use_effective_date = (HANDLED(effective) && ! HANDLED(actual_dates)); - session.journal->commodity_pool->keep_base = HANDLED(base); - session.journal->commodity_pool->get_quotes = session.HANDLED(download); + commodity_pool_t::current_pool->keep_base = HANDLED(base); + commodity_pool_t::current_pool->get_quotes = session.HANDLED(download); if (session.HANDLED(price_exp_)) - session.journal->commodity_pool->quote_leeway = + commodity_pool_t::current_pool->quote_leeway = session.HANDLER(price_exp_).value.as_long(); if (session.HANDLED(price_db_)) - session.journal->commodity_pool->price_db = - session.HANDLER(price_db_).str(); + commodity_pool_t::current_pool->price_db = session.HANDLER(price_db_).str(); else - session.journal->commodity_pool->price_db = none; + commodity_pool_t::current_pool->price_db = none; if (HANDLED(date_format_)) set_date_format(HANDLER(date_format_).str().c_str()); @@ -294,12 +293,15 @@ void report_t::accounts_report(acct_handler_ptr handler) sort_expr, HANDLED(flat))); } - if (HANDLED(display_)) + if (HANDLED(display_)) { + DEBUG("report.predicate", + "Display predicate = " << HANDLER(display_).str()); pass_down_accounts(handler, *iter.get(), predicate_t(HANDLER(display_).str(), what_to_keep()), *this); - else + } else { pass_down_accounts(handler, *iter.get()); + } session.journal->clear_xdata(); } @@ -381,6 +383,32 @@ value_t report_t::fn_strip(call_scope_t& args) return args.value().strip_annotations(what_to_keep()); } +value_t report_t::fn_trim(call_scope_t& args) +{ + string temp(args.value().to_string()); + scoped_array<char> buf(new char[temp.length() + 1]); + std::strcpy(buf.get(), temp.c_str()); + + const char * p = buf.get(); + while (*p && std::isspace(*p)) + p++; + + const char * e = buf.get() + temp.length(); + while (e > p && std::isspace(*e)) + e--; + + if (e == p) { + return string_value(empty_string); + } + else if (e < p) { + assert(false); + return string_value(empty_string); + } + else { + return string_value(string(p, e - p)); + } +} + value_t report_t::fn_scrub(call_scope_t& args) { value_t temp(args.value().strip_annotations(what_to_keep())); @@ -522,7 +550,7 @@ value_t report_t::fn_price(call_scope_t& scope) value_t report_t::fn_lot_date(call_scope_t& scope) { interactive_t args(scope, "v"); - if (args.value_at(0).is_annotated()) { + if (args.value_at(0).has_annotation()) { const annotation_t& details(args.value_at(0).annotation()); if (details.date) return *details.date; @@ -533,7 +561,7 @@ value_t report_t::fn_lot_date(call_scope_t& scope) value_t report_t::fn_lot_price(call_scope_t& scope) { interactive_t args(scope, "v"); - if (args.value_at(0).is_annotated()) { + if (args.value_at(0).has_annotation()) { const annotation_t& details(args.value_at(0).annotation()); if (details.price) return *details.price; @@ -544,7 +572,7 @@ value_t report_t::fn_lot_price(call_scope_t& scope) value_t report_t::fn_lot_tag(call_scope_t& scope) { interactive_t args(scope, "v"); - if (args.value_at(0).is_annotated()) { + if (args.value_at(0).has_annotation()) { const annotation_t& details(args.value_at(0).annotation()); if (details.tag) return string_value(*details.tag); @@ -845,6 +873,7 @@ option_t<report_t> * report_t::lookup_option(const char * p) else OPT(percent); else OPT_(period_); else OPT_ALT(sort_xacts_, period_sort_); + else OPT(pivot_); else OPT(plot_amount_format_); else OPT(plot_total_format_); else OPT(price); @@ -888,6 +917,8 @@ option_t<report_t> * report_t::lookup_option(const char * p) OPT(unbudgeted); else OPT(uncleared); else OPT(unrealized); + else OPT(unrealized_gains_); + else OPT(unrealized_losses_); else OPT(unround); else OPT(unsorted); break; @@ -1077,6 +1108,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, return MAKE_FUNCTOR(report_t::fn_today); else if (is_eq(p, "t")) return MAKE_FUNCTOR(report_t::fn_display_amount); + else if (is_eq(p, "trim")) + return MAKE_FUNCTOR(report_t::fn_trim); else if (is_eq(p, "to_boolean")) return MAKE_FUNCTOR(report_t::fn_to_boolean); else if (is_eq(p, "to_int")) @@ -1239,7 +1272,7 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, switch (*p) { case 'a': if (is_eq(p, "args")) - return WRAP_FUNCTOR(args_command); + return WRAP_FUNCTOR(query_command); break; case 'e': if (is_eq(p, "eval")) @@ -1261,6 +1294,10 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind, else if (is_eq(p, "period")) return WRAP_FUNCTOR(period_command); break; + case 'q': + if (is_eq(p, "query")) + return WRAP_FUNCTOR(query_command); + break; case 't': if (is_eq(p, "template")) return WRAP_FUNCTOR(template_command); |