diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-08 17:57:19 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-08 17:57:19 +0200 |
commit | d33797bdb63318b219407a6eb66a4a6bc0ea5e61 (patch) | |
tree | 731088e96e40d393b8e533b4c46d6cdf61d4b258 /src | |
parent | 583ba3d2830fc6972770c60e14e382678c0b7198 (diff) | |
download | trivmix-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.hs | 13 |
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 | ||
27 | import System.INotify | 27 | import System.INotify |
28 | 28 | ||
29 | import Data.Char | ||
30 | |||
29 | data Options = Options | 31 | data 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 | |||
121 | handleLevel :: MVar Float -> FilePath -> IO () | 123 | handleLevel :: MVar Float -> FilePath -> IO () |
122 | handleLevel level file = catch action handler | 124 | handleLevel 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 | ||