From b0f12c600c8080d11d8f514aa7d4149323da6803 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Oct 2009 03:07:15 -0400 Subject: Added a --forecast-years option This sets how many years of forecasting Ledger will do before it terminates the attempt. --- src/report.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/report.cc') diff --git a/src/report.cc b/src/report.cc index bc0680d1..7d74952c 100644 --- a/src/report.cc +++ b/src/report.cc @@ -559,6 +559,7 @@ option_t * report_t::lookup_option(const char * p) case 'f': OPT(flat); else OPT_ALT(forecast_while_, forecast_); + else OPT(forecast_years_); else OPT(format_); else OPT(force_color); else OPT(force_pager); -- cgit v1.2.3 From 77c9d7b1ff9fc0033e653453e08d042b2e95692b Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Oct 2009 03:22:38 -0400 Subject: Add valexpr functions for lot dates, prices and tags --- src/report.cc | 33 +++++++++++++++++++++++++++++++++ src/report.h | 3 +++ 2 files changed, 36 insertions(+) (limited to 'src/report.cc') diff --git a/src/report.cc b/src/report.cc index 7d74952c..565597c6 100644 --- a/src/report.cc +++ b/src/report.cc @@ -315,6 +315,39 @@ value_t report_t::fn_price(call_scope_t& scope) return args.value_at(0).price(); } +value_t report_t::fn_lot_date(call_scope_t& scope) +{ + interactive_t args(scope, "v"); + if (args.value_at(0).is_annotated()) { + const annotation_t& details(args.value_at(0).annotation()); + if (details.date) + return *details.date; + } + return NULL_VALUE; +} + +value_t report_t::fn_lot_price(call_scope_t& scope) +{ + interactive_t args(scope, "v"); + if (args.value_at(0).is_annotated()) { + const annotation_t& details(args.value_at(0).annotation()); + if (details.price) + return *details.price; + } + return NULL_VALUE; +} + +value_t report_t::fn_lot_tag(call_scope_t& scope) +{ + interactive_t args(scope, "v"); + if (args.value_at(0).is_annotated()) { + const annotation_t& details(args.value_at(0).annotation()); + if (details.tag) + return string_value(*details.tag); + } + return NULL_VALUE; +} + namespace { value_t fn_black(call_scope_t&) { return string_value("black"); diff --git a/src/report.h b/src/report.h index c1ad1997..0fe7d05b 100644 --- a/src/report.h +++ b/src/report.h @@ -160,6 +160,9 @@ public: value_t fn_ansify_if(call_scope_t& scope); value_t fn_percent(call_scope_t& scope); value_t fn_price(call_scope_t& scope); + value_t fn_lot_date(call_scope_t& scope); + value_t fn_lot_price(call_scope_t& scope); + value_t fn_lot_tag(call_scope_t& scope); value_t fn_now(call_scope_t&) { return terminus; -- cgit v1.2.3 From 4427016b1bc20fac4c1700e4f1577f6c7f9ab78c Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Oct 2009 03:34:32 -0400 Subject: Improved arg checking for several valexpr functions --- src/item.cc | 27 ++++++++++++++++++++++----- src/option.h | 15 +++++++++++++-- src/report.cc | 8 ++++---- 3 files changed, 39 insertions(+), 11 deletions(-) (limited to 'src/report.cc') diff --git a/src/item.cc b/src/item.cc index 631423a9..debda7a3 100644 --- a/src/item.cc +++ b/src/item.cc @@ -32,6 +32,7 @@ #include #include "item.h" +#include "interactive.h" namespace ledger { @@ -210,15 +211,31 @@ namespace { return item.has_tag(args[0].as_string()); else if (args[0].is_mask()) return item.has_tag(args[0].as_mask()); - } else { - return item.has_tag(args[0].to_mask(), args[1].to_mask()); + else + throw_(std::logic_error, + _("Expected string for argument 1, but received %1") + << args[0].label()); + } + else if (args.size() == 2) { + if (args[0].is_mask() && args[1].is_mask()) + return item.has_tag(args[0].to_mask(), args[1].to_mask()); + else + throw_(std::logic_error, + _("Expected masks for arguments 1 and 2, but received %1 and %2") + << args[0].label() << args[1].label()); + } + else if (args.size() == 0) { + throw_(std::logic_error, _("Too few arguments to function")); + } + else { + throw_(std::logic_error, _("Too many arguments to function")); } return false; } - value_t get_tag(call_scope_t& args) { - item_t& item(find_scope(args)); - if (optional value = item.get_tag(args[0].as_string())) + value_t get_tag(call_scope_t& scope) { + in_context_t env(scope, "s"); + if (optional value = env->get_tag(env.get(0))) return string_value(*value); return false; } diff --git a/src/option.h b/src/option.h index 83710a1c..0600779c 100644 --- a/src/option.h +++ b/src/option.h @@ -162,10 +162,21 @@ public: virtual void handler(call_scope_t& args) { if (wants_arg) { - if (args.empty() || args.size() == 1) + if (args.size() < 2) throw_(std::runtime_error, _("No argument provided for %1") << desc()); + else if (args.size() > 2) + throw_(std::runtime_error, _("To many arguments provided for %1") << desc()); + else if (! args[0].is_string()) + throw_(std::runtime_error, _("Context argument for %1 not a string") << desc()); on_with(args[0].as_string(), args[1]); - } else { + } + else if (args.size() < 1) { + throw_(std::runtime_error, _("No argument provided for %1") << desc()); + } + else if (! args[0].is_string()) { + throw_(std::runtime_error, _("Context argument for %1 not a string") << desc()); + } + else { on_only(args[0].as_string()); } diff --git a/src/report.cc b/src/report.cc index 565597c6..096536c9 100644 --- a/src/report.cc +++ b/src/report.cc @@ -235,12 +235,13 @@ value_t report_t::fn_justify(call_scope_t& scope) return string_value(out.str()); } -value_t report_t::fn_quoted(call_scope_t& args) +value_t report_t::fn_quoted(call_scope_t& scope) { + interactive_t args(scope, "s"); std::ostringstream out; out << '"'; - foreach (const char ch, args[0].to_string()) { + foreach (const char ch, args.get(0)) { if (ch == '"') out << "\\\""; else @@ -253,8 +254,7 @@ value_t report_t::fn_quoted(call_scope_t& args) value_t report_t::fn_join(call_scope_t& scope) { - interactive_t args(scope, "s"); - + interactive_t args(scope, "s"); std::ostringstream out; foreach (const char ch, args.get(0)) { -- cgit v1.2.3