ref: 21babac8956007ce969518889aec3c93fa1b1fe3
parent: 64a62e84710939806896b0b0cd1f10ad9bdf3016
	author: Lennart Augustsson <lennart.augustsson@epicgames.com>
	date: Mon Jan  8 08:47:48 EST 2024
	
Get rid of hSetBinaryMode, add openBinaryFile.
--- a/Tools/Addcombs.hs
+++ b/Tools/Addcombs.hs
@@ -2,6 +2,7 @@
import Prelude
import Data.Char
import System.Environment
+import System.IO
chunkify :: Int -> [Char] -> [[Char]]
chunkify n [] = []
@@ -14,17 +15,19 @@
main :: IO ()
main = do
-{-args <- getArgs
-  let fn = case args of { [a] -> a; _ -> error "Usage: Addcombs file" }- file <- readFile fn
--}
- hSetBinaryMode stdin True
- file <- hGetContents stdin
+  let (ifn, ofn) = case args of { [a,b] -> (a,b); _ -> error "Usage: Addcombs in-file out-file" }+ ifile <- openBinaryFile ifn ReadMode
+ ofile <- openFile ofn WriteMode
+
+ file <- hGetContents ifile
let size = length file
chunks = chunkify 20 file
-  putStrLn $ "unsigned char combexprdata[] = {"- mapM_ (putStrLn . showChunk) chunks
- putStrLn "0 };"
- putStrLn "unsigned char *combexpr = combexprdata;"
- putStrLn $ "int combexprlen = " ++ show size ++ ";"
+  hPutStrLn ofile $ "unsigned char combexprdata[] = {"+ mapM_ (hPutStrLn ofile . showChunk) chunks
+ hPutStrLn ofile "0 };"
+ hPutStrLn ofile "unsigned char *combexpr = combexprdata;"
+ hPutStrLn ofile $ "int combexprlen = " ++ show size ++ ";"
+ hClose ifile
+ hClose ofile
+
--- a/Tools/Compress.hs
+++ b/Tools/Compress.hs
@@ -2,6 +2,7 @@
import Prelude
import Data.Map as M
import Data.Char
+import System.Environment
import System.IO
--import Debug.Trace
@@ -63,9 +64,14 @@
main :: IO ()
main = do
- f <- hGetContents stdin
+ args <- getArgs
+  let (ifn, ofn) = case args of { [a,b] -> (a,b); _ -> error "Usage: Compress in-file out-file" }+ ifile <- openFile ifn ReadMode
+ f <- hGetContents ifile
when (any bad f) $
error "Non-printable ASCII in input"
let bs = compress initTable f []
- hSetBinaryMode stdout True
- putStr $ 'Z' : (map chr $ toBytes bs)
+ ofile <- openBinaryFile ofn WriteMode
+ hPutStr ofile $ 'Z' : (map chr $ toBytes bs)
+ hClose ifile
+ hClose ofile
--- a/lib/System/IO.hs
+++ b/lib/System/IO.hs
@@ -211,9 +211,9 @@
unsafeInterleaveIO :: forall a . IO a -> IO a
unsafeInterleaveIO ioa = return (primPerformIO ioa)
--- MicroHs is always in binary mode
-hSetBinaryMode :: Handle -> Bool -> IO ()
-hSetBinaryMode _ _ = return ()
+-- MicroHs is currently always in binary mode.
+openBinaryFile :: FilePath -> IOMode -> IO Handle
+openBinaryFile = openFile
--------
--
⑨