[project @ 2001-05-18 14:18:34 by simonmar]
[ghc-hetmet.git] / ghc / tests / io / should_run / io018.stdout
1 Smoewnst pa ihyu
2 Caught EOF
3 S-m-o e!w!n
4 Caught EOF
5 S-m-o e!w!n!s tT epsat iinhgy uR!s tT epsat iinhgy uRW handles 
6 module Main(main) where
7
8 import IO
9 import IOExts
10 import Directory (removeFile, doesFileExist)
11 import Monad
12
13 -- This test is weird, full marks to whoever dreamt it up!
14
15 main :: IO ()
16 main = do
17    let username = "io018.inout"
18    f <- doesFileExist username
19    when f (removeFile username)
20    cd <- openFile username ReadWriteMode
21    hSetBinaryMode cd True
22    hSetBuffering stdin NoBuffering
23    hSetBuffering stdout NoBuffering
24    hSetBuffering cd NoBuffering
25    hPutStr cd speakString
26    hSeek cd AbsoluteSeek 0
27    speak cd  `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err
28    hSeek cd AbsoluteSeek 0
29    hSetBuffering cd LineBuffering
30    speak cd  `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err
31    hSeek cd AbsoluteSeek 0
32    hSetBuffering cd (BlockBuffering Nothing)
33    speak cd  `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err
34
35 speakString = "Someone wants to speak with you\n"
36
37 speak cd = do
38      (do
39         ready <- hReady cd
40         if ready then 
41            hGetChar cd >>= putChar
42          else
43            return ()
44         ready <- hReady stdin
45         if ready then (do { ch <- ge
46 Caught EOF