From 15bf3ed39ed24bc55abc624757a1a943ebabb085 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 12 Jun 2010 21:31:55 -0400 Subject: 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. --- src/post.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/post.cc') 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(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 + (acct->find_account(args.get(0), false))); + else if (scope[0].is_mask()) + return value_t(static_cast + (acct->find_account_re(args.get(0).str()))); + else + return NULL_VALUE; + } else { + return account_name(scope); + } } value_t get_account_id(post_t& post) { -- cgit v1.2.3