NeoMutt  2020-06-26-89-g172cd3
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 
56 #define CS_REG_DISABLED (1 << 0)
57 
63 struct ConfigDef
64 {
65  const char *name;
66  unsigned int type;
67  void *var;
68  intptr_t initial;
69  intptr_t data;
70 
80  int (*validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
81 };
82 
89 {
90  const char *name;
91 
107  int (*string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
108 
124  int (*string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result);
125 
140  int (*native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
141 
156  intptr_t (*native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
157 
172  int (*string_plus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
173 
188  int (*string_minus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
189 
203  int (*reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
204 
216  void (*destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef);
217 };
218 
227 struct ConfigSet
228 {
229  struct HashTable *hash;
230  struct ConfigSetType types[18];
231 };
232 
233 struct ConfigSet *cs_new(size_t size);
234 void cs_free(struct ConfigSet **ptr);
235 
236 struct HashElem * cs_get_base (struct HashElem *he);
237 struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
238 const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
239 
240 bool cs_register_type (struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst);
241 bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags);
242 struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *parent, const char *name);
243 void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
244 
245 int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
246 int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
247 intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
248 int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
249 int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
250 int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
251 int cs_he_string_minus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
252 int cs_he_string_plus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
253 int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
254 
255 int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
256 int cs_str_initial_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
257 intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err);
258 int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
259 int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
260 int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
261 int cs_str_string_minus_equals(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
262 int cs_str_string_plus_equals (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
263 int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
264 
265 #endif /* MUTT_CONFIG_SET_H */
Type definition for a config item.
Definition: set.h:88
Container for lots of config items.
Definition: set.h:227
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:229
A Hash Table.
Definition: hash.h:84
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:522
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
intptr_t initial
Initial value.
Definition: set.h:68
String manipulation buffer.
Definition: buffer.h:33
bool cs_register_type(struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst)
Register a type of config item.
Definition: set.c:251
intptr_t data
Extra variable data.
Definition: set.h:69
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name)
Create in inherited config item.
Definition: set.c:308
Config item definition.
Definition: set.h:63
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:860
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:687
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
Register a set of config items.
Definition: set.c:279
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:172
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:348
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:620
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:919
const char * name
User-visible name.
Definition: set.h:65
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:545
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:664
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:460
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:229
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:206
int(* validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate a config variable.
Definition: set.h:80
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:158
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:943
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:792
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:597
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:418
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:739
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:333
void * var
Pointer to the global variable.
Definition: set.h:67
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:1002
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:66
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:395
const char * name
Name of the type, e.g. "String".
Definition: set.h:90
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:486
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:191
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:843