*** empty log message ***
This commit is contained in:
parent
9d5172792a
commit
68e6b8538e
3 changed files with 54 additions and 41 deletions
83
balance.cc
83
balance.cc
|
|
@ -16,48 +16,55 @@ static bool show_empty;
|
||||||
static bool no_subtotals;
|
static bool no_subtotals;
|
||||||
static bool full_names;
|
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,
|
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::map<account *, totals *>& balances,
|
||||||
const std::list<mask>& regexps)
|
const std::list<mask>& regexps)
|
||||||
{
|
{
|
||||||
|
bool displayed = false;
|
||||||
|
|
||||||
std::map<account *, totals *>::const_iterator b =
|
std::map<account *, totals *>::const_iterator b =
|
||||||
balances.find(const_cast<account *>(acct));
|
balances.find(const_cast<account *>(acct));
|
||||||
if (b != balances.end()) {
|
if (b != balances.end()) {
|
||||||
totals * balance = (*b).second;
|
totals * balance = (*b).second;
|
||||||
|
|
||||||
if (balance && (show_empty || *balance)) {
|
if (balance && (show_empty || *balance)) {
|
||||||
bool match = true;
|
displayed = 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;
|
||||||
out << *balance;
|
if (top_level)
|
||||||
|
total_balance.credit(*balance);
|
||||||
|
|
||||||
if (! acct->parent || true_match)
|
if (acct->parent && ! no_subtotals && ! full_names) {
|
||||||
total_balance.credit(*balance);
|
for (const account * a = acct; a; a = a->parent)
|
||||||
|
out << " ";
|
||||||
if (acct->parent && ! no_subtotals && ! full_names) {
|
out << acct->name << std::endl;
|
||||||
for (const account * a = acct; a; a = a->parent)
|
} else {
|
||||||
out << " ";
|
out << " " << *acct << std::endl;
|
||||||
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();
|
for (account::const_iterator i = acct->children.begin();
|
||||||
i != acct->children.end();
|
i != acct->children.end();
|
||||||
i++)
|
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;
|
account * acct = (*x)->acct;
|
||||||
|
|
||||||
for (; acct; acct = no_subtotals ? NULL : acct->parent) {
|
for (; acct; acct = no_subtotals ? NULL : acct->parent) {
|
||||||
if (! show_children && acct->parent &&
|
bool true_match = false;
|
||||||
(regexps.empty() || ! matches(regexps, acct->name)))
|
if (! (regexps.empty() ||
|
||||||
|
account_matches(acct, regexps, &true_match)))
|
||||||
|
break;
|
||||||
|
else if (! (true_match || show_children || ! acct->parent))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
totals * balance = NULL;
|
totals * balance = NULL;
|
||||||
|
|
@ -140,14 +151,12 @@ void report_balances(int argc, char **argv, std::ostream& out)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool do_credit = true;
|
bool do_credit = true;
|
||||||
|
|
||||||
if (have_beginning && difftime((*i)->date, begin_date) < 0)
|
if (have_beginning && difftime((*i)->date, begin_date) < 0)
|
||||||
do_credit = false;
|
do_credit = false;
|
||||||
else if (have_ending && difftime((*i)->date, end_date) > 0)
|
else if (have_ending && difftime((*i)->date, end_date) > 0)
|
||||||
do_credit = false;
|
do_credit = false;
|
||||||
else if (show_cleared && ! (*i)->cleared)
|
else if (show_cleared && ! (*i)->cleared)
|
||||||
do_credit = false;
|
do_credit = false;
|
||||||
|
|
||||||
if (! do_credit)
|
if (! do_credit)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
@ -164,7 +173,7 @@ void report_balances(int argc, char **argv, std::ostream& out)
|
||||||
for (accounts_iterator i = main_ledger.accounts.begin();
|
for (accounts_iterator i = main_ledger.accounts.begin();
|
||||||
i != main_ledger.accounts.end();
|
i != main_ledger.accounts.end();
|
||||||
i++)
|
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
|
// Print the total of all the balances shown
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,8 @@ void read_regexps(const char * path, std::list<mask>& regexps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matches(const std::list<mask>& regexps, const std::string& str)
|
bool matches(const std::list<mask>& regexps, const std::string& str,
|
||||||
|
bool * exclude)
|
||||||
{
|
{
|
||||||
// If the first pattern is an exclude, we assume all patterns match
|
// If the first pattern is an exclude, we assume all patterns match
|
||||||
// if they don't match the exclude. If the first pattern is an
|
// if they don't match the exclude. If the first pattern is an
|
||||||
|
|
@ -225,8 +226,11 @@ bool matches(const std::list<mask>& regexps, const std::string& str)
|
||||||
r++) {
|
r++) {
|
||||||
int ovec[3];
|
int ovec[3];
|
||||||
if (pcre_exec((*r).regexp, NULL, str.c_str(), str.length(),
|
if (pcre_exec((*r).regexp, NULL, str.c_str(), str.length(),
|
||||||
0, 0, ovec, 3) >= 0)
|
0, 0, ovec, 3) >= 0) {
|
||||||
|
if (exclude)
|
||||||
|
*exclude = (*r).exclude;
|
||||||
match = ! (*r).exclude;
|
match = ! (*r).exclude;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
|
|
|
||||||
4
ledger.h
4
ledger.h
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _LEDGER_H
|
#ifndef _LEDGER_H
|
||||||
#define _LEDGER_H "$Revision: 1.10 $"
|
#define _LEDGER_H "$Revision: 1.11 $"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
|
@ -159,7 +159,7 @@ extern std::list<mask> regexps;
|
||||||
extern void record_regexp(char * pattern, std::list<mask>& regexps);
|
extern void record_regexp(char * pattern, std::list<mask>& regexps);
|
||||||
extern void read_regexps(const char * path, std::list<mask>& regexps);
|
extern void read_regexps(const char * path, std::list<mask>& regexps);
|
||||||
extern bool matches(const std::list<mask>& regexps,
|
extern bool matches(const std::list<mask>& regexps,
|
||||||
const std::string& str);
|
const std::string& str, bool * exclude = NULL);
|
||||||
|
|
||||||
|
|
||||||
struct account;
|
struct account;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue