NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
module.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdbool.h>
31#include <stddef.h>
32#include "private.h"
33#include "mutt/lib.h"
34#include "config/lib.h"
35#include "core/lib.h"
36#include "module_data.h"
37
38extern struct ConfigDef PatternVars[];
39
43static bool pattern_init(struct NeoMutt *n)
44{
45 struct PatternModuleData *mod_data = MUTT_MEM_CALLOC(1, struct PatternModuleData);
46
47 // clang-format off
48 mod_data->range_regexes[RANGE_K_REL] = (struct RangeRegex){ RANGE_REL_RX, 1, 3, 0, { 0 } };
49 mod_data->range_regexes[RANGE_K_ABS] = (struct RangeRegex){ RANGE_ABS_RX, 1, 3, 0, { 0 } };
50 mod_data->range_regexes[RANGE_K_LT] = (struct RangeRegex){ RANGE_LT_RX, 1, 2, 0, { 0 } };
51 mod_data->range_regexes[RANGE_K_GT] = (struct RangeRegex){ RANGE_GT_RX, 2, 1, 0, { 0 } };
52 mod_data->range_regexes[RANGE_K_BARE] = (struct RangeRegex){ RANGE_BARE_RX, 1, 1, 0, { 0 } };
53 // clang-format on
54
56
57 mod_data->notify = notify_new();
58 notify_set_parent(mod_data->notify, n->notify);
59
60 return true;
61}
62
66static bool pattern_config_define_variables(struct NeoMutt *n, struct ConfigSet *cs)
67{
69}
70
74static bool pattern_cleanup(struct NeoMutt *n, void *data)
75{
76 struct PatternModuleData *mod_data = data;
77
78 notify_free(&mod_data->notify);
79
80 for (int i = 0; i < RANGE_K_INVALID; i++)
81 {
82 if (mod_data->range_regexes[i].ready)
83 regfree(&mod_data->range_regexes[i].cooked);
84 }
85
86 FREE(&mod_data);
87 return true;
88}
89
93const struct Module ModulePattern = {
95 "pattern",
97 NULL, // config_define_types
99 NULL, // commands_register
100 NULL, // gui_init
101 NULL, // gui_cleanup
103};
Convenience wrapper for the config headers.
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[])
Register a set of config items.
Definition set.c:290
Convenience wrapper for the core headers.
const struct Module ModulePattern
Module for the Pattern library.
Definition module.c:93
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
@ MODULE_ID_PATTERN
ModulePattern, Pattern
Definition module_api.h:85
Convenience wrapper for the library headers.
struct Notify * notify_new(void)
Create a new notifications handler.
Definition notify.c:62
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
void neomutt_set_module_data(struct NeoMutt *n, enum ModuleId id, void *data)
Set the private data for a Module.
Definition neomutt.c:677
struct ConfigDef PatternVars[]
Config definitions for the pattern library.
Definition config.c:57
static bool pattern_config_define_variables(struct NeoMutt *n, struct ConfigSet *cs)
Define the Config Variables - Implements Module::config_define_variables()
Definition module.c:66
static bool pattern_cleanup(struct NeoMutt *n, void *data)
Clean up a Module - Implements Module::cleanup()
Definition module.c:74
static bool pattern_init(struct NeoMutt *n)
Initialise a Module - Implements Module::init()
Definition module.c:43
Pattern private Module data.
Shared constants/structs that are private to libpattern.
#define RANGE_GT_RX
Regex for greater-than range (e.g., ">50")
Definition private.h:117
#define RANGE_ABS_RX
Regex for absolute range (e.g., "1-5")
Definition private.h:112
#define RANGE_LT_RX
Regex for less-than range (e.g., "<100")
Definition private.h:115
#define RANGE_BARE_RX
Regex for bare number range.
Definition private.h:120
#define RANGE_REL_RX
Regex for relative range (e.g., "1,5" or "-3,.")
Definition private.h:107
@ RANGE_K_REL
Relative range.
Definition private.h:93
@ RANGE_K_ABS
Absolute range.
Definition private.h:94
@ RANGE_K_LT
Less-than range.
Definition private.h:95
@ RANGE_K_INVALID
Range is invalid.
Definition private.h:99
@ RANGE_K_BARE
Single symbol.
Definition private.h:97
@ RANGE_K_GT
Greater-than range.
Definition private.h:96
Container for lots of config items.
Definition set.h:251
Container for Accounts, Notifications.
Definition neomutt.h:41
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
Pattern private Module data.
Definition module_data.h:32
struct Notify * notify
Notifications.
Definition module_data.h:33
struct RangeRegex range_regexes[RANGE_K_INVALID]
Set of Regexes for various range types.
Definition module_data.h:34
Regular expression representing a range.
Definition private.h:80
regex_t cooked
Compiled form.
Definition private.h:85
bool ready
Compiled yet?
Definition private.h:84