[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / misc / examples / io / io018 / Main.hs
diff --git a/ghc/misc/examples/io/io018/Main.hs b/ghc/misc/examples/io/io018/Main.hs
new file mode 100644 (file)
index 0000000..f15c1cb
--- /dev/null
@@ -0,0 +1,23 @@
+import LibSystem(getArgs)
+
+main =   getArgs                            >>=        \ [user,host] ->
+         let username = (user ++ "@" ++ host) in
+         openFile username ReadWriteMode    >>=        \ cd          ->
+         hSetBuffering stdin NoBuffering    >>
+         hSetBuffering stdout NoBuffering   >>
+         hSetBuffering cd NoBuffering       >>
+         hPutStr cd speakString             >>
+         speak cd
+
+speakString = "Someone wants to speak with you\n"
+
+speak cd =
+         (hReady cd                         >>=        \ ready       ->
+         if ready then (hGetChar cd >>= putChar)
+         else return ()                     >>
+
+         hReady stdin                       >>=        \ ready       ->
+         if ready then (getChar >>= hPutChar cd)
+         else return ())                    >>
+
+         speak cd