Added back a lot of hacktastic logic from 2.6.1 that made the "bal" command
somewhat smart about how it interpreted certain options. Beware, code, for your days are not long-lived.
This commit is contained in:
parent
2bff7565c1
commit
6432d7c594
4 changed files with 90 additions and 110 deletions
77
src/main.cc
77
src/main.cc
|
|
@ -398,18 +398,26 @@ namespace ledger {
|
|||
|
||||
function_t command;
|
||||
|
||||
if (verb == "register" || verb == "reg" || verb == "r")
|
||||
if (verb == "register" || verb == "reg" || verb == "r") {
|
||||
verb = "register";
|
||||
command = reporter<>(new format_xacts(report, session.register_format));
|
||||
else if (verb == "print" || verb == "p")
|
||||
}
|
||||
else if (verb == "print" || verb == "p") {
|
||||
verb = "print";
|
||||
command = reporter<>(new format_xacts(report, session.print_format));
|
||||
else if (verb == "balance" || verb == "bal" || verb == "b")
|
||||
}
|
||||
else if (verb == "balance" || verb == "bal" || verb == "b") {
|
||||
verb = "balance";
|
||||
command = reporter<account_t, acct_handler_ptr,
|
||||
&report_t::accounts_report>
|
||||
(new format_accounts(report, session.balance_format));
|
||||
else if (verb == "equity")
|
||||
}
|
||||
else if (verb == "equity") {
|
||||
verb = "equity";
|
||||
command = reporter<account_t, acct_handler_ptr,
|
||||
&report_t::accounts_report>
|
||||
(new format_equity(report, session.print_format));
|
||||
}
|
||||
#if 0
|
||||
else if (verb == "entry")
|
||||
command = entry_command();
|
||||
|
|
@ -440,6 +448,67 @@ namespace ledger {
|
|||
throw_(std::logic_error, string("Unrecognized command '") + verb + "'");
|
||||
}
|
||||
|
||||
// Patch up some of the reporting options based on what kind of
|
||||
// command it was.
|
||||
|
||||
// jww (2008-08-14): This code really needs to be rationalized away
|
||||
// for 3.0.
|
||||
|
||||
if (verb == "print" || verb == "entry" || verb == "dump") {
|
||||
report.show_related = true;
|
||||
report.show_all_related = true;
|
||||
}
|
||||
else if (verb == "equity") {
|
||||
report.show_subtotal = true;
|
||||
}
|
||||
else if (report.show_related) {
|
||||
if (verb == "register") {
|
||||
report.show_inverted = true;
|
||||
} else {
|
||||
report.show_subtotal = true;
|
||||
report.show_all_related = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (verb != "balance" && verb != "register")
|
||||
amount_t::keep_base = true;
|
||||
|
||||
// Setup the default value for the display predicate
|
||||
|
||||
if (report.display_predicate.empty()) {
|
||||
if (verb == "balance") {
|
||||
if (! report.show_empty)
|
||||
report.display_predicate = "total";
|
||||
if (! report.show_subtotal) {
|
||||
if (! report.display_predicate.empty())
|
||||
report.display_predicate += "&";
|
||||
report.display_predicate += "depth<=1";
|
||||
}
|
||||
}
|
||||
else if (verb == "equity") {
|
||||
report.display_predicate = "fmt_t"; // jww (2008-08-14): ???
|
||||
}
|
||||
else if (verb == "register" && ! report.show_empty) {
|
||||
report.display_predicate = "amount";
|
||||
}
|
||||
}
|
||||
|
||||
// Now setup the various formatting strings
|
||||
|
||||
// jww (2008-08-14): I hear a song, and it's sound is "HaAaaCcK"
|
||||
|
||||
#if 0
|
||||
if (! date_output_format.empty())
|
||||
date_t::output_format = date_output_format;
|
||||
#endif
|
||||
|
||||
amount_t::keep_price = report.keep_price;
|
||||
amount_t::keep_date = report.keep_date;
|
||||
amount_t::keep_tag = report.keep_tag;
|
||||
|
||||
if (! report.report_period.empty() && ! report.sort_all)
|
||||
report.entry_sort = true;
|
||||
|
||||
// Create an argument scope containing the report command's
|
||||
// arguments, and then invoke the command.
|
||||
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ bool format_accounts::disp_subaccounts_p(account_t& account,
|
|||
{
|
||||
bool display = false;
|
||||
unsigned int counted = 0;
|
||||
bool matches = disp_pred(account);
|
||||
bool matches = should_display(account);
|
||||
bool computed = false;
|
||||
value_t acct_total;
|
||||
value_t result;
|
||||
|
|
@ -179,7 +179,7 @@ bool format_accounts::disp_subaccounts_p(account_t& account,
|
|||
to_show = NULL;
|
||||
|
||||
foreach (accounts_map::value_type pair, account.accounts) {
|
||||
if (! disp_pred(*pair.second))
|
||||
if (! should_display(*pair.second))
|
||||
continue;
|
||||
|
||||
call_scope_t args(*pair.second);
|
||||
|
|
@ -219,13 +219,11 @@ bool format_accounts::display_account(account_t& account)
|
|||
if (disp_subaccounts_p(account, account_to_show))
|
||||
return true;
|
||||
|
||||
return ! account_to_show && disp_pred(account);
|
||||
return ! account_to_show && should_display(account);
|
||||
}
|
||||
|
||||
format_equity::format_equity(report_t& _report,
|
||||
const string& _format,
|
||||
const string& display_predicate)
|
||||
: format_accounts(_report, "", display_predicate)
|
||||
format_equity::format_equity(report_t& _report, const string& _format)
|
||||
: format_accounts(_report)
|
||||
{
|
||||
const char * f = _format.c_str();
|
||||
|
||||
|
|
|
|||
18
src/output.h
18
src/output.h
|
|
@ -100,21 +100,24 @@ protected:
|
|||
|
||||
public:
|
||||
format_accounts(report_t& _report,
|
||||
const string& _format,
|
||||
const string& display_predicate = "",
|
||||
const string& _format = "",
|
||||
const bool _print_final_total = true)
|
||||
: report(_report), format(_format), disp_pred(display_predicate),
|
||||
: report(_report), format(_format), disp_pred(),
|
||||
print_final_total(_print_final_total)
|
||||
{
|
||||
TRACE_CTOR(format_accounts,
|
||||
"report&, const string&, const string&, const bool");
|
||||
TRACE_CTOR(format_accounts, "report&, const string&, const bool");
|
||||
}
|
||||
virtual ~format_accounts() {
|
||||
TRACE_DTOR(format_accounts);
|
||||
}
|
||||
|
||||
virtual void flush();
|
||||
bool should_display(account_t& account) {
|
||||
if (! disp_pred.predicate)
|
||||
disp_pred.predicate.parse(report.display_predicate);
|
||||
return disp_pred(account);
|
||||
}
|
||||
|
||||
virtual void flush();
|
||||
virtual void operator()(account_t& account);
|
||||
};
|
||||
|
||||
|
|
@ -127,8 +130,7 @@ class format_equity : public format_accounts
|
|||
|
||||
public:
|
||||
format_equity(report_t& _report,
|
||||
const string& _format,
|
||||
const string& display_predicate = "");
|
||||
const string& _format);
|
||||
virtual ~format_equity() {
|
||||
TRACE_DTOR(format_equity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,95 +34,6 @@
|
|||
|
||||
namespace ledger {
|
||||
|
||||
#if 0
|
||||
void report_t::process_options(const std::string& command,
|
||||
strings_list::iterator arg,
|
||||
strings_list::iterator args_end)
|
||||
{
|
||||
// Configure some other options depending on report type
|
||||
|
||||
if (command == "p" || command == "e" || command == "w") {
|
||||
show_related =
|
||||
show_all_related = true;
|
||||
}
|
||||
else if (command == "E") {
|
||||
show_subtotal = true;
|
||||
}
|
||||
else if (show_related) {
|
||||
if (command == "r") {
|
||||
show_inverted = true;
|
||||
} else {
|
||||
show_subtotal = true;
|
||||
show_all_related = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (command != "b" && command != "r")
|
||||
amount_t::keep_base = true;
|
||||
|
||||
// Process remaining command-line arguments
|
||||
|
||||
if (command != "e") {
|
||||
// Treat the remaining command-line arguments as regular
|
||||
// expressions, used for refining report results.
|
||||
|
||||
std::list<std::string>::iterator i = arg;
|
||||
for (; i != args_end; i++)
|
||||
if (*i == "--")
|
||||
break;
|
||||
|
||||
if (i != arg)
|
||||
regexps_to_predicate(command, arg, i, true,
|
||||
(command == "b" && ! show_subtotal &&
|
||||
display_predicate.empty()));
|
||||
if (i != args_end && ++i != args_end)
|
||||
regexps_to_predicate(command, i, args_end);
|
||||
}
|
||||
|
||||
// Setup the default value for the display predicate
|
||||
|
||||
if (display_predicate.empty()) {
|
||||
if (command == "b") {
|
||||
if (! show_empty)
|
||||
display_predicate = "T";
|
||||
if (! show_subtotal) {
|
||||
if (! display_predicate.empty())
|
||||
display_predicate += "&";
|
||||
display_predicate += "l<=1";
|
||||
}
|
||||
}
|
||||
else if (command == "E") {
|
||||
display_predicate = "t";
|
||||
}
|
||||
else if (command == "r" && ! show_empty) {
|
||||
display_predicate = "a";
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_PRINT("ledger.config.predicates", "Predicate: " << predicate);
|
||||
DEBUG_PRINT("ledger.config.predicates", "Display P: " << display_predicate);
|
||||
|
||||
// Setup the values of %t and %T, used in format strings
|
||||
|
||||
if (! amount_expr.empty())
|
||||
ledger::amount_expr = amount_expr;
|
||||
if (! total_expr.empty())
|
||||
ledger::total_expr = total_expr;
|
||||
|
||||
// Now setup the various formatting strings
|
||||
|
||||
if (! date_output_format.empty())
|
||||
date_t::output_format = date_output_format;
|
||||
|
||||
amount_t::keep_price = keep_price;
|
||||
amount_t::keep_date = keep_date;
|
||||
amount_t::keep_tag = keep_tag;
|
||||
|
||||
if (! report_period.empty() && ! sort_all)
|
||||
entry_sort = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
xact_handler_ptr
|
||||
report_t::chain_xact_handlers(xact_handler_ptr base_handler,
|
||||
const bool handle_individual_xacts)
|
||||
|
|
@ -139,8 +50,8 @@ report_t::chain_xact_handlers(xact_handler_ptr base_handler,
|
|||
if (head_entries || tail_entries)
|
||||
handler.reset(new truncate_entries(handler, head_entries, tail_entries));
|
||||
|
||||
// filter_xacts will only pass through xacts
|
||||
// matching the `display_predicate'.
|
||||
// filter_xacts will only pass through xacts matching the
|
||||
// `display_predicate'.
|
||||
if (! display_predicate.empty())
|
||||
handler.reset(new filter_xacts(handler, display_predicate));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue