blob: 6b26eecb9720c5f839b30ac9320aac18b44c1558 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
-- !!! Testing hGetPosn and hSetPosn
module Main(main) where
import System.IO
getPosnAndPrint h = do
x <- hTell h
v <- hGetChar h
putStrLn ("At position: " ++ show x ++ ", found: " ++ show v)
return x
recordDoAndRepos h a = do
x <- getPosnAndPrint h
a
hSeek h AbsoluteSeek x
getPosnAndPrint h
return ()
recordDoAndRepos2 h a = do
x <- getPosnAndPrint h
a
hSeek h AbsoluteSeek x
getPosnAndPrint h
return ()
recordDoAndRepos3 h a = do
x <- getPosnAndPrint h
a
hSeek h SeekFromEnd (negate (x + 1))
getPosnAndPrint h
return ()
file = "hTell001.hs"
main :: IO ()
main = do
h <- openBinaryFile file ReadMode
recordDoAndRepos h $
recordDoAndRepos h $
recordDoAndRepos h $
recordDoAndRepos h $
recordDoAndRepos h $
putStrLn ""
hClose h
putStrLn "\nUsing hSeek/AbsoluteSeek: "
h <- openBinaryFile file ReadMode
recordDoAndRepos2 h $
recordDoAndRepos2 h $
recordDoAndRepos2 h $
recordDoAndRepos2 h $
recordDoAndRepos2 h $
putStrLn ""
hClose h
putStrLn "\nUsing hSeek/SeekFromEnd: "
putStrLn "(Don't worry if you're seeing differing numbers here, it might be down to '\\n' vs '\\r\\n')"
h <- openBinaryFile file ReadMode
recordDoAndRepos3 h $
recordDoAndRepos3 h $
recordDoAndRepos3 h $
recordDoAndRepos3 h $
recordDoAndRepos3 h $
putStrLn ""
|