Add stage2/ghci to ghc-api's import list.
[ghc-hetmet.git] / ghc / misc / examples / posix / po012 / Main.hs
1 import Posix
2 import IO -- 1.3
3
4 main =
5     createFile "po012.out" stdFileMode >>= \ fd ->
6     installHandler processStatusChanged (Catch (reap1 fd)) Nothing >>
7     ls >>
8     awaitSignal Nothing
9
10 ls =
11     runProcess "ls" ["-l","po012.out"] Nothing Nothing Nothing Nothing Nothing
12
13 reap1 fd =
14     getAnyProcessStatus True False >>
15     installHandler processStatusChanged (Catch (reap2 fd)) Nothing >>
16     writeChannel fd (take 666 (repeat 'x')) >>
17     ls >>
18     awaitSignal Nothing
19     
20 reap2 fd =
21     getAnyProcessStatus True False >>
22     installHandler processStatusChanged (Catch (reap3 fd)) Nothing >>
23     setFileMode "po012.out" 
24         (foldr1 unionFileModes [ownerReadMode,ownerWriteMode,groupReadMode,otherReadMode]) >>
25     ls >>
26     awaitSignal Nothing
27     
28 reap3 fd =
29     getAnyProcessStatus True False >>
30     installHandler processStatusChanged (Catch (reap4 fd)) Nothing >>
31     setFileTimes "po012.out" 0 0 >>
32     ls >>
33     awaitSignal Nothing
34     
35 reap4 fd =
36     getAnyProcessStatus True False >>
37     installHandler processStatusChanged (Catch (reap5 fd)) Nothing >>
38     removeLink "po012.out" >>
39     ls >>
40     awaitSignal Nothing
41
42 reap5 fd =
43     getAnyProcessStatus True False >>
44     seekChannel fd SeekFromEnd 0 >>= \ bytes ->
45     if bytes == 666 then
46         seekChannel fd AbsoluteSeek 0 >>
47         readChannel fd 1024 >>= \ (str, _) ->
48         if str == (take 666 (repeat 'x')) then
49             putStr "Okay\n"
50         else
51             putStr "Read failed\n"
52     else
53         putStr "Seek returned wrong size\n"