fsautoproc
Basic file transformation automation management utility
Loading...
Searching...
No Matches
lcmd.h File Reference

File-specific system command execution mapping functions. More...

#include <regex.h>
#include <stdbool.h>
#include <stdint.h>
#include "sl.h"
Include dependency graph for lcmd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lcmdset_s
 A set of system commands to execute when a file event of a specific type and file path is triggered. More...
 

Macros

#define LCTRIG_NEW   (1 << 0)
 Trigger bit flag for new file events.
 
#define LCTRIG_MOD   (1 << 1)
 Trigger bit flag for modified file events.
 
#define LCTRIG_DEL   (1 << 2)
 Trigger bit flag for deleted file events.
 
#define LCTRIG_NOP   (1 << 3)
 Trigger bit flag for no operation/unmodified file events.
 
#define LCTRIG_ALL   (LCTRIG_NEW | LCTRIG_MOD | LCTRIG_DEL | LCTRIG_NOP)
 Trigger bit flag for all file events.
 
#define LCTOPT_TRACE   (1 << 7)
 Option bit flag for tracing command set matches by printing to stdout.
 
#define LCTOPT_VERBOSE   (1 << 8)
 Option bit flag for printing commands to stdout before execution.
 

Functions

void lcmdfree_r (struct lcmdset_s **cs)
 Iterates and frees all memory allocated by the command set array.
 
struct lcmdset_s ** lcmdparse (const char *fp)
 Prses the provided file path and populates an array of command sets. The file must be a valid JSON file containing an array of objects. Each object must contain the following keys:
 
bool lcmdmatchany (struct lcmdset_s **cs, const char *fp)
 Checks if the provided file path matches any of the file patterns in the command set.
 
int lcmdexec (struct lcmdset_s **cs, const struct inode_s *node, const struct fdset_s *fds, int flags)
 Sequentially iterates the command set and executes the configured system commands on the provided file node if the trigger flags and file patterns match.
 

Detailed Description

File-specific system command execution mapping functions.

Macro Definition Documentation

◆ LCTOPT_TRACE

#define LCTOPT_TRACE   (1 << 7)

Option bit flag for tracing command set matches by printing to stdout.

◆ LCTOPT_VERBOSE

#define LCTOPT_VERBOSE   (1 << 8)

Option bit flag for printing commands to stdout before execution.

◆ LCTRIG_ALL

#define LCTRIG_ALL   (LCTRIG_NEW | LCTRIG_MOD | LCTRIG_DEL | LCTRIG_NOP)

Trigger bit flag for all file events.

◆ LCTRIG_DEL

#define LCTRIG_DEL   (1 << 2)

Trigger bit flag for deleted file events.

◆ LCTRIG_MOD

#define LCTRIG_MOD   (1 << 1)

Trigger bit flag for modified file events.

◆ LCTRIG_NEW

#define LCTRIG_NEW   (1 << 0)

Trigger bit flag for new file events.

◆ LCTRIG_NOP

#define LCTRIG_NOP   (1 << 3)

Trigger bit flag for no operation/unmodified file events.

Function Documentation

◆ lcmdexec()

int lcmdexec ( struct lcmdset_s ** cs,
const struct inode_s * node,
const struct fdset_s * fds,
int flags )

Sequentially iterates the command set and executes the configured system commands on the provided file node if the trigger flags and file patterns match.

Parameters
csThe command set array to filter and execute
nodeThe file node to execute on
fdsThe file descriptor set to use for stdout/stderr redirection
flagsThe trigger flags to match, see LCTRIG_*. If LCTOPT_VERBOSE is set, the commands will be printed to stdout before execution. If LCTOPT_TRACE is set, the true/false match result for each command set will be printed to stdout.
Returns
0 if successful, otherwise the first non-zero return value from system(3) is returned.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcmdfree_r()

void lcmdfree_r ( struct lcmdset_s ** cs)

Iterates and frees all memory allocated by the command set array.

Parameters
csThe command set array to free
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcmdmatchany()

bool lcmdmatchany ( struct lcmdset_s ** cs,
const char * fp )

Checks if the provided file path matches any of the file patterns in the command set.

Parameters
csThe command set array to filter
fpThe file path to match
Returns
true if the file path matches any file pattern, otherwise false
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcmdparse()

struct lcmdset_s ** lcmdparse ( const char * fp)

Prses the provided file path and populates an array of command sets. The file must be a valid JSON file containing an array of objects. Each object must contain the following keys:

  • on: An array of trigger flags to match
  • patterns: An array of file patterns to match
  • commands: An array of system commands to execute The on array must contain one or more of the following strings:
  • new: Trigger on new files
  • mod: Trigger on modified files
  • del: Trigger on deleted files
  • nop: Trigger on no operation The patterns array must contain one or more strings that are used to match the file path. The commands array must contain one or more strings that are passed to system(3) for execution.
    Parameters
    fpThe file path to parse
    Returns
    An array of command sets if successful, otherwise NULL.
Here is the call graph for this function:
Here is the caller graph for this function: