Prettified some code in report.cc
This commit is contained in:
parent
121d878a0c
commit
477a9106e3
1 changed files with 55 additions and 84 deletions
139
src/report.cc
139
src/report.cc
|
|
@ -1382,24 +1382,37 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
|
||||||
return MAKE_OPT_HANDLER(report_t, handler);
|
return MAKE_OPT_HANDLER(report_t, handler);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#define POSTS_REPORT(formatter) \
|
||||||
|
WRAP_FUNCTOR(reporter<>(post_handler_ptr(formatter), *this, \
|
||||||
|
string("#") + p));
|
||||||
|
|
||||||
|
// Can't use WRAP_FUNCTOR here because the template arguments
|
||||||
|
// confuse the parser
|
||||||
|
#define POSTS_REPORT_(method, formatter) \
|
||||||
|
expr_t::op_t::wrap_functor \
|
||||||
|
(reporter<post_t, post_handler_ptr, method> \
|
||||||
|
(post_handler_ptr(formatter), *this, string("#") + p));
|
||||||
|
|
||||||
|
#define ACCOUNTS_REPORT(formatter) \
|
||||||
|
expr_t::op_t::wrap_functor(reporter<account_t, acct_handler_ptr, \
|
||||||
|
&report_t::accounts_report> \
|
||||||
|
(acct_handler_ptr(formatter), *this, \
|
||||||
|
string("#") + p));
|
||||||
|
|
||||||
case symbol_t::COMMAND:
|
case symbol_t::COMMAND:
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case 'a':
|
case 'a':
|
||||||
if (is_eq(p, "accounts")) {
|
if (is_eq(p, "accounts")) {
|
||||||
return WRAP_FUNCTOR(reporter<>(post_handler_ptr(new report_accounts(*this)),
|
return POSTS_REPORT(new report_accounts(*this));
|
||||||
*this, "#accounts"));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b':
|
case 'b':
|
||||||
if (*(p + 1) == '\0' || is_eq(p, "bal") || is_eq(p, "balance")) {
|
if (*(p + 1) == '\0' || is_eq(p, "bal") || is_eq(p, "balance")) {
|
||||||
return expr_t::op_t::wrap_functor
|
return ACCOUNTS_REPORT(new format_accounts
|
||||||
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
|
(*this, report_format(HANDLER(balance_format_)),
|
||||||
(acct_handler_ptr(new format_accounts
|
maybe_format(HANDLER(prepend_format_)),
|
||||||
(*this, report_format(HANDLER(balance_format_)),
|
HANDLER(prepend_width_).value.to_size_t()));
|
||||||
maybe_format(HANDLER(prepend_format_)),
|
|
||||||
HANDLER(prepend_width_).value.to_size_t())),
|
|
||||||
*this, "#balance"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "budget")) {
|
else if (is_eq(p, "budget")) {
|
||||||
HANDLER(amount_).set_expr(string("#budget"), "(amount, 0)");
|
HANDLER(amount_).set_expr(string("#budget"), "(amount, 0)");
|
||||||
|
|
@ -1408,72 +1421,46 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
|
||||||
if (! (budget_flags & ~BUDGET_WRAP_VALUES))
|
if (! (budget_flags & ~BUDGET_WRAP_VALUES))
|
||||||
budget_flags |= BUDGET_BUDGETED;
|
budget_flags |= BUDGET_BUDGETED;
|
||||||
|
|
||||||
#if 0
|
return ACCOUNTS_REPORT(new format_accounts
|
||||||
#define POSTS_REPORT(formatter)
|
(*this, report_format(HANDLER(budget_format_)),
|
||||||
return WRAP_FUNCTOR(reporter<>(post_handler_ptr(formatter), *this,
|
maybe_format(HANDLER(prepend_format_)),
|
||||||
string("#") + p));
|
HANDLER(prepend_width_).value.to_size_t()));
|
||||||
|
|
||||||
#define ACCOUNTS_REPORT(formatter)
|
|
||||||
return WRAP_FUNCTOR(reporter<account_t, acct_handler_ptr,
|
|
||||||
&report_t::accounts_report>
|
|
||||||
(acct_handler_ptr(formatter), *this,
|
|
||||||
string("#") + p));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return expr_t::op_t::wrap_functor
|
|
||||||
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
|
|
||||||
(acct_handler_ptr(new format_accounts
|
|
||||||
(*this, report_format(HANDLER(budget_format_)),
|
|
||||||
maybe_format(HANDLER(prepend_format_)),
|
|
||||||
HANDLER(prepend_width_).value.to_size_t())),
|
|
||||||
*this, "#budget"));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
if (is_eq(p, "csv")) {
|
if (is_eq(p, "csv")) {
|
||||||
return WRAP_FUNCTOR
|
return POSTS_REPORT(new format_posts
|
||||||
(reporter<>
|
(*this, report_format(HANDLER(csv_format_)),
|
||||||
(post_handler_ptr(new format_posts
|
maybe_format(HANDLER(prepend_format_)),
|
||||||
(*this, report_format(HANDLER(csv_format_)),
|
HANDLER(prepend_width_).value.to_size_t()));
|
||||||
maybe_format(HANDLER(prepend_format_)),
|
|
||||||
HANDLER(prepend_width_).value.to_size_t())),
|
|
||||||
*this, "#csv"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "cleared")) {
|
else if (is_eq(p, "cleared")) {
|
||||||
HANDLER(amount_).set_expr(string("#cleared"),
|
HANDLER(amount_).set_expr(string("#cleared"),
|
||||||
"(amount, cleared ? amount : 0)");
|
"(amount, cleared ? amount : 0)");
|
||||||
return expr_t::op_t::wrap_functor
|
return ACCOUNTS_REPORT(new format_accounts
|
||||||
(reporter<account_t, acct_handler_ptr, &report_t::accounts_report>
|
(*this, report_format(HANDLER(cleared_format_)),
|
||||||
(acct_handler_ptr(new format_accounts
|
maybe_format(HANDLER(prepend_format_)),
|
||||||
(*this, report_format(HANDLER(cleared_format_)),
|
HANDLER(prepend_width_).value.to_size_t()));
|
||||||
maybe_format(HANDLER(prepend_format_)),
|
|
||||||
HANDLER(prepend_width_).value.to_size_t())),
|
|
||||||
*this, "#cleared"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "convert")) {
|
else if (is_eq(p, "convert")) {
|
||||||
return WRAP_FUNCTOR(convert_command);
|
return WRAP_FUNCTOR(convert_command);
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "commodities")) {
|
else if (is_eq(p, "commodities")) {
|
||||||
return WRAP_FUNCTOR(reporter<>
|
return POSTS_REPORT(new report_commodities(*this));
|
||||||
(post_handler_ptr(new report_commodities(*this)),
|
|
||||||
*this, "#commodities"));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
if (is_eq(p, "equity")) {
|
if (is_eq(p, "equity")) {
|
||||||
HANDLER(generated).on_only(string("#equity"));
|
HANDLER(generated).on_only(string("#equity"));
|
||||||
return WRAP_FUNCTOR(reporter<>(post_handler_ptr(new print_xacts(*this)),
|
return POSTS_REPORT(new print_xacts(*this));
|
||||||
*this, "#equity"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "entry")) {
|
else if (is_eq(p, "entry")) {
|
||||||
return WRAP_FUNCTOR(xact_command);
|
return WRAP_FUNCTOR(xact_command);
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "emacs")) {
|
else if (is_eq(p, "emacs")) {
|
||||||
return WRAP_FUNCTOR
|
return POSTS_REPORT(new format_emacs_posts(output_stream));
|
||||||
(reporter<>(post_handler_ptr(new format_emacs_posts(output_stream)),
|
|
||||||
*this, "#emacs"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "echo")) {
|
else if (is_eq(p, "echo")) {
|
||||||
return MAKE_FUNCTOR(report_t::echo_command);
|
return MAKE_FUNCTOR(report_t::echo_command);
|
||||||
|
|
@ -1482,56 +1469,43 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
if (is_eq(p, "org")) {
|
if (is_eq(p, "org")) {
|
||||||
return WRAP_FUNCTOR
|
return POSTS_REPORT(new posts_to_org_table
|
||||||
(reporter<>
|
(*this, maybe_format(HANDLER(prepend_format_))));
|
||||||
(post_handler_ptr(new posts_to_org_table
|
|
||||||
(*this, maybe_format(HANDLER(prepend_format_)))),
|
|
||||||
*this, "#org"));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
if (*(p + 1) == '\0' || is_eq(p, "print")) {
|
if (*(p + 1) == '\0' || is_eq(p, "print")) {
|
||||||
return WRAP_FUNCTOR
|
return POSTS_REPORT(new print_xacts(*this, HANDLED(raw)));
|
||||||
(reporter<>(post_handler_ptr(new print_xacts(*this, HANDLED(raw))),
|
|
||||||
*this, "#print"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "prices")) {
|
else if (is_eq(p, "prices")) {
|
||||||
return expr_t::op_t::wrap_functor
|
return POSTS_REPORT_(&report_t::commodities_report,
|
||||||
(reporter<post_t, post_handler_ptr, &report_t::commodities_report>
|
new format_posts
|
||||||
(post_handler_ptr(new format_posts
|
|
||||||
(*this, report_format(HANDLER(prices_format_)),
|
(*this, report_format(HANDLER(prices_format_)),
|
||||||
maybe_format(HANDLER(prepend_format_)),
|
maybe_format(HANDLER(prepend_format_)),
|
||||||
HANDLER(prepend_width_).value.to_size_t())),
|
HANDLER(prepend_width_).value.to_size_t()));
|
||||||
*this, "#prices"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "pricedb")) {
|
else if (is_eq(p, "pricedb")) {
|
||||||
return expr_t::op_t::wrap_functor
|
return POSTS_REPORT_(&report_t::commodities_report,
|
||||||
(reporter<post_t, post_handler_ptr, &report_t::commodities_report>
|
new format_posts
|
||||||
(post_handler_ptr(new format_posts
|
|
||||||
(*this, report_format(HANDLER(pricedb_format_)),
|
(*this, report_format(HANDLER(pricedb_format_)),
|
||||||
maybe_format(HANDLER(prepend_format_)),
|
maybe_format(HANDLER(prepend_format_)),
|
||||||
HANDLER(prepend_width_).value.to_size_t())),
|
HANDLER(prepend_width_).value.to_size_t()));
|
||||||
*this, "#pricedb"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "pricemap")) {
|
else if (is_eq(p, "pricemap")) {
|
||||||
return MAKE_FUNCTOR(report_t::pricemap_command);
|
return MAKE_FUNCTOR(report_t::pricemap_command);
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "payees")) {
|
else if (is_eq(p, "payees")) {
|
||||||
return WRAP_FUNCTOR(reporter<>(post_handler_ptr(new report_payees(*this)),
|
return POSTS_REPORT(new report_payees(*this));
|
||||||
*this, "#payees"));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
if (*(p + 1) == '\0' || is_eq(p, "reg") || is_eq(p, "register")) {
|
if (*(p + 1) == '\0' || is_eq(p, "reg") || is_eq(p, "register")) {
|
||||||
return WRAP_FUNCTOR
|
return POSTS_REPORT(new format_posts
|
||||||
(reporter<>
|
(*this, report_format(HANDLER(register_format_)),
|
||||||
(post_handler_ptr(new format_posts
|
maybe_format(HANDLER(prepend_format_)),
|
||||||
(*this, report_format(HANDLER(register_format_)),
|
HANDLER(prepend_width_).value.to_size_t()));
|
||||||
maybe_format(HANDLER(prepend_format_)),
|
|
||||||
HANDLER(prepend_width_).value.to_size_t())),
|
|
||||||
*this, "#register"));
|
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "reload")) {
|
else if (is_eq(p, "reload")) {
|
||||||
return MAKE_FUNCTOR(report_t::reload_command);
|
return MAKE_FUNCTOR(report_t::reload_command);
|
||||||
|
|
@ -1549,8 +1523,7 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
|
||||||
if (is_eq(p, "xact"))
|
if (is_eq(p, "xact"))
|
||||||
return WRAP_FUNCTOR(xact_command);
|
return WRAP_FUNCTOR(xact_command);
|
||||||
else if (is_eq(p, "xml"))
|
else if (is_eq(p, "xml"))
|
||||||
return WRAP_FUNCTOR(reporter<>(post_handler_ptr(new format_xml(*this)),
|
return POSTS_REPORT(new format_xml(*this));
|
||||||
*this, "#xml"));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -1572,11 +1545,9 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
|
||||||
return WRAP_FUNCTOR(format_command);
|
return WRAP_FUNCTOR(format_command);
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
if (is_eq(p, "generate")) {
|
if (is_eq(p, "generate"))
|
||||||
return expr_t::op_t::wrap_functor
|
return POSTS_REPORT_(&report_t::generate_report,
|
||||||
(reporter<post_t, post_handler_ptr, &report_t::generate_report>
|
new print_xacts(*this));
|
||||||
(post_handler_ptr(new print_xacts(*this)), *this, "#generate"));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (is_eq(p, "parse"))
|
if (is_eq(p, "parse"))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue