fsautoproc
Basic file transformation automation management utility
Loading...
Searching...
No Matches
lcmd.h
Go to the documentation of this file.
1
3#ifndef FSAUTOPROC_LCMD_H
4#define FSAUTOPROC_LCMD_H
5
6#include <regex.h>
7#include <stdbool.h>
8#include <stdint.h>
9
10#include "set.h"
11
12struct fdset_s;
13
16#define LCTRIG_NEW (1 << 0)
17
20#define LCTRIG_MOD (1 << 1)
21
24#define LCTRIG_DEL (1 << 2)
25
28#define LCTRIG_ALL (LCTRIG_NEW | LCTRIG_MOD | LCTRIG_DEL)
29
32#define LCTOPT_TRACE (1 << 7)
33
36#define LCTOPT_VERBOSE (1 << 8)
37
40struct reg_t {
41 regex_t reg;
42 _Bool compiled : 1;
43};
44
45DEFINE_SET_TYPE(regex_set, struct reg_t)
46
47DEFINE_SET_TYPE(str_set, char*)
48
49
52struct lcmdset_s {
53 int onflags;
54 regex_set* fpatterns;
55 str_set* syscmds;
56 char* name;
57 _Atomic uint64_t msspent;
58};
59
60DEFINE_SET_TYPE(lcmdset_set, struct lcmdset_s)
61
62
64void lcmdfree_r(lcmdset_set* cs);
65
81lcmdset_set* lcmdparse(const char* fp);
82
88bool lcmdmatchany(lcmdset_set* cs, const char* fp);
89
102int lcmdexec(lcmdset_set* cs, const char* fp, struct fdset_s fds, int flags);
103
104#endif//FSAUTOPROC_LCMD_H
int lcmdexec(lcmdset_set *cs, const char *fp, struct fdset_s fds, int flags)
Sequentially iterates the command set and executes the configured system commands on the provided fil...
Definition lcmd.c:354
lcmdset_set * lcmdparse(const char *fp)
Parses the provided file path and populates an array of command sets. The file must be a valid JSON f...
Definition lcmd.c:210
void lcmdfree_r(lcmdset_set *cs)
Iterates and frees all memory allocated by the command set array.
Definition lcmd.c:67
bool lcmdmatchany(lcmdset_set *cs, const char *fp)
Checks if the provided file path matches any of the file patterns in the command set.
Definition lcmd.c:262
#define DEFINE_SET_TYPE(typ, inner)
Defines a set type containing an array of the specified inner type.
Definition set.h:8
A set of file descriptors for redirecting writes to stdout and stderr from child processes to log fil...
Definition fd.h:9
A set of system commands to execute when a file event of a specific type and file path is triggered.
Definition lcmd.h:52
regex_set * fpatterns
Compiled patterns used for file path matching.
Definition lcmd.h:54
str_set * syscmds
Commands to pass to system(3)
Definition lcmd.h:55
char * name
Command set name or description for logging.
Definition lcmd.h:56
int onflags
Command set trigger bit flags.
Definition lcmd.h:53
_Atomic uint64_t msspent
Sum milliseconds spent executing commands.
Definition lcmd.h:57
Wrapper struct for a regex pattern and its compile metadata.
Definition lcmd.h:40
_Bool compiled
Indicates if the regex was successfully compiled.
Definition lcmd.h:42
regex_t reg
Compiled regex pattern.
Definition lcmd.h:41