diff --git a/Makefile b/Makefile index e75e7cebf..496ec5929 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ test: @./hledger.hs test @./regtest.py -haddock: +docs haddock: haddock -h -o doc *.hs overview: diff --git a/data/test.dat b/data/test.dat new file mode 100644 index 000000000..d7bc00abc --- /dev/null +++ b/data/test.dat @@ -0,0 +1,54 @@ +; test ledger +; set up this account tree: +; +; assets +; cash +; checking +; saving +; equity +; expenses +; food +; shelter +; income +; salary +; liabilities +; debts + +2007/01/01 * save + assets:saving $1000 + equity + +2007/01/01 * eat + assets:cash + expenses:food $1 + +2007/01/01 * hide + expenses:shelter $1 + assets:cash + +2007/01/20 * test + expenses:food $1 + assets:cash:petty + +2007/01/21 * atm + assets:cash $40.00 + expenses:banking $2.00 + expenses:banking $2.00 + assets:checking $-44.00 + +2007/01/22 * test xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx + assets:checking $10 ; xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx + expenses:food xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx $1234567890 + income:salary + +; 2007/01/23 * test +; assets:fruit APPLES1 +; assets:cash + +2007/01/24 * test + liabilities:debts $1. + assets:checking + +2007/01/25 * test + liabilities:debts $2.00 + assets:checking ;test 3 diff --git a/data/test1.dat b/data/test1.dat new file mode 100644 index 000000000..3c13249ae --- /dev/null +++ b/data/test1.dat @@ -0,0 +1,8 @@ +2007/01/21 * test + expenses:shelter $1 + assets:cash + +2007/01/22 * test xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx + assets:checking $10 ; xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx + expenses:food xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx $1234567890 + income:salary diff --git a/data/test2.dat b/data/test2.dat new file mode 100644 index 000000000..fb228295c --- /dev/null +++ b/data/test2.dat @@ -0,0 +1,6 @@ +2007/01/01 * atm + assets:cash $40.00 + expenses:banking $2.00 + expenses:banking $2.00 + assets:checking + diff --git a/tools/listbydeps.hs b/tools/listbydeps.hs new file mode 100644 index 000000000..62642b9e2 --- /dev/null +++ b/tools/listbydeps.hs @@ -0,0 +1,60 @@ +#!/usr/bin/env runhaskell + +import System +import System.Directory +import IO +import Data.List +import Data.Char +import Data.Maybe +import Data.Ord + +{- + Read a Haskell *.hs file and get a list of all the modules + that it imports. +-} +findDeps base pkg = do + let hi = base ++ (map dotToSlash pkg) ++ ".hs" + ex <- doesFileExist hi + if not ex then return [] else do + src <- readFile hi + let imps = filter isImport (lines src) + return $ catMaybes $ map getTargetModule imps + + where dotToSlash '.' = '/' + dotToSlash x = x + + isImport (' ':t) = isImport t + isImport ('\t':t) = isImport t + isImport t = "import" `isPrefixOf` t + + getTargetModule s = let pre = takeWhile (/= '(') s in + find (isUpper . head) (words pre) + +{- + Find the transitive, reflexive closure of the relation defined + by the findDeps function. This returns a list of ALL modules + that this one uses or depends on, directly or indirectly. +-} +allDeps base mod = allDeps' [mod] [mod] where + allDeps' (m:ms) full = do d <- findDeps base m + let d' = filter (not . flip elem full) d + t <- allDeps' (d' ++ ms) (d' ++ full) + return (m : t) + allDeps' [] _ = return [] + +{- + Usage: OrderByComplexity + + = directory where source code is found. This MUST + end in '/' + = file that lists the modules you're interested in, + one per line. This is often taken from a .cabal +-} +main = do [ base, pkgFile ] <- getArgs + pkgStr <- readFile pkgFile + let pkgs = lines pkgStr + mods <- mapM (allDeps base) pkgs + let deps = zip pkgs mods + let deps' = sortBy (comparing fst) deps + mapM_ print $ map fst $ sortBy (comparing $ length . snd) deps' + diff --git a/overview.hs b/tools/overview.hs similarity index 98% rename from overview.hs rename to tools/overview.hs index 19884688d..8bd7a4874 100644 --- a/overview.hs +++ b/tools/overview.hs @@ -1,6 +1,7 @@ #!/usr/bin/env runhaskell {- overview.hs - print an overview of functions from a given list of modules +Simon Michael 2007 Usage: ./overview.hs somefile diff --git a/regtest.py b/tools/regressiontest.py similarity index 90% rename from regtest.py rename to tools/regressiontest.py index 7f8e30ce9..05eea5138 100644 --- a/regtest.py +++ b/tools/regressiontest.py @@ -1,12 +1,13 @@ #!/usr/bin/python # test whether hledger output matches ledger's +# Simon Michael 2007 from os import * from posix import * files = [ - 'test.dat', - 'test1.dat', + 'data/test.dat', + 'data/test1.dat', # getenv('LEDGER'), ] diff --git a/tools/simplifyprof.hs b/tools/simplifyprof.hs new file mode 100644 index 000000000..c3c0aba8d --- /dev/null +++ b/tools/simplifyprof.hs @@ -0,0 +1,14 @@ +#!/usr/bin/env runhaskell +-- filters uninteresting fields from profile data lines +-- Simon Michael 2007 +import Data.List +main = interact $ unlines . map print . filter (/=[]) . + (["cost-centre - - entries %time %mem %t-inh %m-inh"]++) . tail . + dropWhile (notElem "entries" . words) . lines + where + print line = tabcat [paddedfirst, field 3, field 4, field 5, field 6, field 7] + where + tabcat = concat . intersperse "\t" + first = takeWhile (==' ') line ++ (takeWhile (/=' ') $ dropWhile (==' ') line) + paddedfirst = first ++ (take (60 - (length first)) $ repeat ' ') + field n = words line !! n