From d33797bdb63318b219407a6eb66a4a6bc0ea5e61 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 8 Jun 2015 17:57:19 +0200 Subject: Less whitespace-finecky --- src/Trivmix.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/Trivmix.hs') diff --git a/src/Trivmix.hs b/src/Trivmix.hs index a754e76..c1fbe8a 100644 --- a/src/Trivmix.hs +++ b/src/Trivmix.hs @@ -26,6 +26,8 @@ import System.IO.Error import System.INotify +import Data.Char + data Options = Options { input :: String , output :: String @@ -107,7 +109,7 @@ onLevelFile file initial action = do exists <- doesFileExist file let acquire = case exists of True -> return () - False -> createFile file mode >>= closeFd >> writeFile file (show initial) + False -> createFile file mode >>= closeFd >> writeFile file (show initial ++ "\n") mode = foldl unionFileModes nullFileMode [ ownerReadMode , ownerWriteMode , groupReadMode @@ -121,7 +123,12 @@ onLevelFile file initial action = do handleLevel :: MVar Float -> FilePath -> IO () handleLevel level file = catch action handler where - action = readFile file >>= readIO >>= swapMVar level >>= const (return ()) + action = readFile file >>= readIO . stripSpace >>= swapMVar level >>= const (return ()) handler e = if isUserError e - then readMVar level >>= \l -> writeFile file (show l) + then readMVar level >>= \l -> writeFile file (show l ++ "\n") else throw e + stripSpace = reverse . stripSpace' . reverse . stripSpace' + stripSpace' [] = [] + stripSpace' l@(x:xs) = if isSpace x + then stripSpace' xs + else l -- cgit v1.2.3