From 2519e7a2b858b205fe02538dd283d4e2e1ae1054 Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Sat, 6 Feb 2010 01:39:09 +0100 Subject: get rid of action-permutations and use parsec permutation library instead Ignore-this: 73dbcd588c961bd8bb4dd6d0c931cb3760e2949e code gets shorter and error messages maybe meaningful darcs-hash:20100206003909-d6583-631e1c5e75ad7e7334f865828b398f4d2310af5a.gz --- Main.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Main.hs') diff --git a/Main.hs b/Main.hs index a94c597..c34af3b 100644 --- a/Main.hs +++ b/Main.hs @@ -35,8 +35,7 @@ import System.Console.GetOpt import System.Exit import System.Environment import System.Posix.Files - -import Control.Monad.Writer (MonadWriter,MonadIO,unless,runWriterT) +import Control.Monad (unless) -- $main @@ -46,9 +45,9 @@ main = do d <- openDisplay "" args <- getArgs (o,file) <- getOpts args - (c,defaultings) <- runWriterT $ case file of - [cfgfile] -> readConfig cfgfile - _ -> readDefaultConfig + (c,defaultings) <- case file of + [cfgfile] -> readConfig cfgfile + _ -> readDefaultConfig unless (null defaultings) $ putStrLn $ "Fields missing from config defaulted: " ++ intercalate "," defaultings @@ -68,19 +67,20 @@ main = do releaseFont d fs -- | Reads the configuration files or quits with an error -readConfig :: (MonadIO m, MonadWriter [String] m) => FilePath -> m Config +readConfig :: FilePath -> IO (Config,[String]) readConfig f = do file <- io $ fileExist f s <- io $ if file then readFileSafe f else error $ f ++ ": file not found!\n" ++ usage either (\err -> error $ f ++ ": configuration file contains errors at:\n" ++ show err) - id $ parseConfig s + return $ parseConfig s + -- | Read default configuration file or load the default config -readDefaultConfig :: (MonadIO m, MonadWriter [String] m) => m Config +readDefaultConfig :: IO (Config,[String]) readDefaultConfig = do home <- io $ getEnv "HOME" let path = home ++ "/.xmobarrc" f <- io $ fileExist path - if f then readConfig path else return defaultConfig + if f then readConfig path else return (defaultConfig,[]) data Opts = Help | Version -- cgit v1.2.3