diff options
author | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-10-02 20:45:00 +0200 |
---|---|---|
committer | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-10-02 20:45:00 +0200 |
commit | 43e01ea9eee814d3984ebec9507cf5439caef149 (patch) | |
tree | 2b1741abdef2432d99e0fd7647ecb9552b2d7a34 | |
parent | 230d3c8f18daecaf1b8344c7bfb98fb965a8c710 (diff) | |
download | xmobar-43e01ea9eee814d3984ebec9507cf5439caef149.tar.gz xmobar-43e01ea9eee814d3984ebec9507cf5439caef149.tar.bz2 |
more code formatting
darcs-hash:20071002184500-d6583-b41a042f203ec30a69264ca04afa98a8f8fe0026.gz
-rw-r--r-- | Main.hs | 51 |
1 files changed, 25 insertions, 26 deletions
@@ -33,38 +33,37 @@ import System.Posix.Files -- | The main entry point main :: IO () -main = - do args <- getArgs - (o,file) <- getOpts args - c <- case file of - [cfgfile] -> readConfig cfgfile - _ -> readDefaultConfig - civ <- newIORef c - doOpts civ o - conf <- readIORef civ - cl <- parseTemplate conf (template conf) - vars <- mapM startCommand cl - (d,w) <- createWin conf - eventLoop conf vars d w - return () +main = do + args <- getArgs + (o,file) <- getOpts args + c <- case file of + [cfgfile] -> readConfig cfgfile + _ -> readDefaultConfig + civ <- newIORef c + doOpts civ o + conf <- readIORef civ + cl <- parseTemplate conf (template conf) + vars <- mapM startCommand cl + (d,w) <- createWin conf + eventLoop conf vars d w -- | Reads the configuration files or quits with an error readConfig :: FilePath -> IO Config -readConfig f = - do file <- fileExist f - s <- if file then readFile f else error $ f ++ ": file not found!\n" ++ usage - case reads s of - [(conf,_)] -> return conf - [] -> error $ f ++ ": configuration file contains errors!\n" ++ usage - _ -> error ("Some problem occured. Aborting...") +readConfig f = do + file <- fileExist f + s <- if file then readFile f else error $ f ++ ": file not found!\n" ++ usage + case reads s of + [(conf,_)] -> return conf + [] -> error $ f ++ ": configuration file contains errors!\n" ++ usage + _ -> error ("Some problem occured. Aborting...") -- | Read default configuration file or load the default config readDefaultConfig :: IO Config -readDefaultConfig = - do home <- getEnv "HOME" - let path = home ++ "/.xmobarrc" - f <- fileExist path - if f then readConfig path else return defaultConfig +readDefaultConfig = do + home <- getEnv "HOME" + let path = home ++ "/.xmobarrc" + f <- fileExist path + if f then readConfig path else return defaultConfig data Opts = Help | Version |