update
[fp1415-soccerfun.git] / src / StdLibExt / fileIO.icl
1 implementation module fileIO
2
3 import StdEnvExt
4 import StdBitmap
5
6 getImage :: !String !*env -> (!Bitmap,!*env) | FileSystem env
7 getImage path env
8 = case openBitmap path env of
9 (Nothing,_) = abort ("getImage: unable to get Image " <+++ path <+++".\n")
10 (Just bm,env) = (bm,env)
11
12 writeFile :: !Bool !String !String !*env -> *env | FileSystem env
13 writeFile append path text env
14 # (open,outputFile,env) = fopen path (if append FAppendText FWriteText) env
15 | not open = abort ("writeFile: could not open " <+++ path <+++ ".\n")
16 # (close, env) = fclose (outputFile <<< text) env
17 | not close = abort ("writeFile: could not close " <+++ path <+++".\n")
18 | otherwise = env
19
20 readFile :: !String !*env -> (!Maybe String,*env) | FileSystem env
21 readFile path env
22 # (open,inputFile,env) = fopen path FReadText env
23 | not open = (Nothing,snd (fclose inputFile env))
24 # (ok,inputFile) = fseek inputFile 0 FSeekEnd
25 | not ok = (Nothing,snd (fclose inputFile env))
26 # (pos,inputFile) = fposition inputFile
27 # (ok,inputFile) = fseek inputFile 0 FSeekSet
28 | not ok = (Nothing,snd (fclose inputFile env))
29 # (str,inputFile) = freads inputFile pos
30 # (ok,env) = fclose inputFile env
31 | not ok = (Nothing, env)
32 | otherwise = (Just str,env)