diff options
Diffstat (limited to 'Inotify.icl')
-rw-r--r-- | Inotify.icl | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/Inotify.icl b/Inotify.icl index 20ce3e9..e676f03 100644 --- a/Inotify.icl +++ b/Inotify.icl @@ -1,6 +1,7 @@ implementation module Inotify import Data.Either +import Data.List import Data.Maybe import StdArray @@ -74,22 +75,25 @@ where inotify_check :: *(Inotify st) *World -> *(*Inotify st, *World) inotify_check inot=:{fd,watches,state} w - # (ok, wds, masks, fd) = c_check fd + # (ok, wds, masks, fnames, fd) = c_check fd inot = { inot & fd=fd } | not ok = (inot, w) | (size wds) rem 4 <> 0 || (size masks) rem 4 <> 0 = (inot,w) - # (wds,masks) = (split 4 wds, split 4 masks) + # (wds,masks,fnames) = (split 4 wds, split 4 masks, splitOn '\0' fnames) | length wds <> length masks = (inot, w) - # wdsmasks = zip2 (map bytesToInt wds) (map bytesToInt masks) - # (fd,st,w`) = seq (map (check wdsmasks) watches) (inot.fd, state, w) + # infos = zip3 (map bytesToInt wds) (map bytesToInt masks) fnames + # (fd,st,w`) = seq (map (check infos) watches) (inot.fd, state, w) = ({ inot & fd=fd, state=st }, w`) where - check :: [(Int,Int)] (INWatch, INCallback st) *(*Int, st, *World) + check :: [(Int,Int,String)] (INWatch, INCallback st) *(*Int, st, *World) -> *(*Int, st, *World) - check wdsmasks (watch,f) (fd,st,w) - # (st,w) = seq [\(st,w) -> f mask st w - \\ (wd,mask) <- wdsmasks | wd == watch] (st,w) + check infos (watch,f) (fd,st,w) + # (st,w) = seq [\(st,w) -> f mask (toMaybe name) st w + \\ (wd,mask,name) <- infos | wd == watch] (st,w) = (fd,st,w) + where + toMaybe :: String -> Maybe String + toMaybe s = if (s=="") Nothing (Just s) bytesToInt :: {#Char} -> Int bytesToInt cs = sum [toInt c * (8 ^ p) \\ c <-: cs & p <- [0..]] @@ -99,12 +103,26 @@ where | size s > n = [s % (0,n-1) : split n (s % (n, size s - 1))] | size s == n = [s] | s == "" = [] + + splitOn :: Char String -> [String] + splitOn c s = map toString (split` c [c \\ c <-: s]) + where + split` :: Char [Char] -> [[Char]] + split` c [] = [] + split` c cs=:[x:xs] + = let (l,r) = span ((<>)c) cs in [l:split` c (removeMember c r)] - c_check :: !*Int -> *(!Bool, !String, !String, !*Int) + c_check :: !*Int -> *(!Bool, !String, !String, !String, !*Int) c_check fd = code { - ccall clean_inotify_check "I:VISSI" + ccall clean_inotify_check "I:VISSSI" } +inotify_loop_forever :: *(Inotify st) *World -> *(*Inotify st, *World) +inotify_loop_forever inot w + # inot = inotify_poll inot + # (inot,w) = inotify_check inot w + = inotify_loop_forever inot w + errno :: Int errno = err 0 where |