summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-06-08 17:57:19 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-06-08 17:57:19 +0200
commitd33797bdb63318b219407a6eb66a4a6bc0ea5e61 (patch)
tree731088e96e40d393b8e533b4c46d6cdf61d4b258 /src
parent583ba3d2830fc6972770c60e14e382678c0b7198 (diff)
downloadtrivmix-d33797bdb63318b219407a6eb66a4a6bc0ea5e61.tar
trivmix-d33797bdb63318b219407a6eb66a4a6bc0ea5e61.tar.gz
trivmix-d33797bdb63318b219407a6eb66a4a6bc0ea5e61.tar.bz2
trivmix-d33797bdb63318b219407a6eb66a4a6bc0ea5e61.tar.xz
trivmix-d33797bdb63318b219407a6eb66a4a6bc0ea5e61.zip
Less whitespace-finecky
Diffstat (limited to 'src')
-rw-r--r--src/Trivmix.hs13
1 files changed, 10 insertions, 3 deletions
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
26 26
27import System.INotify 27import System.INotify
28 28
29import Data.Char
30
29data Options = Options 31data Options = Options
30 { input :: String 32 { input :: String
31 , output :: String 33 , output :: String
@@ -107,7 +109,7 @@ onLevelFile file initial action = do
107 exists <- doesFileExist file 109 exists <- doesFileExist file
108 let acquire = case exists of 110 let acquire = case exists of
109 True -> return () 111 True -> return ()
110 False -> createFile file mode >>= closeFd >> writeFile file (show initial) 112 False -> createFile file mode >>= closeFd >> writeFile file (show initial ++ "\n")
111 mode = foldl unionFileModes nullFileMode [ ownerReadMode 113 mode = foldl unionFileModes nullFileMode [ ownerReadMode
112 , ownerWriteMode 114 , ownerWriteMode
113 , groupReadMode 115 , groupReadMode
@@ -121,7 +123,12 @@ onLevelFile file initial action = do
121handleLevel :: MVar Float -> FilePath -> IO () 123handleLevel :: MVar Float -> FilePath -> IO ()
122handleLevel level file = catch action handler 124handleLevel level file = catch action handler
123 where 125 where
124 action = readFile file >>= readIO >>= swapMVar level >>= const (return ()) 126 action = readFile file >>= readIO . stripSpace >>= swapMVar level >>= const (return ())
125 handler e = if isUserError e 127 handler e = if isUserError e
126 then readMVar level >>= \l -> writeFile file (show l) 128 then readMVar level >>= \l -> writeFile file (show l ++ "\n")
127 else throw e 129 else throw e
130 stripSpace = reverse . stripSpace' . reverse . stripSpace'
131 stripSpace' [] = []
132 stripSpace' l@(x:xs) = if isSpace x
133 then stripSpace' xs
134 else l