<commit_before>-- !!! Test file positioning

module Main(main) where

import IO
import Monad
import Directory (removeFile, doesFileExist)
#ifdef i386_unknown_mingw32
import GHC.Handle(hSetBinaryMode)
#endif

main = do
  hIn <- openFile "hGetPosn001.in" ReadMode
#ifdef i386_unknown_mingw32
  hSetBinaryMode hIn True
#endif
  f <- doesFileExist "hGetPosn001.out"
  when f (removeFile "hGetPosn001.out")
  hOut <- openFile "hGetPosn001.out" ReadWriteMode
  bof <- hGetPosn hIn
  putStrLn (show bof)  -- you can show HandlePosns
  copy hIn hOut
  hSetPosn bof
  copy hIn hOut
#ifdef i386_unknown_mingw32
  hSetBinaryMode hOut True
#endif
  hSeek hOut AbsoluteSeek 0
#ifdef i386_unknown_mingw32
  hSetBinaryMode hOut False
#endif
  stuff <- hGetContents hOut
  putStr stuff

copy :: Handle -> Handle -> IO ()
copy hIn hOut =
    try (hGetChar hIn) >>=
    either (\ err -> if isEOFError err then return () else error "copy")
	   ( \ x -> hPutChar hOut x >> copy hIn hOut)
<commit_msg>Fix hGetPosn001 on Windows<commit_after>-- !!! Test file positioning

module Main(main) where

import IO
import Monad
import Directory (removeFile, doesFileExist)
#ifdef mingw32_HOST_OS
import GHC.Handle(hSetBinaryMode)
#endif

main = do
  hIn <- openFile "hGetPosn001.in" ReadMode
#ifdef mingw32_HOST_OS
  hSetBinaryMode hIn True
#endif
  f <- doesFileExist "hGetPosn001.out"
  when f (removeFile "hGetPosn001.out")
  hOut <- openFile "hGetPosn001.out" ReadWriteMode
  bof <- hGetPosn hIn
  putStrLn (show bof)  -- you can show HandlePosns
  copy hIn hOut
  hSetPosn bof
  copy hIn hOut
#ifdef mingw32_HOST_OS
  hSetBinaryMode hOut True
#endif
  hSeek hOut AbsoluteSeek 0
#ifdef mingw32_HOST_OS
  hSetBinaryMode hOut False
#endif
  stuff <- hGetContents hOut
  putStr stuff

copy :: Handle -> Handle -> IO ()
copy hIn hOut =
    try (hGetChar hIn) >>=
    either (\ err -> if isEOFError err then return () else error "copy")
	   ( \ x -> hPutChar hOut x >> copy hIn hOut)

{'fraction_non_alphanumeric': 0.08499743983614952, 'fraction_numerical': 0.029185867895545316, 'mean_word_length': 3.909547738693467, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2268217', 'n_tokens_mistral': 776, 'n_tokens_neox': 717, 'n_words': 221}