summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.cc109
-rw-r--r--config.h4
-rw-r--r--format.cc31
-rw-r--r--format.h3
-rw-r--r--main.cc25
-rw-r--r--valexpr.cc2
6 files changed, 94 insertions, 80 deletions
diff --git a/config.cc b/config.cc
index 7fec3f4d..ecf3d649 100644
--- a/config.cc
+++ b/config.cc
@@ -28,8 +28,8 @@ config_t::config_t()
value_expr = "a";
total_expr = "O";
pricing_leeway = 24 * 3600;
- show_subtotals = true;
- show_expanded = false;
+ show_collapsed = false;
+ show_subtotal = false;
show_related = false;
show_inverted = false;
show_empty = false;
@@ -52,59 +52,62 @@ static void show_version(std::ostream& out)
void option_help(std::ostream& out)
{
out
- << "usage: ledger [options] COMMAND [options] [REGEXPS]\n\n\
+ << "usage: ledger [options] COMMAND [ACCT REGEX]... [-- [PAYEE REGEX]...]\n\n\
Basic options:\n\
-h, --help display this help text\n\
- -v, --version display version information\n\
- -i, --init FILE initialize ledger by loading FILE\n\
- -f, --file FILE specify pathname of ledger data file\n\
- -o, --output FILE write all output to FILE\n\
- -p, --set-price CONV specifies commodity conversion: COMM=AMOUNT\n\n\
+ -v, --version show version information\n\
+ -i, --init FILE initialize ledger by loading FILE (def: ~/.ledgerrc)\n\
+ -f, --file FILE read ledger data from FILE\n\
+ -o, --output FILE write output to FILE\n\
+ -p, --set-price CONV specify a commodity conversion: \"COMM=AMOUNT\"\n\n\
Report filtering:\n\
- -b, --begin-date DATE specify a beginning date\n\
- -e, --end-date DATE specify an ending date\n\
- -c, --current do not show future entries (same as -e TODAY)\n\
- -C, --cleared show only cleared transactions and balances\n\
- -U, --uncleared show only uncleared transactions and balances\n\
- -R, --real do not consider virtual transactions: real only\n\n\
+ -b, --begin-date DATE set report begin date\n\
+ -e, --end-date DATE set report end date\n\
+ -c, --current show only current and past entries (not future)\n\
+ -C, --cleared consider only cleared transactions\n\
+ -U, --uncleared consider only uncleared transactions\n\
+ -R, --real consider only non-virtual transactions\n\n\
+ -r, --related calculate report using related transactions\n\
Output customization:\n\
- -F, --format STR \n\
- -y, --date-format STR \n\
- -E, --empty balance: also show accounts that total to zero\n\
- -n, --collapse balance: no parent account totals; register: collapse\n\
- -s, --show-all balance: show sub-accounts; register: show subtotals\n\
- -S, --sort EXPR sort report according to value EXPR\n\
- -r, --related \n\
- -z, --interval EXPR \n\
- -w, --dow print register using day of week sub-totals\n\
- -W, --weekly \" \" weekly sub-totals\n\
- -M, --monthly \" \" monthly sub-totals\n\
- -Y, --yearly \" \" yearly sub-totals\n\
- -l, --limit EXPR don't calculate entries for which EXPR yields 0\n\
- -d, --display EXPR don't print entries for which EXPR yields 0\n\
- -t, --value EXPR \n\
- -T, --total EXPR \n\
- -j, --value-data \n\
- -J, --total-data \n\n\
+ -F, --format STR use STR as the report format\n\
+ -y, --date-format STR use STR as the date format (def: %Y/%m/%d)\n\
+ -E, --empty balance: show accounts with zero balance\n\
+ -n, --collapse register: collapse entries with multiple transactions\n\
+ -s, --subtotal balance: show sub-accounts; register: show subtotals\n\
+ -S, --sort EXPR sort report according to the value expression EXPR\n\
+ -z, --interval STR report by interval, based on interval expression STR\n\
+ -w, --dow show a days-of-the-week report\n\
+ -W, --weekly show weekly sub-totals\n\
+ -M, --monthly show monthly sub-totals\n\
+ -Y, --yearly show yearly sub-totals\n\
+ -l, --limit EXPR calculate only transactions matching EXPR\n\
+ -d, --display EXPR display only transactions matching EXPR\n\
+ -t, --value EXPR set the value expression for all report types\n\
+ -T, --total EXPR set the total expression for all report types\n\
+ -j, --value-data print only raw value data (useful when scripting)\n\
+ -J, --total-data print only raw total data\n\n\
Commodity reporting:\n\
- -P, --price-db FILE sets the price database\n\
- -L, --price-exp MINS with -Q, fetch quotes only if data is older than MINS\n\
- -Q, --download download price information from the Internet\n\
- (works by running \"getquote SYMBOL\")\n\
- -O, --quantity \n\
- -B, --basis report cost basis of commodities\n\
- -V, --market report the market value of commodities\n\
- -G, --gain \n\
- -A, --average \n\
- -D, --deviation \n\
- -X, --trend \n\
- -Z, --weighted-trend \n\n\
+ -P, --price-db FILE sets the price database to FILE (def: ~/.pricedb)\n\
+ -L, --price-exp MINS download quotes only if newer than MINS (def: 1440)\n\
+ -Q, --download download price information when needed\n\
+ -O, --quantity report commodity totals (this is the default)\n\
+ -B, --basis report commodity cost basis\n\
+ -V, --market report commodity market value\n\
+ -G, --gain report commodity gain/loss\n\
+ -A, --average report average transaction amount\n\
+ -D, --deviation report deviation from the average\n\
+ -X, --trend report average deviation from the average\n\
+ -Z, --weighted-trend same as trend, but older values less significant\n\n\
Commands:\n\
- balance show balance totals\n\
- register display a register for ACCOUNT\n\
- print print all ledger entries\n\
- entry output a newly formed entry, based on arguments\n\
- equity output equity entries for specified accounts\n";
+ balance [REGEXP]... show balance totals for matching accounts\n\
+ register [REGEXP]... show register of matching transactions\n\
+ print [REGEXP]... print all matching entries\n\
+ equity [REGEXP]... output equity entries for matching accounts\n\
+ entry DATE PAYEE AMT output a derived entry, based on the arguments\n\n\
+For commands that accepts a list of regular expressions, these match against\n\
+the account. If the separator \"--\" is specified, regexps after it are\n\
+matched against the payee name. For even more sophisticated entry matching,\n\
+use --limit; to affect display only (not calculation), use --display.\n";
}
//////////////////////////////////////////////////////////////////////
@@ -214,12 +217,12 @@ OPT_BEGIN(empty, "E") {
} OPT_END(empty);
OPT_BEGIN(collapse, "n") {
- config->show_subtotals = false;
+ config->show_collapsed = true;
} OPT_END(collapse);
-OPT_BEGIN(show_all, "s") {
- config->show_expanded = true;
-} OPT_END(show_all);
+OPT_BEGIN(subtotal, "s") {
+ config->show_subtotal = true;
+} OPT_END(subtotal);
OPT_BEGIN(sort, "S:") {
config->sort_string = optarg;
diff --git a/config.h b/config.h
index a5319059..8aa9eca0 100644
--- a/config.h
+++ b/config.h
@@ -32,8 +32,8 @@ struct config_t
std::string value_expr;
std::string total_expr;
unsigned long pricing_leeway;
- bool show_subtotals;
- bool show_expanded;
+ bool show_collapsed;
+ bool show_subtotal;
bool show_related;
bool show_inverted;
bool show_empty;
diff --git a/format.cc b/format.cc
index d917877c..42d5a082 100644
--- a/format.cc
+++ b/format.cc
@@ -347,24 +347,30 @@ bool format_account::disp_subaccounts_p(const account_t * account,
disp_pred,
const account_t *& to_show)
{
- bool display = false;
- unsigned int counted = 0;
+ bool display = false;
+ unsigned int counted = 0;
+ bool computed = false;
+ bool matches = disp_pred(account);
+ balance_t acct_total;
to_show = NULL;
for (accounts_map::const_iterator i = account->accounts.begin();
i != account->accounts.end();
i++) {
- // jww (2004-08-03): How to compute the right figure? It should
- // be a value expression specified by the user which says, "If
- // this expression is equivalent between a parent account and a
- // lone displayed child, don't display the parent."
-
- if (! (*i).second->total || ! disp_pred((*i).second))
+ if (! disp_pred((*i).second))
continue;
- if ((*i).second->total != account->total || counted > 0) {
- display = true;
+ balance_t result;
+ format_t::compute_total(result, details_t((*i).second));
+
+ if (! computed) {
+ format_t::compute_total(acct_total, details_t(account));
+ computed = true;
+ }
+
+ if ((result != acct_total) || counted > 0) {
+ display = matches;
break;
}
to_show = (*i).second;
@@ -375,11 +381,12 @@ bool format_account::disp_subaccounts_p(const account_t * account,
}
bool format_account::display_account(const account_t * account,
- const item_predicate<account_t>& disp_pred)
+ const item_predicate<account_t>& disp_pred,
+ const bool even_top)
{
// Never display the master account, or an account that has already
// been displayed.
- if (! account->parent || account->dflags & ACCOUNT_DISPLAYED)
+ if (! (account->parent || even_top) || account->dflags & ACCOUNT_DISPLAYED)
return false;
// At this point, one of two possibilities exists: the account is a
diff --git a/format.h b/format.h
index 00b61282..ba488f68 100644
--- a/format.h
+++ b/format.h
@@ -161,7 +161,8 @@ class format_account : public item_handler<account_t>
}
static bool display_account(const account_t * account,
- const item_predicate<account_t>& disp_pred);
+ const item_predicate<account_t>& disp_pred,
+ const bool even_top = false);
virtual void flush() {
output_stream.flush();
diff --git a/main.cc b/main.cc
index 82a739c8..ba18a2ff 100644
--- a/main.cc
+++ b/main.cc
@@ -159,7 +159,7 @@ int main(int argc, char * argv[], char * envp[])
process_environment(envp, "LEDGER_");
#if 1
- // These are here until 3.x, for backwards compatability.
+ // These are here for backwards compatability, but are deprecated.
if (const char * p = std::getenv("LEDGER"))
process_option("file", p);
@@ -272,7 +272,7 @@ int main(int argc, char * argv[], char * envp[])
break;
regexps_to_predicate(arg, i, config, true,
- command == "b" && ! config->show_expanded &&
+ command == "b" && ! config->show_subtotal &&
config->display_predicate.empty());
if (i != args.end())
regexps_to_predicate(i, args.end(), config);
@@ -284,7 +284,7 @@ int main(int argc, char * argv[], char * envp[])
if (command == "b") {
if (! config->show_empty)
config->display_predicate = "T";
- if (! config->show_expanded) {
+ if (! config->show_subtotal) {
if (! config->display_predicate.empty())
config->display_predicate += "&";
config->display_predicate += "!l";
@@ -352,11 +352,12 @@ int main(int argc, char * argv[], char * envp[])
bool show_all_related = false;
if (command == "p" || command == "e") {
- config->show_related = show_all_related = true;
- config->show_expanded = true;
+ config->show_related =
+ show_all_related =
+ config->show_subtotal = true;
}
else if (command == "E") {
- config->show_expanded = true;
+ config->show_subtotal = true;
}
else if (config->show_related) {
if (command == "r")
@@ -469,12 +470,14 @@ int main(int argc, char * argv[], char * envp[])
formatter->flush();
format_account acct_formatter(OUT(), format, config->display_predicate);
- if (config->show_subtotals)
- sum_accounts(journal->master);
+ sum_accounts(journal->master);
walk_accounts(journal->master, acct_formatter, sort_order.get());
acct_formatter.flush();
- if (format_account::disp_subaccounts_p(journal->master)) {
+ journal->master->value = journal->master->total;
+ if (format_account::display_account(journal->master,
+ item_predicate<account_t>("T"),
+ true)) {
std::string end_format = "--------------------\n";
format.reset(end_format + f);
format.format_elements(OUT(), details_t(journal->master));
@@ -537,7 +540,7 @@ int main(int argc, char * argv[], char * envp[])
// collapse_transactions causes entries with multiple transactions
// to appear as entries with a subtotaled transaction for each
// commodity used.
- if (! config->show_subtotals)
+ if (config->show_collapsed)
formatter.reset(new collapse_transactions(formatter.release()));
// subtotal_transactions combines all the transactions it receives
@@ -551,7 +554,7 @@ int main(int argc, char * argv[], char * envp[])
// dow_transactions is like interval_transactions, except that it
// reports all the transactions that fall on each subsequent day
// of the week.
- if (config->show_expanded)
+ if (config->show_subtotal)
formatter.reset(new subtotal_transactions(formatter.release()));
else if (report_interval.get())
formatter.reset(new interval_transactions(formatter.release(),
diff --git a/valexpr.cc b/valexpr.cc
index 7c97451f..13e7e6a4 100644
--- a/valexpr.cc
+++ b/valexpr.cc
@@ -227,7 +227,7 @@ void value_expr_t::compute(value_t& result, const details_t& details,
assert(left);
left->compute(result, details);
if (result.type == value_t::BALANCE) {
- // jww (2004-08-17): do something smarter here
+ // jww (2004-08-17): do something smarter here?
result.cast(value_t::AMOUNT);
}
if (result.type == value_t::AMOUNT) {