summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/global.cc18
-rw-r--r--src/option.h15
-rw-r--r--src/report.cc2
-rw-r--r--src/report.h111
4 files changed, 69 insertions, 77 deletions
diff --git a/src/global.cc b/src/global.cc
index c2a86569..f5ebe61a 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -372,29 +372,29 @@ void global_scope_t::normalize_report_options(const string& verb)
// jww (2008-08-14): This code really needs to be rationalized away
// for 3.0.
if (verb == "print" || verb == "entry" || verb == "dump") {
- rep.HANDLER(related).on();
- rep.HANDLER(related_all).on();
+ rep.HANDLER(related).on_only();
+ rep.HANDLER(related_all).on_only();
}
else if (verb == "equity") {
- rep.HANDLER(subtotal).on();
+ rep.HANDLER(subtotal).on_only();
}
else if (rep.HANDLED(related)) {
if (verb[0] == 'r') {
- rep.HANDLER(invert).on();
+ rep.HANDLER(invert).on_only();
} else {
- rep.HANDLER(subtotal).on();
- rep.HANDLER(related_all).on();
+ rep.HANDLER(subtotal).on_only();
+ rep.HANDLER(related_all).on_only();
}
}
if (! rep.HANDLED(empty))
- rep.HANDLER(display_).append("amount|(!xact&total)");
+ rep.HANDLER(display_).on("amount|(!xact&total)");
if (verb[0] != 'b' && verb[0] != 'r')
- rep.HANDLER(base).on();
+ rep.HANDLER(base).on_only();
if (rep.HANDLED(period_) && ! rep.HANDLED(sort_all_))
- rep.HANDLER(sort_entries_).on();
+ rep.HANDLER(sort_entries_).on_only();
}
void handle_debug_options(int argc, char * argv[])
diff --git a/src/option.h b/src/option.h
index 5abc312f..d7aeba1b 100644
--- a/src/option.h
+++ b/src/option.h
@@ -119,18 +119,13 @@ public:
return value.as_string_lval();
}
- void on() {
+ void on_only() {
handled = true;
}
- void on(const char * str) {
- handled = true;
- value = string_value(str);
- }
void on(const string& str) {
- handled = true;
- value = string_value(str);
+ on_with(string_value(str));
}
- void on(const value_t& val) {
+ virtual void on_with(const value_t& val) {
handled = true;
value = val;
}
@@ -146,9 +141,9 @@ public:
if (wants_arg) {
if (args.empty())
throw_(std::runtime_error, "No argument provided for " << desc());
- on(args[0]);
+ on_with(args[0]);
} else {
- on();
+ on_only();
}
handler_thunk(args);
diff --git a/src/report.cc b/src/report.cc
index 7ba9ac2f..a145a1cc 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -224,7 +224,7 @@ namespace {
value_t operator()(call_scope_t& args)
{
if (args.size() > 0) {
- report.HANDLER(limit_).append
+ report.HANDLER(limit_).on
(args_to_predicate_expr(args.value().as_sequence().begin(),
args.value().as_sequence().end()));
DEBUG("report.predicate",
diff --git a/src/report.h b/src/report.h
index 8ce5f913..60c6249f 100644
--- a/src/report.h
+++ b/src/report.h
@@ -180,11 +180,11 @@ public:
*/
OPTION__(report_t, abbrev_len_,
- CTOR(report_t, abbrev_len_) { on(2L); });
+ CTOR(report_t, abbrev_len_) { on_with(2L); });
OPTION(report_t, account_);
OPTION_(report_t, actual, DO() { // -L
- parent->HANDLER(limit_).append("actual");
+ parent->HANDLER(limit_).on("actual");
});
OPTION_(report_t, add_budget, DO() {
@@ -206,7 +206,7 @@ public:
});
OPTION_(report_t, amount_data, DO() { // -j
- parent->HANDLER(format_).on(parent->HANDLER(plot_amount_format_).str());
+ parent->HANDLER(format_).on_with(parent->HANDLER(plot_amount_format_).value);
});
OPTION(report_t, anon);
@@ -240,7 +240,7 @@ public:
string predicate =
"date>=[" + to_iso_extended_string(interval.begin) + "]";
- parent->HANDLER(limit_).append(predicate);
+ parent->HANDLER(limit_).on(predicate);
});
OPTION_(report_t, budget, DO() {
@@ -251,7 +251,7 @@ public:
OPTION(report_t, cache_);
OPTION_(report_t, cleared, DO() { // -C
- parent->HANDLER(limit_).append("cleared");
+ parent->HANDLER(limit_).on("cleared");
});
OPTION(report_t, code_as_payee);
@@ -262,11 +262,11 @@ public:
OPTION_(report_t, collapse, DO() { // -n
// Make sure that balance reports are collapsed too, but only apply it
// to account entries
- parent->HANDLER(display_).append("xact|depth<=1");
+ parent->HANDLER(display_).on("xact|depth<=1");
});
OPTION_(report_t, collapse_if_zero, DO() {
- parent->HANDLER(collapse).on();
+ parent->HANDLER(collapse).on_only();
});
OPTION__(report_t, csv_format_, CTOR(report_t, csv_format_) {
@@ -284,7 +284,7 @@ public:
OPTION(report_t, current); // -c
OPTION_(report_t, daily, DO() {
- parent->HANDLER(period_).prepend("daily");
+ parent->HANDLER(period_).on("daily");
});
OPTION__(report_t, date_format_, // -y
@@ -297,14 +297,12 @@ public:
OPTION__
(report_t, display_, // -d
CTOR(report_t, display_) {}
- void append(const string& text) {
+ virtual void on_with(const value_t& text) {
if (! handled)
- on(text);
+ option_t<report_t>::on_with(text);
else
- on(string("(") + str() + ")&(" + text + ")");
- }
- DO_(args) {
- append(args[0].to_string());
+ option_t<report_t>::on_with(string_value(string("(") + str() + ")&(" +
+ text.as_string() + ")"));
});
OPTION__
@@ -348,7 +346,7 @@ public:
string predicate =
"date<[" + to_iso_extended_string(interval.begin) + "]";
- parent->HANDLER(limit_).append(predicate);
+ parent->HANDLER(limit_).on(predicate);
#if 0
terminus = interval.begin;
#endif
@@ -368,14 +366,12 @@ public:
OPTION__
(report_t, limit_, // -l
CTOR(report_t, limit_) {}
- void append(const string& text) {
+ virtual void on_with(const value_t& text) {
if (! handled)
- on(text);
+ option_t<report_t>::on_with(text);
else
- on(string("(") + str() + ")&(" + text + ")");
- }
- DO_(args) {
- append(args[0].to_string());
+ option_t<report_t>::on_with(string_value(string("(") + str() + ")&(" +
+ text.as_string() + ")"));
});
OPTION(report_t, lot_dates);
@@ -384,26 +380,24 @@ public:
OPTION(report_t, lots);
OPTION_(report_t, market, DO() { // -V
- parent->HANDLER(revalued).on();
+ parent->HANDLER(revalued).on_only();
parent->HANDLER(display_amount_).set_expr("market_value(amount_expr)");
parent->HANDLER(display_total_).set_expr("market_value(total_expr)");
});
OPTION_(report_t, monthly, DO() { // -M
- parent->HANDLER(period_).prepend("monthly");
+ parent->HANDLER(period_).on("monthly");
});
OPTION__
(report_t, only_,
CTOR(report_t, only_) {}
- void append(const string& text) {
+ virtual void on_with(const value_t& text) {
if (! handled)
- on(text);
+ option_t<report_t>::on_with(text);
else
- on(string("(") + str() + ")&(" + text + ")");
- }
- DO_(args) {
- append(args[0].to_string());
+ option_t<report_t>::on_with(string_value(string("(") + str() + ")&(" +
+ text.as_string() + ")"));
});
OPTION(report_t, output_); // -o
@@ -411,7 +405,7 @@ public:
OPTION(report_t, payee_as_account);
OPTION_(report_t, pending, DO() { // -C
- parent->HANDLER(limit_).append("pending");
+ parent->HANDLER(limit_).on("pending");
});
OPTION(report_t, percentage); // -%
@@ -420,19 +414,22 @@ public:
OPTION__
(report_t, period_, // -p
CTOR(report_t, period_) {}
- void prepend(const string& text) {
+ virtual void on_with(const value_t& text) {
if (! handled)
- on(text);
+ option_t<report_t>::on_with(text);
else
- on(text + " " + str());
- }
- DO_(args) {
- prepend(args[0].to_string());
+ option_t<report_t>::on_with(string_value(text.as_string() + " " + str()));
});
OPTION(report_t, period_sort_);
- OPTION(report_t, plot_amount_format_);
- OPTION(report_t, plot_total_format_);
+
+ OPTION__(report_t, plot_amount_format_, CTOR(report_t, plot_amount_format_) {
+ on("%(format_date(date, \"%Y-%m-%d\")) %(quantity(strip(amount)))\n");
+ });
+
+ OPTION__(report_t, plot_total_format_, CTOR(report_t, plot_total_format_) {
+ on("%(format_date(date, \"%Y-%m-%d\")) %(quantity(strip(total)))\n");
+ });
OPTION_(report_t, price, DO() { // -I
parent->HANDLER(revalued).off();
@@ -469,11 +466,11 @@ public:
});
OPTION_(report_t, quarterly, DO() {
- parent->HANDLER(period_).prepend("quarterly");
+ parent->HANDLER(period_).on("quarterly");
});
OPTION_(report_t, real, DO() { // -R
- parent->HANDLER(limit_).append("real");
+ parent->HANDLER(limit_).on("real");
});
OPTION__(report_t, register_format_, CTOR(report_t, register_format_) {
@@ -503,18 +500,18 @@ public:
OPTION(report_t, set_price_);
OPTION_(report_t, sort_, DO_(args) { // -S
- on(args[0].to_string());
+ on_with(args[0]);
parent->HANDLER(sort_entries_).off();
parent->HANDLER(sort_all_).off();
});
OPTION_(report_t, sort_all_, DO_(args) {
- parent->HANDLER(sort_).on(args[0].to_string());
+ parent->HANDLER(sort_).on_with(args[0]);
parent->HANDLER(sort_entries_).off();
});
OPTION_(report_t, sort_entries_, DO_(args) {
- parent->HANDLER(sort_).on(args[0].to_string());
+ parent->HANDLER(sort_).on_with(args[0]);
parent->HANDLER(sort_all_).off();
});
@@ -536,7 +533,7 @@ public:
});
OPTION_(report_t, total_data, DO() { // -J
- parent->HANDLER(format_).on(parent->HANDLER(plot_total_format_).str());
+ parent->HANDLER(format_).on_with(parent->HANDLER(plot_total_format_).value);
});
OPTION(report_t, totals);
@@ -560,39 +557,39 @@ public:
});
OPTION_(report_t, uncleared, DO() { // -U
- parent->HANDLER(limit_).append("uncleared|pending");
+ parent->HANDLER(limit_).on("uncleared|pending");
});
OPTION_(report_t, weekly, DO() { // -W
- parent->HANDLER(period_).prepend("weekly");
+ parent->HANDLER(period_).on("weekly");
});
OPTION_(report_t, wide, DO() { // -w
- parent->HANDLER(date_width_).on(9L);
- parent->HANDLER(payee_width_).on(35L);
- parent->HANDLER(account_width_).on(39L);
- parent->HANDLER(amount_width_).on(22L);
- parent->HANDLER(total_width_).on(22L);
+ parent->HANDLER(date_width_).on_with(9L);
+ parent->HANDLER(payee_width_).on_with(35L);
+ parent->HANDLER(account_width_).on_with(39L);
+ parent->HANDLER(amount_width_).on_with(22L);
+ parent->HANDLER(total_width_).on_with(22L);
});
OPTION_(report_t, yearly, DO() { // -Y
- parent->HANDLER(period_).prepend("yearly");
+ parent->HANDLER(period_).on("yearly");
});
OPTION__(report_t, date_width_,
- CTOR(report_t, date_width_) { on(9L); }
+ CTOR(report_t, date_width_) { on_with(9L); }
DO_(args) { value = args[0].to_long(); });
OPTION__(report_t, payee_width_,
- CTOR(report_t, payee_width_) { on(20L); }
+ CTOR(report_t, payee_width_) { on_with(20L); }
DO_(args) { value = args[0].to_long(); });
OPTION__(report_t, account_width_,
- CTOR(report_t, account_width_) { on(23L); }
+ CTOR(report_t, account_width_) { on_with(23L); }
DO_(args) { value = args[0].to_long(); });
OPTION__(report_t, amount_width_,
- CTOR(report_t, amount_width_) { on(12L); }
+ CTOR(report_t, amount_width_) { on_with(12L); }
DO_(args) { value = args[0].to_long(); });
OPTION__(report_t, total_width_,
- CTOR(report_t, total_width_) { on(12L); }
+ CTOR(report_t, total_width_) { on_with(12L); }
DO_(args) { value = args[0].to_long(); });
};