diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-12 21:31:55 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-13 01:03:47 -0400 |
commit | 15bf3ed39ed24bc55abc624757a1a943ebabb085 (patch) | |
tree | 5d2cc4212554f22696ae123e9cd7ab195af2ad66 /src/post.cc | |
parent | 9effdb3aa2bfcad9dc391cbe5a15b9f563505b00 (diff) | |
download | fork-ledger-15bf3ed39ed24bc55abc624757a1a943ebabb085.tar.gz fork-ledger-15bf3ed39ed24bc55abc624757a1a943ebabb085.tar.bz2 fork-ledger-15bf3ed39ed24bc55abc624757a1a943ebabb085.zip |
account(NAME) function can lookup account objects
For example, just the word "account" returns the name of the current
posting's account, but account("Expenses:Food") returns the actual
account object, so that it's total may be accessed.
Diffstat (limited to 'src/post.cc')
-rw-r--r-- | src/post.cc | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/post.cc b/src/post.cc index fa8bab4f..dd489cba 100644 --- a/src/post.cc +++ b/src/post.cc @@ -318,7 +318,22 @@ namespace { value_t get_account(call_scope_t& scope) { - return account_name(scope); + interactive_t args(scope, "&v"); + account_t& account(*find_scope<post_t>(scope).account); + if (args.has(0)) { + account_t * acct = account.parent; + for (; acct && acct->parent; acct = acct->parent) ; + if (scope[0].is_string()) + return value_t(static_cast<scope_t *> + (acct->find_account(args.get<string>(0), false))); + else if (scope[0].is_mask()) + return value_t(static_cast<scope_t *> + (acct->find_account_re(args.get<mask_t>(0).str()))); + else + return NULL_VALUE; + } else { + return account_name(scope); + } } value_t get_account_id(post_t& post) { |