From 11987749fc6e6d3e53ea737d46d5ab13a16faeb8 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Sat, 28 Sep 2019 13:43:29 -0400 Subject: Factor out some new libraries word64-map: Data.Word64Map network-addr: Network.Address tox-crypto: Crypto.Tox lifted-concurrent: Control.Concurrent.Lifted.Instrument Control.Concurrent.Async.Lifted.Instrument psq-wrap: Data.Wrapper.PSQInt Data.Wrapper.PSQ minmax-psq: Data.MinMaxPSQ tasks: Control.Concurrent.Tasks kad: Network.Kademlia Network.Kademlia.Bootstrap Network.Kademlia.Routing Network.Kademlia.CommonAPI Network.Kademlia.Persistence Network.Kademlia.Search --- src/Text/XXD.hs | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 src/Text/XXD.hs (limited to 'src/Text/XXD.hs') diff --git a/src/Text/XXD.hs b/src/Text/XXD.hs deleted file mode 100644 index 77606bfa..00000000 --- a/src/Text/XXD.hs +++ /dev/null @@ -1,48 +0,0 @@ -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE ScopedTypeVariables #-} -module Text.XXD (xxd, xxd2) where - -import Data.ByteArray (ByteArrayAccess) -import qualified Data.ByteArray as BA -import Data.Word -import Data.Bits -import Data.Char -import Text.Printf - -nibble :: Word8 -> Char -nibble b = intToDigit (fromIntegral (b .&. 0x0F)) - -nibbles :: ByteArrayAccess ba => ba -> String -nibbles xs = unwords $ map (\byte -> [nibble (byte `shiftR` 4), nibble byte]) - $ BA.unpack xs - -xxd0 :: (ByteArrayAccess ba) => (forall b. ByteArrayAccess b => b -> String) -> Int -> ba -> [String] -xxd0 tr offset bs | BA.null bs = [] -xxd0 tr offset bs = printf "%03x: %s%s" offset (nibbles xs) (tr xs) - : xxd0 tr (offset + BA.length xs) bs' - where - (xs,bs') = splitAtView 16 bs - -splitAtView :: (ByteArrayAccess ba) => Int -> ba -> (BA.View ba, BA.View ba) -splitAtView n bs = (BA.takeView bs n, BA.dropView bs n) - -xxd :: ByteArrayAccess a => Int -> a -> [String] -xxd = xxd0 (const "") - --- | like xxd, but also shows ascii -xxd2 :: ByteArrayAccess a => Int -> a -> [String] -xxd2 = xxd0 withAscii - -withAscii :: ByteArrayAccess a => a -> [Char] -withAscii row = replicate (50 - 3 * BA.length row) ' ' ++ myunpack row - where - myunpack s = map word8tochar (BA.unpack s) - where word8tochar w | (w .&. 0x80 /= 0) = '.' - word8tochar w = let c = chr (fromIntegral w) - in if isPrint c then c else '.' - -{- -main = do - bs <- B.getContents - mapM_ putStrLn $ xxd2 0 bs - -} -- cgit v1.2.3