packages feed

MicroHs-0.17.4.0 / Tools / Addcombs.hs

module Addcombs(main) whereimport Preludeimport Data.Charimport System.Environmentimport System.IOchunkify :: Int -> [Char] -> [[Char]]chunkify n [] = []chunkify n xs =  let (as, bs) = splitAt n xs  in  as : chunkify n bsshowChunk :: [Char] -> StringshowChunk = concatMap (\ c -> show (ord c) ++ ",")main :: IO ()main = do  args <- getArgs  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  hPutStrLn ofile "static unsigned char combexprdata[] = {"  mapM_ (hPutStrLn ofile . showChunk) chunks  hPutStrLn ofile "};"  hPutStrLn ofile "const unsigned char *combexpr = combexprdata;"  hPutStrLn ofile $ "const int combexprlen = " ++ show size ++ ";"--  hClose ifile--  hClose ofile