Verified Commit 7189a71b authored by Camil Staps's avatar Camil Staps 🐧

Bring up to date, remove unnecessary C help functions

parent e52795d4
......@@ -14,19 +14,13 @@ from Data.Maybe import ::Maybe
*/
:: *Inotify st
/**
* An inotify watch descriptor
*/
//* An inotify watch descriptor
:: INWatch
/**
* An inotify event mask
*/
//* An inotify event mask
:: INMask :== Int
/**
* An inotify event
*/
//* An inotify event
:: INEvent :== Int
/**
......@@ -36,9 +30,7 @@ from Data.Maybe import ::Maybe
*/
:: INCallback st :== INEvent (Maybe String) st *World -> *(st, *World)
/**
* Bitwise OR for event masks
*/
//* Bitwise OR for event masks
(|-) infixl 6 :: (INMask INMask -> INMask)
/**
......@@ -126,125 +118,67 @@ inotify_loop_forever :: !*(Inotify st) !*World -> *(!*Inotify st, !*World)
/*** Begin inotify.h ***/
/**
* Inotify event mask: file was accessed
*/
//* Inotify event mask: file was accessed
IN_ACCESS :== 0x00000001
/**
* Inotify event mask: file was modified
*/
//* Inotify event mask: file was modified
IN_MODIFY :== 0x00000002
/**
* Inotify event mask: metadata changed
*/
//* Inotify event mask: metadata changed
IN_ATTRIB :== 0x00000004
/**
* Inotify event mask: file opened for writing was closed
*/
//* Inotify event mask: file opened for writing was closed
IN_CLOSE_WRITE :== 0x00000008
/**
* Inotify event mask: file not opened for writing was closed
*/
//* Inotify event mask: file not opened for writing was closed
IN_CLOSE_NOWRITE :== 0x00000010
/**
* Inotify event mask: file was opened
*/
//* Inotify event mask: file was opened
IN_OPEN :== 0x00000020
/**
* Inotify event mask: file was moved from watched directory
*/
//* Inotify event mask: file was moved from watched directory
IN_MOVED_FROM :== 0x00000040
/**
* Inotify event mask: file was moved to watched directory
*/
//* Inotify event mask: file was moved to watched directory
IN_MOVED_TO :== 0x00000080
/**
* Inotify event mask: file was created in watched directory
*/
//* Inotify event mask: file was created in watched directory
IN_CREATE :== 0x00000100
/**
* Inotify event mask: file in watched directory was deleted
*/
//* Inotify event mask: file in watched directory was deleted
IN_DELETE :== 0x00000200
/**
* Inotify event mask: watched file was deleted
*/
//* Inotify event mask: watched file was deleted
IN_DELETE_SELF :== 0x00000400
/**
* Inotify event mask: watched file was moved
*/
//* Inotify event mask: watched file was moved
IN_MOVE_SELF :== 0x00000800
/**
* Inotify event mask: backing fs of watched file was unmounted
*/
//* Inotify event mask: backing fs of watched file was unmounted
IN_UNMOUNT :== 0x00002000
/**
* Inotify event mask: the inotify event queue overflowed
*/
//* Inotify event mask: the inotify event queue overflowed
IN_Q_OVERFLOW :== 0x00004000
/**
* Inotify event mask: the watch has been removed, either through
* inotify_rm_watch or because it was deleted, the fs was unmounted, etc.
*/
IN_IGNORED :== 0x00008000
/**
* Inotify event mask: watched file was closed
* @type Int
*/
IN_CLOSE :== (IN_CLOSE_WRITE |- IN_CLOSE_NOWRITE)
/**
* Inotify event mask: a file was moved from or to a watched directory
* @type Int
*/
IN_MOVE :== (IN_MOVED_FROM |- IN_MOVED_TO)
/**
* Inotify event mask: only watch the path if it is a directory
*/
//* Inotify event mask: only watch the path if it is a directory
IN_ONLYDIR :== 0x01000000
/**
* Inotify event mask: don't follow symlinks
*/
//* Inotify event mask: don't follow symlinks
IN_DONT_FOLLOW :== 0x02000000
/**
* Inotify event mask: stop watching files when they get unlinked
*/
//* Inotify event mask: stop watching files when they get unlinked
IN_EXCL_UNLINK :== 0x04000000
/**
* Inotify event mask: when adding a watch on a path for which a watch already
* exists, OR the new event mask with the old one instead of replacing it.
*/
IN_MASK_ADD :== 0x20000000
/**
* Inotify event mask: the event occurred against a directory
*/
//* Inotify event mask: the event occurred against a directory
IN_ISDIR :== 0x40000000
/**
* Inotify event mask: monitor a watch only for one event, then remove it
*/
//* Inotify event mask: monitor a watch only for one event, then remove it
IN_ONESHOT :== 0x80000000
/**
* Inotify event mask: OR of all events
* @type Int
*/
IN_ALL_EVENTS :==
(IN_ACCESS |- IN_MODIFY |- IN_ATTRIB |- IN_CLOSE_WRITE |- IN_CLOSE_NOWRITE
......
implementation module Inotify
import Data.Either
import Data.List
import Data.Maybe
import StdArray
import StdBool
import StdFunc
import StdInt
import StdList
from StdOverloaded import class zero(zero)
import StdString
from StdOverloaded import class zero(zero)
import Data.Either
import Data.List
import Data.Maybe
import System._Pointer
import System._Posix
import code from "inotify_c.o"
:: *Inotify st = { fd :: *Int
, watches :: [(INWatch, INCallback st)]
, state :: st
}
:: *Inotify st =
{ fd :: !Int
, watches :: ![(INWatch, INCallback st)]
, state :: !st
}
:: INWatch :== Int
......@@ -27,17 +29,21 @@ import code from "inotify_c.o"
inotify_init :: st -> Maybe *(Inotify st)
inotify_init st
= let fd=c_init 0 in if (fd<0) Nothing (Just {fd=fd, watches=[], state=st})
# (fd,_) = c_init 0
| fd < 0 = Nothing
# (i,_) = fcntlArg fd 00004000 0 37 // IN_NONBLOCK
| i <> i = Nothing
= Just {fd=fd, watches=[], state=st}
where
c_init :: !Int -> *Int
c_init :: !Int -> (!Int, !Int)
c_init i = code {
ccall clean_inotify_init "I:I"
ccall inotify_init ":I:I"
}
inotify_close :: *(Inotify st) -> st
inotify_close {fd,state} = c_close fd state
where
c_close :: !*Int !st -> st
c_close :: !Int !st -> st
c_close fd st = code {
ccall close "I:V:A"
}
......@@ -45,24 +51,26 @@ where
inotify_add_watch :: (INCallback st) !INMask !String !*(Inotify st)
-> *(!Either Int INWatch, !*Inotify st)
inotify_add_watch f mask fname inot=:{fd,watches}
= let (w, fd`) = c_add_watch fd fname mask in
( if (w == -1) (Left errno) (Right w)
, {inot & fd=fd`, watches=[(w,f):watches]}
)
# w = c_add_watch fd (packString fname) mask
| w == -1
# (err,inot) = errno inot
= (Left err,inot)
= (Right w, {inot & watches=[(w,f):watches]})
where
c_add_watch :: !*Int !String !Int -> *(!Int, !*Int)
c_add_watch :: !Int !String !Int -> Int
c_add_watch inot fname mask = code {
ccall clean_inotify_add_watch "ISI:VII"
ccall inotify_add_watch "IsI:I"
}
inotify_rm_watch :: !INWatch !*(Inotify st) -> *(!Bool, !*Inotify st)
inotify_rm_watch w inot=:{fd}
= case c_inotify_rm_watch fd w of (0, fd`) = (True, {inot & fd=fd`})
(_, fd`) = (False, {inot & fd=fd`})
= case c_inotify_rm_watch fd w of
0 -> (True, inot)
_ -> (False, inot)
where
c_inotify_rm_watch :: !*Int !Int -> *(!Int, !*Int)
c_inotify_rm_watch :: !Int !Int -> Int
c_inotify_rm_watch w i = code {
ccall clean_inotify_rm_watch "II:VII"
ccall inotify_rm_watch "II:I"
}
inotify_poll :: !(Maybe Int) !*(Inotify st) -> *(!Int, !*Inotify st)
......@@ -70,7 +78,7 @@ inotify_poll mbTo inot=:{fd} = let (n,fd`)=c_poll fd to in (n, {inot & fd=fd`})
where
to = if (isNothing mbTo) -1 (fromJust mbTo)
c_poll :: !*Int !Int -> *(!Int, !*Int)
c_poll :: !Int !Int -> (!Int, !Int)
c_poll fd timeout = code {
ccall clean_poll "II:VII"
}
......@@ -87,8 +95,8 @@ inotify_check inot=:{fd,watches,state} w
# (fd,st,w`) = seq (map (check infos) watches) (inot.fd, state, w)
= ({ inot & fd=fd, state=st }, w`)
where
check :: [(Int,Int,String)] (INWatch, INCallback st) *(*Int, st, *World)
-> *(*Int, st, *World)
check :: [(Int,Int,String)] (INWatch, INCallback st) *(Int, st, *World)
-> *(Int, st, *World)
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)
......@@ -114,7 +122,7 @@ where
split` c cs=:[x:xs]
= let (l,r) = span ((<>)c) cs in [l:split` c (removeMember c r)]
c_check :: !*Int -> *(!Bool, !String, !String, !String, !*Int)
c_check :: !Int -> (!Bool, !String, !String, !String, !Int)
c_check fd = code {
ccall clean_inotify_check "I:VISSSI"
}
......@@ -132,11 +140,3 @@ inotify_loop_with_timeout to inot w
inotify_loop_forever :: !*(Inotify st) !*World -> *(!*Inotify st, !*World)
inotify_loop_forever inot w = inotify_loop_with_timeout Nothing inot w
errno :: Int
errno = err 0
where
err :: !Int -> Int
err i = code {
ccall clean_errno "I:I"
}
......@@ -9,72 +9,9 @@
#include "Clean.h"
/**
* Cast a CleanString to a char*
* The result should be freed.
*/
char* clstocs(CleanString* cs) {
char* s = calloc(CleanStringLength(cs) + 1, 1);
uint8_t i;
for (i = 0; i < CleanStringLength(cs); i++)
s[i] = CleanStringCharacters(cs)[i];
s[i] = 0;
return s;
}
/** The empty string, as a CleanString */
static struct {int length; char chars[1]; } empty_string = {0,""};
/**
* Get the errno. The parameter is ignored, it is just there because ccalls
* need to have an argument.
*/
int clean_errno(int ignored) {
return errno;
}
/**
* Initialise an inotify file descriptor and change to NONBLOCK mode.
*/
int clean_inotify_init(int ignored) {
int fd;
fd = inotify_init();
if (fd < 0)
return 0;
fcntl(fd, IN_NONBLOCK);
return fd;
}
/**
* Add a watch on some file.
*
* fd The inotify file descriptor
* fname The file to watch
* mask A mask of events to watch on
* re_watch Will be set to the resulting watch descriptor
* re_fd Will be set to fd (needed for uniqueness)
*/
void clean_inotify_add_watch(int fd, CleanString* fname_, int mask,
int *re_watch, int *re_fd) {
char* fname = clstocs(fname_);
*re_watch = inotify_add_watch(fd, fname, mask);
free(fname);
*re_fd = fd;
}
/**
* Remove a watch descriptor.
*
* fd The inotify file descriptor
* watch The watch descriptor to remove
* re_code Will be set to the return code of inotify_rm_watch
* re_fd Will be set to fd (needed for uniqueness)
*/
void clean_inotify_rm_watch(int fd, int watch, int *re_code, int *re_fd) {
*re_fd = fd;
*re_code = inotify_rm_watch(fd, watch);
}
/**
* Poll an inotify file descriptor
*
......
......@@ -23,6 +23,9 @@ Global
MemoryMinimumHeapSize: 0
Time: False
Stack: False
Dynamics: False
GenericFusion: False
DescExL: False
Output
Output: NoConsole
Font: Monaco
......@@ -39,8 +42,9 @@ Global
ExportedNames:
Paths
Path: {Project}
Path: {Application}/lib/clean-platform/OS-Independent
Path: {Application}/lib/Generics
Path: {Application}*lib*Platform
OtherPaths
Path: {Application}*lib*StdEnv
Precompile:
Postlink:
MainModule
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment