summaryrefslogtreecommitdiff
path: root/Hosts.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Hosts.hs')
-rw-r--r--Hosts.hs19
1 files changed, 13 insertions, 6 deletions
diff --git a/Hosts.hs b/Hosts.hs
index 8d02cc3..5f09de1 100644
--- a/Hosts.hs
+++ b/Hosts.hs
@@ -9,6 +9,7 @@ module Hosts
9 , assignName 9 , assignName
10 , assignName' 10 , assignName'
11 , assignNewName 11 , assignNewName
12 , removeName
12 , inet_pton 13 , inet_pton
13 , inet_ntop 14 , inet_ntop
14 , empty 15 , empty
@@ -184,7 +185,18 @@ cannonizeName name line = scrubName f line
184 f ws = [name," "] ++ pre ++ drop 2 rst 185 f ws = [name," "] ++ pre ++ drop 2 rst
185 where 186 where
186 (pre,rst) = break (==name) ws 187 (pre,rst) = break (==name) ws
188
189removeName name hosts = hosts'
190 where
191 hosts' = scrubTrailingEmpties (maybe hosts (removeName0 name hosts) ns)
192 ns = Map.lookup name (namenum hosts)
193
187 194
195removeName0 name hosts nums = hosts
196 { namenum = Map.delete name (namenum hosts)
197 , numline = foldl' scrub (numline hosts) nums
198 }
199 where scrub m num = Map.adjust (scrubName $ filter (/=name)) num m
188 200
189assignName' :: Bool -> SockAddr -> L.ByteString -> Hosts -> Hosts 201assignName' :: Bool -> SockAddr -> L.ByteString -> Hosts -> Hosts
190assignName' iscannon addr name hosts = hosts' 202assignName' iscannon addr name hosts = hosts'
@@ -198,7 +210,7 @@ assignName' iscannon addr name hosts = hosts'
198 else hosts { numline = foldl' canonize (numline hosts) $ fromJust ns} 210 else hosts { numline = foldl' canonize (numline hosts) $ fromJust ns}
199 else 211 else
200 let hosts0 = -- remove name if it's present 212 let hosts0 = -- remove name if it's present
201 scrubTrailingEmpties $ maybe hosts (removeName hosts) ns 213 scrubTrailingEmpties $ maybe hosts (removeName0 name hosts) ns
202 ns' = fmap (filter $ 214 ns' = fmap (filter $
203 isLonerName 215 isLonerName
204 . fromJust 216 . fromJust
@@ -212,11 +224,6 @@ assignName' iscannon addr name hosts = hosts'
212 (appendName iscannon name hosts0) 224 (appendName iscannon name hosts0)
213 a 225 a
214 in hosts1 226 in hosts1
215 removeName hosts nums = hosts
216 { namenum = Map.delete name (namenum hosts)
217 , numline = foldl' scrub (numline hosts) nums
218 }
219 where scrub m num = Map.adjust (scrubName $ filter (/=name)) num m
220 newLine hosts = hosts 227 newLine hosts = hosts
221 { lineCount = cnt 228 { lineCount = cnt
222 , numline = Map.insert cnt line $ numline hosts 229 , numline = Map.insert cnt line $ numline hosts