{-
   GhcProfileCrash.lhs
   This program crashes when trying to obtain a 
   heap trace with +RTS -hc -RTS, after reading some files.
   The file "dir.short.dat" contains a list filenames; from
   the files mentioned in this list, the name and the first 
   line are displayed.

   Output in the Dos shell:
Reading: C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00542.dat
C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00542.dat
THE_URL:http://www.behr.nl/Beurs/Slotkoersen/slotkoersen.php?fd=bca.p.unite

Reading: C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00543.dat
C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00543.dat
THE_URL:http://www.behr.nl/Beurs/Slotkoersen/slotkoersen.php?fd=bce.inc

Reading: C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00544.dat
C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00544.dat
THE_URL:http://www.behr.nl/Beurs/Slotkoersen/slotkoersen.php?fd=bco.p.veron

Reading: C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00545.dat
C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00545.dat
THE_URL:http://www.behr.nl/Beurs/Slotkoersen/slotkoersen.php?fd=be.semicon

Reading: C:\Mijn documenten\beleggen\koersen\TestSet3\040814\lnk00546.dat
C:\MIJNDO~1\SOFTWA~1\HASKELL\READALOT\GHCPROFI.EXE: internal error: heapCensus
    Please report this as a bug to glasgow-haskell-bugs@haskell.org,
    or http://www.sourceforge.net/projects/ghc/


   2004-10-02

-}

> import IO
> import Monad
> import DeepSeq

> debugging = True

===============================================================================
main
===============================================================================

> main :: IO ()
> main = 
>   do 
>     hInputSet   <- openFile "dir.long.version.dat" ReadMode
>     fileNames   <- hGetContents hInputSet
>
>     sequence_ $ map printFileData (lines fileNames)
>
>     hClose hInputSet


===============================================================================
printFileData 
Display the result from collectData 
===============================================================================

> printFileData :: String -> IO ()
> printFileData fileName = collectData fileName >>= putStr . unlines


===============================================================================
collectData 
Read the first line of a file
===============================================================================

> collectData :: String ->      -- A filename
>                IO [String]    -- A list of results
> 
> collectData []       = return []
> collectData fileName = 
>   do
>     putStrLn $ "Reading: " ++ fileName
>     h <- openFile fileName ReadMode
> 
>     contents  <- hGetContents h
>     firstLine <- return $!! head $ lines contents
>
>     hClose h
>
>     return [fileName, firstLine, ""]
