From 86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 18 Jun 2009 18:50:49 +0100 Subject: The -X option now accepts price settings For example, if you had 100 AU (onces of gold) and wanted to report it in dollars, but at a price of $997 per ounce, you could now easily say: ledger bal -X '$,AU=$997' --- src/report.cc | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) (limited to 'src/report.cc') diff --git a/src/report.cc b/src/report.cc index fde3365b..6c7a9f39 100644 --- a/src/report.cc +++ b/src/report.cc @@ -129,33 +129,21 @@ value_t report_t::fn_market(call_scope_t& scope) { interactive_t args(scope, "a&ts"); - if (args.has(2)) { - scoped_array buf(new char[args.get(2).length() + 1]); - std::strcpy(buf.get(), args.get(2).c_str()); - - for (char * p = std::strtok(buf.get(), ","); - p; - p = std::strtok(NULL, ",")) { - if (commodity_t * commodity = amount_t::current_pool->find(trim_ws(p))) { - DEBUG("report.market", "Searching for value of " << args.value_at(0) - << " in terms of commodity " << commodity->symbol()); - value_t result = - args.value_at(0).value(false, args.has(1) ? + value_t result; + optional moment = (args.has(1) ? args.get(1) : - optional(), *commodity); - if (! result.is_null()) { - DEBUG("report.market", "Market value is = " << result); - return result; - } - } - } - } else { - value_t result = - args.value_at(0).value(true, args.has(1) ? - args.get(1) : optional()); - if (! result.is_null()) - return result; - } + optional()); + + if (args.has(2)) + result = args.value_at(0).exchange_commodities(args.get(2), + /* add_prices= */ false, + moment); + else + result = args.value_at(0).value(true, moment); + + if (! result.is_null()) + return result; + return args.value_at(0); } @@ -608,7 +596,6 @@ option_t * report_t::lookup_option(const char * p) case 's': OPT(set_account_); else OPT(set_payee_); - else OPT(set_price_); else OPT(sort_); else OPT(sort_all_); else OPT(sort_xacts_); -- cgit v1.2.3