-{--
+{--
This is a script to generate the necessary tables to support Windows code page
-encoding/decoding.
+encoding/decoding.
License: see libraries/base/LICENSE
statically linked into every executable. We plan to add support for them once
GHC is able to produce Windows DLLs.
---}
+--}
module Main where
readCharHex s = if c > fromEnum (maxBound :: Word16)
then error "Can't handle non-BMP character."
else toEnum c
- where c = readHex' s
+ where c = readHex' s
-------------------------------------------
++ [" ]"]
mkTableEntry (i,m) = " (" ++ show i ++ ", " ++ makeSBE m ++ " )"
blockSizeText = ["blockBitSize :: Int", "blockBitSize = " ++ show blockBitSize]
-
+
makeSBE :: Map.Map Word8 Char -> String
makeSBE m = unlines
[ "SingleByteCP {"
, " decoderArray = " ++ mkConvArray es
- , " , encoderArray = " ++ mkCompactArray (swapMap m)
+ , " , encoderArray = " ++ mkCompactArray (swapMap m)
, " }"
]
where
type CompressState b = (Map.Map Int [b], Map.Map [b] Int)
-- each entry in the list corresponds to a block of size n.
-compress :: (Bounded a, Enum a, Ord a, Bounded b, Ord b) => Int -> Map.Map a b
+compress :: (Bounded a, Enum a, Ord a, Bounded b, Ord b) => Int -> Map.Map a b
-> ([Int], CompressState b)
compress n ms = runState (mapM lookupOrAdd chunks) (Map.empty, Map.empty)
where
instance Embed Word8 where
mkHex = showHex'
-
+
instance Embed Word16 where
mkHex = repDualByte
showHex' s = "\\x" ++ showHex s ""
repDualByte :: Enum c => c -> String
-repDualByte c
+repDualByte c
| n >= 2^(16::Int) = error "value is too high!"
-- NOTE : this assumes little-endian architecture. But we're only using this on Windows,
-- so it's probably OK.