NeoMutt  2019-12-07
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 struct ConfigDef;
34 
39 {
43 };
44 
45 /* Config Set Results */
46 #define CSR_SUCCESS 0
47 #define CSR_ERR_CODE 1
48 #define CSR_ERR_UNKNOWN 2
49 #define CSR_ERR_INVALID 3
50 
51 /* Flags for CSR_SUCCESS */
52 #define CSR_SUC_INHERITED (1 << 4)
53 #define CSR_SUC_EMPTY (1 << 5)
54 #define CSR_SUC_WARNING (1 << 6)
55 #define CSR_SUC_NO_CHANGE (1 << 7)
56 
57 /* Flags for CSR_INVALID */
58 #define CSR_INV_TYPE (1 << 4)
59 #define CSR_INV_VALIDATOR (1 << 5)
60 
61 #define CSR_RESULT_MASK 0x0F
62 #define CSR_RESULT(x) ((x) & CSR_RESULT_MASK)
63 
68 {
71 };
72 
82 typedef int (*cs_validator) (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
94 typedef int (*cst_string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
105 typedef int (*cst_string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result);
115 typedef int (*cst_native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
125 typedef intptr_t(*cst_native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
126 
135 typedef int (*cst_reset) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
142 typedef void (*cst_destroy) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef);
143 
144 #define IP (intptr_t)
145 
146 #define CS_REG_DISABLED (1 << 0)
147 
153 struct ConfigDef
154 {
155  const char *name;
156  unsigned int type;
157  void *var;
158  intptr_t initial;
159  intptr_t data;
161 };
162 
169 {
170  const char *name;
177 };
178 
187 struct ConfigSet
188 {
189  struct Hash *hash;
190  struct ConfigSetType types[18];
191  struct Notify *notify;
192 };
193 
200 {
201  const struct ConfigSet *cs;
202  struct HashElem *he;
203  const char *name;
204 };
205 
206 struct ConfigSet *cs_new(size_t size);
207 void cs_init(struct ConfigSet *cs, size_t size);
208 void cs_free(struct ConfigSet **ptr);
209 
210 struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name);
211 const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
212 
213 bool cs_register_type(struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst);
214 bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags);
215 struct HashElem *cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name);
216 void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
217 
218 void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev);
219 
220 int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
221 int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
222 intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
223 int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
224 int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
225 int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
226 int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
227 
228 int cs_str_initial_get(const struct ConfigSet *cs, const char *name, struct Buffer *result);
229 int cs_str_initial_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
230 intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err);
231 int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
232 int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
233 int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
234 int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
235 
236 #endif /* MUTT_CONFIG_SET_H */
void cs_init(struct ConfigSet *cs, size_t size)
Initialise a Config Set.
Definition: set.c:183
Type definition for a config item.
Definition: set.h:168
Container for lots of config items.
Definition: set.h:187
struct Hash * hash
HashTable storing the config items.
Definition: set.h:189
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
cst_reset reset
Reset the variable to its initial, or parent, value.
Definition: set.h:175
int(* cs_validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
typedef cs_validator - Validate the "charset" config variable
Definition: set.h:82
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:553
A Hash Table.
Definition: hash.h:61
intptr_t initial
Initial value.
Definition: set.h:158
void(* cst_destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
typedef cst_destroy - Destroy a config item
Definition: set.h:142
A config-change event.
Definition: set.h:199
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:261
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:172
intptr_t data
Extra variable data.
Definition: set.h:159
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name)
Create in inherited config item.
Definition: set.c:318
int(* cst_reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
typedef cst_reset - Reset a config item to its initial value
Definition: set.h:135
int(* cst_string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
typedef cst_string_set - Set a config item by string
Definition: set.h:94
Config item definition.
Definition: set.h:153
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:721
NotifyConfig
Config notification types.
Definition: set.h:38
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
Register a set of config items.
Definition: set.c:289
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:198
struct HashElem * he
Config item that changed.
Definition: set.h:202
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:375
const struct ConfigSet * cs
Config set.
Definition: set.h:201
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:650
const char * name
User-visible name.
Definition: set.h:155
cst_native_get native_get
Get the variable&#39;s value as a C-native type.
Definition: set.h:174
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:576
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:698
int(* cst_native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
typedef cst_native_set - Set a config item by string
Definition: set.h:115
CsObserverAction
Config Observer responses.
Definition: set.h:67
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:487
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
Continue notifying observers.
Definition: set.h:69
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:171
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:171
cs_validator validator
Validator callback function.
Definition: set.h:160
int(* cst_string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
typedef cst_string_get - Get a config item as a string
Definition: set.h:105
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:827
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:173
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:627
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:446
Config item has been reset to initial, or parent, value.
Definition: set.h:41
Notification API.
Definition: notify.c:40
cst_destroy destroy
Free the resources for a variable.
Definition: set.h:176
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:772
Config item has been set.
Definition: set.h:40
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:343
void * var
Pointer to the global variable.
Definition: set.h:157
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:156
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:423
struct Notify * notify
Notifications system.
Definition: set.h:191
const char * name
Name of the type, e.g. "String".
Definition: set.h:170
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:513
Stop notifying observers.
Definition: set.h:70
intptr_t(* cst_native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
typedef cst_native_get - Get a string from a config item
Definition: set.h:125
The item stored in a Hash Table.
Definition: hash.h:42
Config item&#39;s initial value has been set.
Definition: set.h:42
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:875
const char * name
Name of config item that changed.
Definition: set.h:203
void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev)
Notify all observers of an event.
Definition: set.c:358