NeoMutt  2021-02-05-666-ge300cd
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 
63 struct ConfigDef
64 {
65  const char *name;
66  uint32_t type;
67  intptr_t initial;
68  intptr_t data;
69 
82  int (*validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
83 
84  const char *docs;
85  intptr_t var;
86 };
87 
96 {
97  int type;
98  const char *name;
99 
118  int (*string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
119 
138  int (*string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result);
139 
157  int (*native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
158 
176  intptr_t (*native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
177 
195  int (*string_plus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
196 
214  int (*string_minus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
215 
232  int (*reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
233 
248  void (*destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef);
249 };
250 
259 struct ConfigSet
260 {
261  struct HashTable *hash;
262  struct ConfigSetType types[18];
263 };
264 
265 struct ConfigSet *cs_new(size_t size);
266 void cs_free(struct ConfigSet **ptr);
267 
268 struct HashElem * cs_get_base (struct HashElem *he);
269 struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
270 const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
271 
272 bool cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst);
273 bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags);
274 struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *parent, const char *name);
275 void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
276 
277 int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
278 int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
279 intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
280 int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
281 int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
282 int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
283 int cs_he_string_minus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
284 int cs_he_string_plus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
285 int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
286 
287 int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
288 int cs_str_initial_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
289 intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err);
290 int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
291 int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
292 int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
293 int cs_str_string_minus_equals(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
294 int cs_str_string_plus_equals (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
295 int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
296 
297 #endif /* MUTT_CONFIG_SET_H */
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:520
Container for lots of config items.
Definition: set.h:259
int type
Data type, e.g. DT_STRING.
Definition: set.h:97
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:841
A Hash Table.
Definition: hash.h:87
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:276
const char * docs
One-liner description.
Definition: set.h:84
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:543
intptr_t initial
Initial value.
Definition: set.h:67
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:416
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:331
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:618
intptr_t data
Extra variable data.
Definition: set.h:68
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:170
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:156
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:204
Definition: set.h:63
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name)
Create in inherited config item.
Definition: set.c:306
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:790
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:662
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:685
bool cs_register_type(struct ConfigSet *cs, const struct ConfigSetType *cst)
Register a type of config item.
Definition: set.c:248
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:346
const char * name
User-visible name.
Definition: set.h:65
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:261
int(* validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:82
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:595
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:227
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:393
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
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:458
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:941
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:917
intptr_t var
Storage for the variable.
Definition: set.h:85
const char * name
Name of the type, e.g. "String".
Definition: set.h:98
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:484
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:189
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:1000
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:737
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:858