NeoMutt  2022-04-29-249-gaae397
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
30struct Buffer;
31struct ConfigSet;
32struct 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
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
260{
261 struct HashTable *hash;
262 struct ConfigSetType types[18];
263};
264
265struct ConfigSet *cs_new(size_t size);
266void cs_free(struct ConfigSet **ptr);
267
268struct HashElem * cs_get_base (struct HashElem *he);
269struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
270const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
271
272bool cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst);
273bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags);
274struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *parent, const char *name);
275void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
276
277int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
278int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
279intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
280int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
281int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
282int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
283int cs_he_string_minus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
284int cs_he_string_plus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
285int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
286
287int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
288int cs_str_initial_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
289intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err);
290int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
291int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
292int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
293int cs_str_string_minus_equals(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
294int cs_str_string_plus_equals (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
295int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
296
297#endif /* MUTT_CONFIG_SET_H */
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:276
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
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:204
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_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
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:170
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
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:156
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 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_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
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
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
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_str_string_get(const struct ConfigSet *cs, const char *name, struct Buffer *result)
Get a config item as a string.
Definition: set.c:662
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
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
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
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
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name)
Create in inherited config item.
Definition: set.c:306
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
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
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
bool cs_register_type(struct ConfigSet *cs, const struct ConfigSetType *cst)
Register a type of config item.
Definition: set.c:248
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_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
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:34
Definition: set.h:64
const char * name
User-visible name.
Definition: set.h:65
intptr_t var
Storage for the variable.
Definition: set.h:85
int(* validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:82
intptr_t data
Extra variable data.
Definition: set.h:68
intptr_t initial
Initial value.
Definition: set.h:67
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
const char * docs
One-liner description.
Definition: set.h:84
int(* string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Definition: set.h:138
int type
Data type, e.g. DT_STRING.
Definition: set.h:97
int(* native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:157
int(* string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:118
int(* string_plus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:195
int(* string_minus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:214
int(* reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition: set.h:232
void(* destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Definition: set.h:248
intptr_t(* native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition: set.h:176
const char * name
Name of the type, e.g. "String".
Definition: set.h:98
Container for lots of config items.
Definition: set.h:260
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:262
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:261
The item stored in a Hash Table.
Definition: hash.h:44
A Hash Table.
Definition: hash.h:97