diff --git a/Ledger/Ledger.hs b/Ledger/Ledger.hs index 6e8be2367..275b67ebd 100644 --- a/Ledger/Ledger.hs +++ b/Ledger/Ledger.hs @@ -70,10 +70,9 @@ cacheLedger l pats = in Ledger l'' ant amap lprecision --- | keep only entries whose description matches one of the --- description patterns, if any, and which have at least one --- transaction matching one of the account patterns, if any. --- No description or account patterns implies match all. +-- | keep only entries whose description matches one of the description +-- patterns, and which have at least one transaction matching one of the +-- account patterns. (One or both patterns may be the wildcard.) filterLedgerEntries :: (Regex,Regex) -> RawLedger -> RawLedger filterLedgerEntries (acctpat,descpat) (RawLedger ms ps es f) = RawLedger ms ps filteredentries f @@ -89,9 +88,8 @@ filterLedgerEntries (acctpat,descpat) (RawLedger ms ps es f) = Nothing -> False otherwise -> True --- | in each ledger entry, filter out transactions which do not match --- the account patterns, if any. (Entries are no longer balanced --- after this.) +-- | in each ledger entry, filter out transactions which do not match the +-- account patterns. (Entries are no longer balanced after this.) filterLedgerTransactions :: (Regex,Regex) -> RawLedger -> RawLedger filterLedgerTransactions (acctpat,descpat) (RawLedger ms ps es f) = RawLedger ms ps (map filterentrytxns es) f @@ -219,6 +217,7 @@ showLedgerAccounts l maxdepth = concatMap (showAccountTree l) (branches $ ledgerAccountTree l maxdepth) +-- XXX need to add up and show balances too showAccountTree :: Ledger -> Tree Account -> String showAccountTree l = showAccountTree' l 0 . pruneBoringBranches diff --git a/Options.hs b/Options.hs index cce88ee44..3542ce1b9 100644 --- a/Options.hs +++ b/Options.hs @@ -1,4 +1,4 @@ -module Options (parseOptions, parsePatternArgs, wildcard, Flag(..), usage, ledgerFilePath) +module Options (parseOptions, parsePatternArgs, nullpats, wildcard, Flag(..), usage, ledgerFilePath) where import System.Console.GetOpt import System.Directory @@ -92,3 +92,4 @@ regexFor ss = mkRegex $ "(" ++ (unwords $ intersperse "|" ss) ++ ")" wildcard :: Regex wildcard = mkRegex ".*" +nullpats = (wildcard,wildcard) diff --git a/Tests.hs b/Tests.hs index 349e68c8a..9e95b1a51 100644 --- a/Tests.hs +++ b/Tests.hs @@ -284,7 +284,7 @@ ledger7 = RawLedger ] "" -l7 = cacheLedger ledger7 (wildcard,wildcard) +l7 = cacheLedger ledger7 nullpats timelogentry1_str = "i 2007/03/11 16:19:00 hledger\n" timelogentry1 = TimeLogEntry 'i' "2007/03/11 16:19:00" "hledger" @@ -375,7 +375,7 @@ test_ledgerAccountNames = (rawLedgerAccountNames ledger7) test_cacheLedger = - assertEqual' 15 (length $ Map.keys $ accounts $ cacheLedger ledger7 (wildcard,wildcard)) + assertEqual' 15 (length $ Map.keys $ accounts $ cacheLedger ledger7 nullpats) test_showLedgerAccounts = assertEqual' 4 (length $ lines $ showLedgerAccounts l7 1) diff --git a/hledger.hs b/hledger.hs index 757ffeafc..a7c01fbdc 100644 --- a/hledger.hs +++ b/hledger.hs @@ -77,9 +77,9 @@ balance opts pats = parseLedgerAndDo opts pats printbalance where showsubs = (ShowSubs `elem` opts) depth = case (pats, showsubs) of - -- when there are no account patterns and no -s, show + -- when there are no filter patterns and no -s, show -- only to depth 1. (This was clearer when we used maybe.) - ((wildcard,_), False) -> 1 + (nullpats, False) -> 1 otherwise -> 9999 -- | parse the user's specified ledger file and do some action with it @@ -104,7 +104,7 @@ rawledger = do ledger :: IO Ledger ledger = do l <- rawledger - return $ cacheLedger l (wildcard,wildcard) + return $ cacheLedger l nullpats -- | get a Ledger from the given file path rawledgerfromfile :: String -> IO RawLedger