packages feed

omnicodec 0.3.1 → 0.4.0

raw patch · 3 files changed

+22/−20 lines, 3 filesdep +bytestring

Dependencies added: bytestring

Files

omnicodec.cabal view
@@ -1,10 +1,10 @@ name: omnicodec-version: 0.3.1+version: 0.4.0 license: GPL license-file: COPYING author: Magnus Therning maintainer: magnus@therning.org-copyright: Magnus Therning, 2007+copyright: Magnus Therning, 2007-2010 synopsis: data encoding and decoding command line utilities description: Two simple command line tools built on dataenc. build-type: Simple@@ -14,11 +14,13 @@ executable odec   main-is: odec.hs   hs-source-dirs: src-  build-depends: base >= 4.0.0 && < 4.3, dataenc >= 0.13, directory, filepath, haskell98+  build-depends: base >= 4.0.0 && < 4.3, dataenc >= 0.13, directory, filepath,+      haskell98, bytestring   ghc-options: -Wall  executable oenc   main-is: oenc.hs   hs-source-dirs: src-  build-depends: base >= 4.0.0 && < 4.3, dataenc >= 0.13, directory, filepath, haskell98+  build-depends: base >= 4.0.0 && < 4.3, dataenc >= 0.13, directory, filepath,+      haskell98, bytestring   ghc-options: -Wall
src/odec.hs view
@@ -21,7 +21,6 @@     ) where  import Codec.Binary.DataEncoding-import Data.Char import Data.Maybe import Data.Version (showVersion) import Data.Word@@ -29,18 +28,19 @@ import System.Console.GetOpt import Control.Exception as CE import System.Directory+import qualified Data.ByteString as BS  import Paths_omnicodec (version)  ver :: String ver = "omnicode decode (odec) " ++ (showVersion version)-    ++ "\nCopyright 2007-2009 Magnus Therning <magnus@therning.org>"+    ++ "\nCopyright 2007-2010 Magnus Therning <magnus@therning.org>"  -- {{{1 Options data DecOptions = DecOptions {     optDecode :: [String] -> [Maybe Word8],     optRead :: IO String,-    optWrite :: String -> IO (),+    optWrite :: BS.ByteString -> IO (),     optFn :: Maybe String  -- needed in case we need to clean up later on     } @@ -48,7 +48,7 @@ defaultOptions = DecOptions {     optDecode = decode' uu . unchop uu,     optRead = getContents,-    optWrite = putStr,+    optWrite = BS.putStr,     optFn = Nothing     } @@ -63,7 +63,7 @@  -- {{{2 Processing command line setOptOutput :: FilePath -> DecOptions -> IO DecOptions-setOptOutput fn opts = return opts { optWrite = writeFile fn, optFn = Just fn }+setOptOutput fn opts = return opts { optWrite = BS.writeFile fn, optFn = Just fn }  setOptCodec :: String -> DecOptions -> IO DecOptions setOptCodec codec opts = case codec of@@ -89,9 +89,9 @@ processFileName (fn:_) = return defaultOptions { optRead = readFile fn } processFileName _ = return defaultOptions --- {{{1 _decode-_decode :: DecOptions -> String -> IO String-_decode opts = return .  map (chr . fromIntegral . fromMaybe (error "Illegal character")) . optDecode opts . lines+-- {{{1 decode'+_decode :: DecOptions -> String -> IO BS.ByteString+_decode opts = return .  BS.pack. map (fromMaybe (error "Illegal character")) . optDecode opts . lines  -- {{{1 main main :: IO ()
src/oenc.hs view
@@ -20,29 +20,29 @@     where  import Codec.Binary.DataEncoding-import Data.Char import Data.Version (showVersion) import Data.Word import System import System.Console.GetOpt+import qualified Data.ByteString as BS  import Paths_omnicodec (version)  ver :: String ver = "omnicode encode (oenc) " ++ (showVersion version)-    ++ "\nCopyright 2007-2009 Magnus Therning <magnus@therning.org>"+    ++ "\nCopyright 2007-2010 Magnus Therning <magnus@therning.org>"  -- {{{1 Options data EncOptions = EncOptions {     optEncode :: [Word8] -> [String],-    optRead :: IO String,+    optRead :: IO BS.ByteString,     optWrite :: String -> IO ()     }  defaultOptions :: EncOptions defaultOptions = EncOptions {     optEncode = chop uu 61 . encode uu,-    optRead = getContents,+    optRead = BS.getContents,     optWrite = putStr     } @@ -79,12 +79,12 @@ optShowHelp _ = putStr (usageInfo "Usage:" options) >> exitWith ExitSuccess  processFileName :: [String] -> IO EncOptions-processFileName (fn:_) = return defaultOptions { optRead = readFile fn }+processFileName (fn:_) = return defaultOptions { optRead = BS.readFile fn } processFileName _ = return defaultOptions  -- {{{1 encode-encode' :: EncOptions -> String -> IO String-encode' opts = return . unlines . optEncode opts . map (fromIntegral . ord)+_encode :: EncOptions -> BS.ByteString -> IO String+_encode opts = return . unlines . optEncode opts . BS.unpack  -- {{{1 main main :: IO ()@@ -92,4 +92,4 @@     args <- getArgs     let (actions, nonOpts, _) = getOpt RequireOrder options args     opts <- foldl (>>=) (processFileName nonOpts) actions-    optRead opts >>= encode' opts >>= optWrite opts+    optRead opts >>= _encode opts >>= optWrite opts