omnicodec 0.3 → 0.3.1
raw patch · 3 files changed
+39/−19 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- omnicodec.cabal +13/−9
- src/odec.hs +16/−6
- src/oenc.hs +10/−4
omnicodec.cabal view
@@ -1,20 +1,24 @@ name: omnicodec-version: 0.3+version: 0.3.1 license: GPL license-file: COPYING author: Magnus Therning maintainer: magnus@therning.org copyright: Magnus Therning, 2007 synopsis: data encoding and decoding command line utilities-description: Two simply command line tools built on dataenc.-build-depends: base >= 4.0.0 && < 4.2, dataenc >= 0.13, directory, filepath, haskell98+description: Two simple command line tools built on dataenc. build-type: Simple category: Codec+cabal-version: >= 1.2 -executable: odec-main-is: odec.hs-hs-source-dirs: src+executable odec+ main-is: odec.hs+ hs-source-dirs: src+ build-depends: base >= 4.0.0 && < 4.3, dataenc >= 0.13, directory, filepath, haskell98+ ghc-options: -Wall -executable: oenc-main-is: oenc.hs-hs-source-dirs: src+executable oenc+ main-is: oenc.hs+ hs-source-dirs: src+ build-depends: base >= 4.0.0 && < 4.3, dataenc >= 0.13, directory, filepath, haskell98+ ghc-options: -Wall
src/odec.hs view
@@ -17,7 +17,8 @@ -} module Main- where+ ( main+ ) where import Codec.Binary.DataEncoding import Data.Char@@ -31,6 +32,7 @@ import Paths_omnicodec (version) +ver :: String ver = "omnicode decode (odec) " ++ (showVersion version) ++ "\nCopyright 2007-2009 Magnus Therning <magnus@therning.org>" @@ -39,14 +41,15 @@ optDecode :: [String] -> [Maybe Word8], optRead :: IO String, optWrite :: String -> IO (),- fn :: Maybe String -- needed in case we need to clean up later on+ optFn :: Maybe String -- needed in case we need to clean up later on } +defaultOptions :: DecOptions defaultOptions = DecOptions { optDecode = decode' uu . unchop uu, optRead = getContents, optWrite = putStr,- fn = Nothing+ optFn = Nothing } -- {{{2 Command line@@ -59,7 +62,10 @@ ] -- {{{2 Processing command line-setOptOutput fn opts = return opts { optWrite = writeFile fn, fn = Just fn }+setOptOutput :: FilePath -> DecOptions -> IO DecOptions+setOptOutput fn opts = return opts { optWrite = writeFile fn, optFn = Just fn }++setOptCodec :: String -> DecOptions -> IO DecOptions setOptCodec codec opts = case codec of "uu" -> return opts { optDecode = decode' uu . unchop uu } "xx" -> return opts { optDecode = decode' xx . unchop xx }@@ -71,8 +77,12 @@ "b32" -> return opts { optDecode = decode' base32 . unchop base32 } "b32h" -> return opts { optDecode = decode' base32Hex . unchop base32Hex } "b16" -> return opts { optDecode = decode' base16 . unchop base16 }+ _ -> error "Unknown encoding." +optShowVersion :: a -> IO DecOptions optShowVersion _ = putStrLn ver >> exitWith ExitSuccess++optShowHelp :: DecOptions -> IO DecOptions optShowHelp _ = putStrLn (usageInfo "Usage:" options) >> exitWith ExitSuccess processFileName :: [String] -> IO DecOptions@@ -87,7 +97,7 @@ main :: IO () main = do args <- getArgs- let (actions, nonOpts, msgs) = getOpt RequireOrder options args+ let (actions, nonOpts, _) = getOpt RequireOrder options args opts <- foldl (>>=) (processFileName nonOpts) actions CE.catch (optRead opts >>= _decode opts >>= optWrite opts)- (\ (CE.SomeException e) -> maybe (return ()) removeFile (fn opts) >> throwIO e)+ (\ (CE.SomeException e) -> maybe (return ()) removeFile (optFn opts) >> throwIO e)
src/oenc.hs view
@@ -20,17 +20,15 @@ where import Codec.Binary.DataEncoding-import Control.Monad import Data.Char import Data.Version (showVersion) import Data.Word-import Numeric import System import System.Console.GetOpt-import System.FilePath import Paths_omnicodec (version) +ver :: String ver = "omnicode encode (oenc) " ++ (showVersion version) ++ "\nCopyright 2007-2009 Magnus Therning <magnus@therning.org>" @@ -41,6 +39,7 @@ optWrite :: String -> IO () } +defaultOptions :: EncOptions defaultOptions = EncOptions { optEncode = chop uu 61 . encode uu, optRead = getContents,@@ -56,6 +55,7 @@ ] -- {{{2 option actions+setOptCodec :: String -> EncOptions -> IO EncOptions setOptCodec codec opts = case codec of "uu" -> return opts { optEncode = chop uu 61 . encode uu } "xx" -> return opts { optEncode = chop xx 61 . encode xx }@@ -67,9 +67,15 @@ "b32" -> return opts { optEncode = chop base32 60 . encode base32 } "b32h" -> return opts { optEncode = chop base32Hex 60 . encode base32Hex } "b16" -> return opts { optEncode = chop base16 60 . encode base16 }+ _ -> error "Unknown encoding." +setOptOutput :: FilePath -> EncOptions -> IO EncOptions setOptOutput fn opts = return opts { optWrite = writeFile fn }++optShowVersion :: EncOptions -> IO EncOptions optShowVersion _ = putStrLn ver >> exitWith ExitSuccess++optShowHelp :: EncOptions -> IO EncOptions optShowHelp _ = putStr (usageInfo "Usage:" options) >> exitWith ExitSuccess processFileName :: [String] -> IO EncOptions@@ -84,6 +90,6 @@ main :: IO () main = do args <- getArgs- let (actions, nonOpts, msgs) = getOpt RequireOrder options args+ let (actions, nonOpts, _) = getOpt RequireOrder options args opts <- foldl (>>=) (processFileName nonOpts) actions optRead opts >>= encode' opts >>= optWrite opts