hledger/overview.hs

35 lines
1.1 KiB
Haskell
Raw Normal View History

2007-03-10 00:39:59 +03:00
-- overview.hs - update an OVERVIEW file
--
2007-03-10 00:42:58 +03:00
-- OVERVIEW should begin with a list of module names (updated manually);
-- below that we generate a list of filename, function, type entries.
-- Useful for getting the big picture and refactoring.
2007-03-10 00:39:59 +03:00
import System
import System.Process
import IO
import Data.List
import Text.Printf
main = do
old <- readFile "OVERVIEW"
let preamble = takeWhile ((> 0) . length) $ lines old
putStr $ unlines preamble
let modules = concat $ map ((++ ".hs ") . dropWhile (== ' ')) preamble
let grep = "grep -H '^\\w[^=]*::' " ++ modules
(inp, out, err, pid) <- runInteractiveCommand grep
2007-05-01 10:48:06 +04:00
waitForProcess pid
2007-03-10 00:39:59 +03:00
grepoutput <- hGetContents out
let groups = groupBy (\a b -> samefile a b) $ lines grepoutput
sequence $ map printgroup groups
putStr "\n"
printgroup ls = do putStr "\n"; sequence $ map printline ls
printline l =
putStrLn $ printf "%-22s %-40s %s" (file++":") code typedecl
where
(file, rest) = break (== ':') l
(code, typedecl) = break (== ':') $ tail rest
samefile a b = ((takeWhile (/= ':') a) ++ ":") `isPrefixOf` b