1 module Scaffolding(readLines, openFile) where
  2 
  3 import qualified IO
  4 import qualified Data.ByteString as BS
  5 
  6 readLines fhandle acc =
  7     do  s <- sreadLine fhandle
  8         case s of
  9             Just s -> do readLines fhandle (s:acc)
 10             Nothing -> do return (reverse acc)
 11 
 12 sreadLine fhandle =
 13     catch (do l <- BS.hGetLine fhandle
 14               return (Just l))
 15     (readErrHandler fhandle)
 16 
 17 readErrHandler fhandle err = do IO.hClose fhandle ; return Nothing
 18 
 19 openFile fileName =
 20     catch (do fh <- IO.openFile fileName IO.ReadMode
 21               return (Just fh))
 22           (openErrHandler fileName)
 23 
 24 openErrHandler fileName err = do putStrLn $ show err ; return Nothing