NeoMutt  2020-09-25
Teaching an old dog new tricks
DOXYGEN
set.h
Go to the documentation of this file.
1 
23 #ifndef MUTT_CONFIG_SET_H
24 #define MUTT_CONFIG_SET_H
25 
26 #include <stdbool.h>
27 #include <stdint.h>
28 #include <stdio.h>
29 
30 struct Buffer;
31 struct ConfigSet;
32 struct HashElem;
33 
34 /* Config Set Results */
35 #define CSR_SUCCESS 0
36 #define CSR_ERR_CODE 1
37 #define CSR_ERR_UNKNOWN 2
38 #define CSR_ERR_INVALID 3
39 
40 /* Flags for CSR_SUCCESS */
41 #define CSR_SUC_INHERITED (1 << 4)
42 #define CSR_SUC_EMPTY (1 << 5)
43 #define CSR_SUC_WARNING (1 << 6)
44 #define CSR_SUC_NO_CHANGE (1 << 7)
45 
46 /* Flags for CSR_INVALID */
47 #define CSR_INV_TYPE (1 << 4)
48 #define CSR_INV_VALIDATOR (1 << 5)
49 #define CSV_INV_NOT_IMPL (1 << 6)
50 
51 #define CSR_RESULT_MASK 0x0F
52 #define CSR_RESULT(x) ((x) & CSR_RESULT_MASK)
53 
54 #define IP (intptr_t)
55 
61 struct ConfigDef
62 {
63  const char *name;
64  unsigned int type;
65  void *var;
66  intptr_t initial;
67  intptr_t data;
68 
78  int (*validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
79 
80  const char *docs;
81 };
82 
89 {
90  int type;
91  const char *name;
92 
108  int (*string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
109 
125  int (*string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result);
126 
141  int (*native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
142 
157  intptr_t (*native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
158 
173  int (*string_plus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
174 
189  int (*string_minus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
190 
204  int (*reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
205 
217  void (*destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef);
218 };
219 
228 struct ConfigSet
229 {
230  struct HashTable *hash;
231  struct ConfigSetType types[18];
232 };
233 
234 struct ConfigSet *cs_new(size_t size);
235 void cs_free(struct ConfigSet **ptr);
236 
237 struct HashElem * cs_get_base (struct HashElem *he);
238 struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
239 const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
240 
241 bool cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst);
242 bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags);
243 struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *parent, const char *name);
244 void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
245 
246 int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
247 int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
248 intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
249 int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
250 int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
251 int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
252 int cs_he_string_minus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
253 int cs_he_string_plus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
254 int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
255 
256 int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
257 int cs_str_initial_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
258 intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err);
259 int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
260 int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
261 int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
262 int cs_str_string_minus_equals(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
263 int cs_str_string_plus_equals (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
264 int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
265 
266 #endif /* MUTT_CONFIG_SET_H */
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
Register a set of config items.
Definition: set.c:286
Type definition for a config item.
Definition: set.h:88
int cs_str_initial_get(const struct ConfigSet *cs, const char *name, struct Buffer *result)
Get the initial, or parent, value of a config item.
Definition: set.c:535
Container for lots of config items.
Definition: set.h:228
int type
Data type, e.g. DT_STRING.
Definition: set.h:90
intptr_t cs_str_native_get(const struct ConfigSet *cs, const char *name, struct Buffer *err)
Natively get the value of a string config item.
Definition: set.c:871
A Hash Table.
Definition: hash.h:84
const char * docs
One-liner description.
Definition: set.h:80
int cs_he_string_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.c:558
intptr_t initial
Initial value.
Definition: set.h:66
int cs_he_initial_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set the initial value of a config item.
Definition: set.c:431
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:341
String manipulation buffer.
Definition: buffer.h:33
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: set.c:636
intptr_t data
Extra variable data.
Definition: set.h:67
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:180
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:166
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
Config item definition.
Definition: set.h:61
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name)
Create in inherited config item.
Definition: set.c:316
intptr_t cs_he_native_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Natively get the value of a HashElem config item.
Definition: set.c:817
int cs_str_string_get(const struct ConfigSet *cs, const char *name, struct Buffer *result)
Get a config item as a string.
Definition: set.c:683
int cs_he_native_set(const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err)
Natively set the value of a HashElem config item.
Definition: set.c:706
bool cs_register_type(struct ConfigSet *cs, const struct ConfigSetType *cst)
Register a type of config item.
Definition: set.c:258
int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:356
const char * name
User-visible name.
Definition: set.h:63
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:230
int(* validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate a config variable.
Definition: set.h:78
int cs_str_string_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.c:613
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
int cs_str_reset(const struct ConfigSet *cs, const char *name, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:408
int cs_str_initial_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Set the initial value of a config item.
Definition: set.c:473
int cs_he_string_minus_equals(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Remove from a config item by string.
Definition: set.c:974
void * var
Pointer to the global variable.
Definition: set.h:65
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
int cs_str_string_plus_equals(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Add to a config item by string.
Definition: set.c:950
const char * name
Name of the type, e.g. "String".
Definition: set.h:91
int cs_he_initial_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get the initial, or parent, value of a config item.
Definition: set.c:499
The item stored in a Hash Table.
Definition: hash.h:43
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
int cs_str_string_minus_equals(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Remove from a config item by string.
Definition: set.c:1036
static void destroy(int type, void *obj, intptr_t data)
Callback function for the Hash Table - Implements hash_hdata_free_t.
Definition: set.c:47
int cs_str_native_set(const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: set.c:761
int cs_he_string_plus_equals(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Add to a config item by string.
Definition: set.c:888