fix haddock submodule pointer
[ghc-hetmet.git] / utils / hpc / HpcShowTix.hs
1 module HpcShowTix (showtix_plugin) where
2
3 import Trace.Hpc.Mix
4 import Trace.Hpc.Tix
5
6 import HpcFlags
7
8 import qualified Data.Set as Set
9
10 showtix_options :: FlagOptSeq
11 showtix_options 
12         = excludeOpt
13         . includeOpt
14         . srcDirOpt
15         . hpcDirOpt
16         . outputOpt
17
18 showtix_plugin :: Plugin
19 showtix_plugin = Plugin { name = "show"
20                        , usage = "[OPTION] .. <TIX_FILE> [<MODULE> [<MODULE> ..]]" 
21                        , options = showtix_options 
22                        , summary = "Show .tix file in readable, verbose format"
23                        , implementation = showtix_main
24                        , init_flags = default_flags
25                        , final_flags = default_final_flags
26                        }
27
28
29 showtix_main :: Flags -> [String] -> IO ()
30 showtix_main _     [] = hpcError showtix_plugin $ "no .tix file or executable name specified" 
31 showtix_main flags (prog:modNames) = do
32   let hpcflags1 = flags 
33                 { includeMods = Set.fromList modNames
34                                    `Set.union` 
35                                 includeMods flags }
36
37   optTixs <- readTix (getTixFileName prog)
38   case optTixs of
39     Nothing -> hpcError showtix_plugin $ "could not read .tix file : "  ++ prog
40     Just (Tix tixs) -> do
41        tixs_mixs <- sequence
42                [ do mix <- readMixWithFlags hpcflags1 (Right tix)
43                     return $ (tix,mix)
44                | tix <- tixs
45                , allowModule hpcflags1 (tixModuleName tix)
46                ]
47      
48        let rjust n str = take (n - length str) (repeat ' ') ++ str 
49        let ljust n str = str ++ take (n - length str) (repeat ' ') 
50      
51        sequence_ [ sequence_ [ putStrLn (rjust 5 (show ix) ++ " " ++
52                                          rjust 10 (show count) ++ " " ++
53                                          ljust 20  modName ++ " " ++ rjust 20 (show pos) ++ " " ++ show lab)
54                              | (count,ix,(pos,lab)) <- zip3 tixs' [(0::Int)..] entries
55                              ]
56                  | ( TixModule modName _hash1 _ tixs'
57                    , Mix _file _timestamp _hash2 _tab entries
58                    ) <- tixs_mixs
59                  ]
60        
61        return ()
62