From a881f713c113b114cc01a6452729bb5cc31fbe3c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 10 Mar 2007 22:29:09 +0000 Subject: [PATCH] balance: support -s with account patterns --- Account.hs | 5 ++++- AccountName.hs | 9 +++++---- TODO | 1 - 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Account.hs b/Account.hs index 84363de6f..1a218d608 100644 --- a/Account.hs +++ b/Account.hs @@ -19,6 +19,9 @@ data Account = Account { abalance :: Amount } +instance Show Account where + show (Account a ts b) = printf "Account %s with %d transactions" a $ length ts + nullacct = Account "" [] nullamt mkAccount :: Ledger -> AccountName -> Account @@ -108,7 +111,7 @@ ledgerAccountTreeMatching l showsubs [] = ledgerAccountTreeMatching l showsubs [".*"] ledgerAccountTreeMatching l showsubs acctpats = addDataToAccountNameTree l $ - filterAccountNameTree acctpats $ + filterAccountNameTree acctpats showsubs $ ledgerAccountNameTree l showLedgerAccounts :: Ledger -> Bool -> [String] -> String diff --git a/AccountName.hs b/AccountName.hs index 0527d7779..c621808d8 100644 --- a/AccountName.hs +++ b/AccountName.hs @@ -82,10 +82,11 @@ showAccountNameTree t = where topacct = indentAccountName 0 $ root t -filterAccountNameTree :: [String] -> Tree AccountName -> Tree AccountName -filterAccountNameTree pats = - treefilter matchany +filterAccountNameTree :: [String] -> Bool -> Tree AccountName -> Tree AccountName +filterAccountNameTree pats keepsubs = + treefilter $ \a -> matchpats a || (keepsubs && issubofmatch a) where - matchany a = any (match a) pats + matchpats a = any (match a) pats match a pat = matchAccountName pat $ accountLeafName a + issubofmatch a = any matchpats $ parentAccountNames a diff --git a/TODO b/TODO index 74ea48b87..1c569e607 100644 --- a/TODO +++ b/TODO @@ -75,7 +75,6 @@ algorithm: 2 add subaccounts if -s 3 display account tree, eliding boring accounts -include subaccounts elide boring accounts