summaryrefslogtreecommitdiff
path: root/src/report.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-06-18 18:50:49 +0100
committerJohn Wiegley <johnw@newartisans.com>2009-06-18 18:50:49 +0100
commit86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9 (patch)
tree55965512c0a1abf8f4bbb1519817c7b96fdcab12 /src/report.cc
parent1dc21c2d344aa52833e516fea831ff45d8bf7aa1 (diff)
downloadfork-ledger-86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9.tar.gz
fork-ledger-86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9.tar.bz2
fork-ledger-86dfc1e0be5dbfab195cba8a8be31d3dbf0f68c9.zip
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'
Diffstat (limited to 'src/report.cc')
-rw-r--r--src/report.cc41
1 files changed, 14 insertions, 27 deletions
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<char> buf(new char[args.get<string>(2).length() + 1]);
- std::strcpy(buf.get(), args.get<string>(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<datetime_t> moment = (args.has(1) ?
args.get<datetime_t>(1) :
- optional<datetime_t>(), *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<datetime_t>(1) : optional<datetime_t>());
- if (! result.is_null())
- return result;
- }
+ optional<datetime_t>());
+
+ if (args.has(2))
+ result = args.value_at(0).exchange_commodities(args.get<string>(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> * 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_);