1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#include <iostream>
#include <vector>
#include <pcre.h> // Perl regular expression library
#include "ledger.h"
namespace ledger {
//////////////////////////////////////////////////////////////////////
//
// Balance report.
//
void report_balances(std::ostream& out, std::vector<entry *>& 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<pcre *> 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 (accounts_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<pcre *>::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
std::cout.width(10);
std::cout << std::right << future_balance << " ";
std::cout.width(10);
std::cout << std::right << current_balance << " ";
std::cout.width(10);
std::cout << std::right << cleared_balance << std::endl;
#if 0
}
#endif
}
} // namespace ledger
|