From e95ea133d0953953ba74f4e5c6163706194971cb Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 29 Sep 2003 07:06:02 +0000 Subject: Initial revision --- balance.cc | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 balance.cc (limited to 'balance.cc') diff --git a/balance.cc b/balance.cc new file mode 100644 index 00000000..2c9569a4 --- /dev/null +++ b/balance.cc @@ -0,0 +1,123 @@ +#include +#include + +#include // Perl regular expression library + +#include "ledger.h" + +namespace ledger { + +////////////////////////////////////////////////////////////////////// +// +// Balance report. +// + +void report_balances(std::ostream& out, std::vector& ledger, + bool show_children, bool show_empty) +{ +#if 0 + // Compile the list of specified regular expressions, which can be + // specified on the command line, or using an include/exclude file. + + std::list regexps; + + for (; optind < argc; optind++) { + const char *error; + int erroffset; + pcre * re = pcre_compile(argv[optind], PCRE_CASELESS, + &error, &erroffset, NULL); + assert(re); + regexps.push_back(re); + } +#endif + + // The balance of all accounts must equal zero + totals future_balance; + totals current_balance; + totals cleared_balance; + + std::cout.width(10); + std::cout << std::right << "Future" << " "; + std::cout.width(10); + std::cout << std::right << "Current" << " "; + std::cout.width(10); + std::cout << std::right << "Cleared" << std::endl; + + for (std::map::iterator i = accounts.begin(); + i != accounts.end(); + i++) { + if (! show_empty && ! (*i).second->future) + continue; + + int depth = 0; + account * acct = (*i).second; + while (acct->parent) { + depth++; + acct = acct->parent; + } + +#if 0 + if (! regexps.empty()) { + bool matches = false; + for (std::list::iterator r = regexps.begin(); + r != regexps.end(); + r++) { + int ovector[30]; + if (pcre_exec(*r, NULL, (*i).first.c_str(), (*i).first.length(), + 0, 0, ovector, 30) >= 0) { + matches = true; + break; + } + } + + if (! matches) + continue; + } + else +#endif + if (! show_children && depth) { + continue; + } + + std::cout.width(10); + std::cout << (*i).second->future << " "; + std::cout.width(10); + std::cout << (*i).second->current << " "; + std::cout.width(10); + std::cout << (*i).second->cleared << " "; + + if (depth) { + while (--depth >= 0) + std::cout << " "; + std::cout << (*i).second->name << std::endl; + } else { + std::cout << (*i).first << std::endl; + +#if 0 + if (regexps.empty()) { +#endif + future_balance.credit((*i).second->future); + current_balance.credit((*i).second->current); + cleared_balance.credit((*i).second->cleared); +#if 0 + } +#endif + } + } + +#if 0 + if (regexps.empty()) { +#endif + // jww (2003-09-29): Let `totals' be streamed + future_balance.print(std::cout); + std::cout << " "; + current_balance.print(std::cout); + std::cout << " "; + cleared_balance.print(std::cout); + std::cout << std::endl; +#if 0 + } +#endif +} + +} // namespace ledger -- cgit v1.2.3