diff options
author | John Wiegley <johnw@newartisans.com> | 2003-10-01 05:39:06 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2003-10-01 05:39:06 +0000 |
commit | 68e6b8538e9c6fd39cb5d6ff80c65f3181763413 (patch) | |
tree | 50e4e14056459b22d0f923b0ab409f080157b694 /balance.cc | |
parent | 9d5172792af05321a05e63b186f477c2af93b2ea (diff) | |
download | fork-ledger-68e6b8538e9c6fd39cb5d6ff80c65f3181763413.tar.gz fork-ledger-68e6b8538e9c6fd39cb5d6ff80c65f3181763413.tar.bz2 fork-ledger-68e6b8538e9c6fd39cb5d6ff80c65f3181763413.zip |
*** empty log message ***
Diffstat (limited to 'balance.cc')
-rw-r--r-- | balance.cc | 87 |
1 files changed, 48 insertions, 39 deletions
@@ -16,48 +16,55 @@ static bool show_empty; static bool no_subtotals; static bool full_names; +static bool account_matches(const account * acct, + const std::list<mask>& regexps, + bool * true_match) +{ + bool match = true; + + if (show_children) { + match = false; + for (const account * a = acct; a; a = a->parent) { + bool exclude = false; + if (matches(regexps, a->name, &exclude)) { + match = true; + *true_match = a == acct; + break; + } + if (exclude) + break; + } + } else { + match = matches(regexps, acct->as_str()); + *true_match = matches(regexps, acct->name); + } + return match; +} + static void display_total(std::ostream& out, totals& total_balance, - const account * acct, + const account * acct, bool top_level, const std::map<account *, totals *>& balances, const std::list<mask>& regexps) { + bool displayed = false; + std::map<account *, totals *>::const_iterator b = balances.find(const_cast<account *>(acct)); if (b != balances.end()) { totals * balance = (*b).second; - if (balance && (show_empty || *balance)) { - bool match = true; - bool true_match = false; - if (! regexps.empty()) { - if (show_children) { - match = false; - for (const account * a = acct; a; a = a->parent) { - if (matches(regexps, a->name)) { - match = true; - true_match = a == acct; - break; - } - } - } else { - match = matches(regexps, acct->as_str()); - true_match = matches(regexps, acct->name); - } - } - - if (match) { - out << *balance; - - if (! acct->parent || true_match) - total_balance.credit(*balance); - - if (acct->parent && ! no_subtotals && ! full_names) { - for (const account * a = acct; a; a = a->parent) - out << " "; - out << acct->name << std::endl; - } else { - out << " " << *acct << std::endl; - } + displayed = true; + + out << *balance; + if (top_level) + total_balance.credit(*balance); + + if (acct->parent && ! no_subtotals && ! full_names) { + for (const account * a = acct; a; a = a->parent) + out << " "; + out << acct->name << std::endl; + } else { + out << " " << *acct << std::endl; } } } @@ -67,7 +74,8 @@ static void display_total(std::ostream& out, totals& total_balance, for (account::const_iterator i = acct->children.begin(); i != acct->children.end(); i++) - display_total(out, total_balance, (*i).second, balances, regexps); + display_total(out, total_balance, (*i).second, ! displayed, + balances, regexps); } ////////////////////////////////////////////////////////////////////// @@ -125,8 +133,11 @@ void report_balances(int argc, char **argv, std::ostream& out) account * acct = (*x)->acct; for (; acct; acct = no_subtotals ? NULL : acct->parent) { - if (! show_children && acct->parent && - (regexps.empty() || ! matches(regexps, acct->name))) + bool true_match = false; + if (! (regexps.empty() || + account_matches(acct, regexps, &true_match))) + break; + else if (! (true_match || show_children || ! acct->parent)) continue; totals * balance = NULL; @@ -140,14 +151,12 @@ void report_balances(int argc, char **argv, std::ostream& out) } bool do_credit = true; - if (have_beginning && difftime((*i)->date, begin_date) < 0) do_credit = false; else if (have_ending && difftime((*i)->date, end_date) > 0) do_credit = false; else if (show_cleared && ! (*i)->cleared) do_credit = false; - if (! do_credit) continue; @@ -164,7 +173,7 @@ void report_balances(int argc, char **argv, std::ostream& out) for (accounts_iterator i = main_ledger.accounts.begin(); i != main_ledger.accounts.end(); i++) - display_total(out, total_balance, (*i).second, balances, regexps); + display_total(out, total_balance, (*i).second, true, balances, regexps); // Print the total of all the balances shown |