summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Feigl <craven@gmx.net>2014-02-26 09:29:31 +0100
committerPeter Feigl <craven@gmx.net>2014-02-26 09:29:31 +0100
commit75b0a5d8ff22abeac8c4f502154159f998ffbe99 (patch)
tree0e8ec4c444700fd996eefead32455ec7086bff08
parent230fa31ba3087884c0701e9a4fe1c44a184e6f27 (diff)
downloadfork-ledger-75b0a5d8ff22abeac8c4f502154159f998ffbe99.tar.gz
fork-ledger-75b0a5d8ff22abeac8c4f502154159f998ffbe99.tar.bz2
fork-ledger-75b0a5d8ff22abeac8c4f502154159f998ffbe99.zip
Adding option --recursive-aliases, adding documentation to man-page and manual
-rw-r--r--doc/ledger.13
-rw-r--r--doc/ledger3.texi10
-rw-r--r--src/journal.cc5
-rw-r--r--src/journal.h1
-rw-r--r--src/session.cc6
-rw-r--r--src/session.h2
-rw-r--r--test/baseline/dir-alias-recursive.test12
-rw-r--r--test/baseline/dir-alias.test34
8 files changed, 43 insertions, 30 deletions
diff --git a/doc/ledger.1 b/doc/ledger.1
index 659d3fbb..ecd97ecc 100644
--- a/doc/ledger.1
+++ b/doc/ledger.1
@@ -420,6 +420,9 @@ For use only with the
command, it causes Ledger to print out matching entries exactly as they
appeared in the original journal file.
.It Fl \-real Pq Fl R
+.It Fl \-recursive-aliases
+Causes ledger to try to expand aliases recursively, i.e. try to expand
+the result of an earlier expansion again, until no more expansions apply.
.It Fl \-register-format Ar FMT
.It Fl \-related Pq Fl r
.It Fl \-related-all
diff --git a/doc/ledger3.texi b/doc/ledger3.texi
index 051c7c76..1a8fd9aa 100644
--- a/doc/ledger3.texi
+++ b/doc/ledger3.texi
@@ -2161,8 +2161,9 @@ The aliases are only in effect for transactions read in after the alias
is defined and are affected by @code{account} directives that precede
them.
-Aliases can refer to other aliases, the following example produces exactly
-the same accounts as the preceding one:
+With the option @option{--recursive-aliases}, aliases can refer to other aliases,
+the following example produces exactly the same transactions and account names
+as the preceding one:
@smallexample
alias Entertainment=Expenses:Entertainment
@@ -5814,6 +5815,11 @@ correct, and if it finds a new account or commodity (same as
a misspelled commodity or account) it will issue a warning giving you
the file and line number of the problem.
+@item --recursive-aliases
+Normally, ledger only expands aliases once. With this option, ledger tries
+to expand the result of alias expansion recursively, until no more expansions
+apply.
+
@item --time-colon
The @option{--time-colon} option will display the value for a seconds
based commodity as real hours and minutes.
diff --git a/src/journal.cc b/src/journal.cc
index 8406da91..007acd7b 100644
--- a/src/journal.cc
+++ b/src/journal.cc
@@ -96,6 +96,7 @@ void journal_t::initialize()
check_payees = false;
day_break = false;
checking_style = CHECK_PERMISSIVE;
+ recursive_aliases = false;
}
void journal_t::add_account(account_t * acct)
@@ -175,7 +176,7 @@ account_t * journal_t::expand_aliases(string name) {
bool keep_expanding = true;
std::list<string> already_seen;
// loop until no expansion can be found
- while(keep_expanding) {
+ do {
if (account_aliases.size() > 0) {
accounts_map::const_iterator i = account_aliases.find(name);
if (i != account_aliases.end()) {
@@ -214,7 +215,7 @@ account_t * journal_t::expand_aliases(string name) {
} else {
keep_expanding = false;
}
- }
+ } while(keep_expanding && recursive_aliases);
return result;
}
diff --git a/src/journal.h b/src/journal.h
index 3c363962..270a2912 100644
--- a/src/journal.h
+++ b/src/journal.h
@@ -131,6 +131,7 @@ public:
bool force_checking;
bool check_payees;
bool day_break;
+ bool recursive_aliases;
payee_mappings_t payee_mappings;
account_mappings_t account_mappings;
accounts_map account_aliases;
diff --git a/src/session.cc b/src/session.cc
index dbd49a0e..99467a43 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -113,6 +113,9 @@ std::size_t session_t::read_data(const string& master_account)
if (HANDLED(day_break))
journal->day_break = true;
+ if (HANDLED(recursive_aliases))
+ journal->recursive_aliases = true;
+
if (HANDLED(permissive))
journal->checking_style = journal_t::CHECK_PERMISSIVE;
else if (HANDLED(pedantic))
@@ -350,6 +353,9 @@ option_t<session_t> * session_t::lookup_option(const char * p)
else OPT(pedantic);
else OPT(permissive);
break;
+ case 'r':
+ OPT(recursive_aliases);
+ break;
case 's':
OPT(strict);
break;
diff --git a/src/session.h b/src/session.h
index 3572b991..c2345362 100644
--- a/src/session.h
+++ b/src/session.h
@@ -109,6 +109,7 @@ public:
HANDLER(permissive).report(out);
HANDLER(price_db_).report(out);
HANDLER(price_exp_).report(out);
+ HANDLER(recursive_aliases).report(out);
HANDLER(strict).report(out);
HANDLER(value_expr_).report(out);
}
@@ -164,6 +165,7 @@ public:
OPTION(session_t, price_db_);
OPTION(session_t, strict);
OPTION(session_t, value_expr_);
+ OPTION(session_t, recursive_aliases);
};
/**
diff --git a/test/baseline/dir-alias-recursive.test b/test/baseline/dir-alias-recursive.test
new file mode 100644
index 00000000..d9addcd1
--- /dev/null
+++ b/test/baseline/dir-alias-recursive.test
@@ -0,0 +1,12 @@
+alias A=B:A
+alias B=C:B
+alias C=D:C
+
+2001-01-01 Test
+ A 10 EUR
+ Foo
+
+test reg --recursive-aliases
+01-Jan-01 Test D:C:B:A 10 EUR 10 EUR
+ Foo -10 EUR 0
+end test
diff --git a/test/baseline/dir-alias.test b/test/baseline/dir-alias.test
index ee363052..6245d944 100644
--- a/test/baseline/dir-alias.test
+++ b/test/baseline/dir-alias.test
@@ -1,31 +1,13 @@
-alias Cash=Assets:Cash
-alias fast-food=food:FastFood
-alias food=Expenses:Food
+alias A=B:A
+alias B=C:B
+alias C=D:C
-2012-02-27 KFC
- fast-food $20.00
- Assets:Cash
-
-2012-02-28 KFC
- fast-food $20.00
- Assets:Cash
-
-2012-02-29 KFC
- fast-food $25.00
- Assets:Cash
-
-2012-02-29 KFC
- fast-food $25.00
- Assets:Cash
+2001-01-01 Test
+ A 10 EUR
+ Foo
test reg
-12-Feb-27 KFC Expenses:Food:FastFood $20.00 $20.00
- Assets:Cash $-20.00 0
-12-Feb-28 KFC Expenses:Food:FastFood $20.00 $20.00
- Assets:Cash $-20.00 0
-12-Feb-29 KFC Expenses:Food:FastFood $25.00 $25.00
- Assets:Cash $-25.00 0
-12-Feb-29 KFC Expenses:Food:FastFood $25.00 $25.00
- Assets:Cash $-25.00 0
+01-Jan-01 Test B:A 10 EUR 10 EUR
+ Foo -10 EUR 0
end test