1 -- *** what's left after removing data/type decls
3 -- I/O functions and definitions
16 import List ( (++), foldr )
17 import PS ( _PackedString, _unpackPS )
23 -- File and channel names:
31 readFile :: String -> FailCont -> StrCont -> Dialogue
32 writeFile :: String -> String -> FailCont -> SuccCont -> Dialogue
33 appendFile :: String -> String -> FailCont -> SuccCont -> Dialogue
34 readBinFile :: String -> FailCont -> BinCont -> Dialogue
35 writeBinFile :: String -> Bin -> FailCont -> SuccCont -> Dialogue
36 appendBinFile :: String -> Bin -> FailCont -> SuccCont -> Dialogue
37 deleteFile :: String -> FailCont -> SuccCont -> Dialogue
38 statusFile :: String -> FailCont -> StrCont -> Dialogue
39 readChan :: String -> FailCont -> StrCont -> Dialogue
40 appendChan :: String -> String -> FailCont -> SuccCont -> Dialogue
41 readBinChan :: String -> FailCont -> BinCont -> Dialogue
42 appendBinChan :: String -> Bin -> FailCont -> SuccCont -> Dialogue
43 statusChan :: String -> FailCont -> StrCont -> Dialogue
44 echo :: Bool -> FailCont -> SuccCont -> Dialogue
45 getArgs :: FailCont -> StrListCont -> Dialogue
46 getProgName :: FailCont -> StrCont -> Dialogue
47 getEnv :: String -> FailCont -> StrCont -> Dialogue
48 setEnv :: String -> String -> FailCont -> SuccCont -> Dialogue
49 sigAction :: Int -> SigAct -> FailCont -> SuccCont -> Dialogue
53 readFile name fail succ resps =
54 (ReadFile name) : strDispatch fail succ resps
56 writeFile name contents fail succ resps =
57 (WriteFile name contents) : succDispatch fail succ resps
59 appendFile name contents fail succ resps =
60 (AppendFile name contents) : succDispatch fail succ resps
62 readBinFile name fail succ resps =
63 (ReadBinFile name) : binDispatch fail succ resps
65 writeBinFile name contents fail succ resps =
66 (WriteBinFile name contents) : succDispatch fail succ resps
68 appendBinFile name contents fail succ resps =
69 (AppendBinFile name contents) : succDispatch fail succ resps
71 deleteFile name fail succ resps =
72 (DeleteFile name) : succDispatch fail succ resps
74 statusFile name fail succ resps =
75 (StatusFile name) : strDispatch fail succ resps
77 readChan name fail succ resps =
78 (ReadChan name) : strDispatch fail succ resps
80 appendChan name contents fail succ resps =
81 (AppendChan name contents) : succDispatch fail succ resps
83 readBinChan name fail succ resps =
84 (ReadBinChan name) : binDispatch fail succ resps
86 appendBinChan name contents fail succ resps =
87 (AppendBinChan name contents) : succDispatch fail succ resps
89 statusChan name fail succ resps =
90 (StatusChan name) : strDispatch fail succ resps
92 echo bool fail succ resps =
93 (Echo bool) : succDispatch fail succ resps
95 getArgs fail succ resps =
96 GetArgs : strListDispatch fail succ resps
98 getProgName fail succ resps =
99 GetProgName : strDispatch fail succ resps
101 getEnv name fail succ resps =
102 (GetEnv name) : strDispatch fail succ resps
104 setEnv name val fail succ resps =
105 (SetEnv name val) : succDispatch fail succ resps
107 sigAction signal action fail succ resps =
108 (SigAction signal action) : succDispatch fail succ resps
110 strDispatch fail succ (resp:resps) =
111 case resp of Str val -> succ val resps
112 Failure msg -> fail msg resps
114 strListDispatch fail succ (resp:resps) =
115 case resp of StrList val -> succ val resps
116 Failure msg -> fail msg resps
118 binDispatch fail succ (resp:resps) =
119 case resp of Bn val -> succ val resps
120 Failure msg -> fail msg resps
122 succDispatch fail succ (resp:resps) =
123 case resp of Success -> succ resps
124 Failure msg -> fail msg resps
131 exit err = appendChan stderr (msg ++ "\n") abort done
132 where msg = case err of ReadError s -> s
139 {-# GENERATE_SPECS print a{+,(),Bool,Char,Int,Integer,Double,_PackedString,[Char],[Int],[[Char]],[[Int]]} #-}
140 print :: (Text a) => a -> Dialogue
141 print x = appendChan stdout (show x) exit done
143 {-# GENERATE_SPECS prints a{+,(),Bool,Char,Int,Integer,Double,_PackedString,[Char],[Int],[[Char]],[[Int]]} #-}
144 prints :: (Text a) => a -> String -> Dialogue
145 prints x s = appendChan stdout (shows x s) exit done
147 interact :: (String -> String) -> Dialogue
148 interact f = readChan stdin exit
149 (\x -> appendChan stdout (f x) exit done)