NeoMutt  2019-12-07-60-g0cfa53
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 #include "subset.h"
30 
31 struct Buffer;
32 struct ConfigSet;
33 struct HashElem;
34 struct ConfigDef;
35 
36 /* Config Set Results */
37 #define CSR_SUCCESS 0
38 #define CSR_ERR_CODE 1
39 #define CSR_ERR_UNKNOWN 2
40 #define CSR_ERR_INVALID 3
41 
42 /* Flags for CSR_SUCCESS */
43 #define CSR_SUC_INHERITED (1 << 4)
44 #define CSR_SUC_EMPTY (1 << 5)
45 #define CSR_SUC_WARNING (1 << 6)
46 #define CSR_SUC_NO_CHANGE (1 << 7)
47 
48 /* Flags for CSR_INVALID */
49 #define CSR_INV_TYPE (1 << 4)
50 #define CSR_INV_VALIDATOR (1 << 5)
51 
52 #define CSR_RESULT_MASK 0x0F
53 #define CSR_RESULT(x) ((x) & CSR_RESULT_MASK)
54 
64 typedef int (*cs_validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
76 typedef int (*cst_string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
87 typedef int (*cst_string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result);
97 typedef int (*cst_native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
107 typedef intptr_t (*cst_native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
116 typedef int (*cst_reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
123 typedef void (*cst_destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef);
124 
125 #define IP (intptr_t)
126 
127 #define CS_REG_DISABLED (1 << 0)
128 
134 struct ConfigDef
135 {
136  const char *name;
137  unsigned int type;
138  void *var;
139  intptr_t initial;
140  intptr_t data;
142 };
143 
150 {
151  const char *name;
158 };
159 
168 struct ConfigSet
169 {
170  struct Hash *hash;
171  struct ConfigSetType types[18];
172 };
173 
174 struct ConfigSet *cs_new(size_t size);
175 void cs_free(struct ConfigSet **ptr);
176 
177 struct HashElem * cs_get_base (struct HashElem *he);
178 struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
179 const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
180 
181 bool cs_register_type (struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst);
182 bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags);
183 struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *parent, const char *name);
184 void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
185 
186 int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
187 int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
188 intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
189 int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
190 int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
191 int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
192 int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
193 
194 int cs_str_initial_get(const struct ConfigSet *cs, const char *name, struct Buffer *result);
195 int cs_str_initial_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
196 intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err);
197 int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
198 int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
199 int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
200 int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
201 
202 #endif /* MUTT_CONFIG_SET_H */
Type definition for a config item.
Definition: set.h:149
Container for lots of config items.
Definition: set.h:168
struct Hash * hash
HashTable storing the config items.
Definition: set.h:170
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:225
cst_reset reset
Reset the variable to its initial, or parent, value.
Definition: set.h:156
int(* cs_validator)(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
typedef cs_validator - Validate a config variable
Definition: set.h:64
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:519
A Hash Table.
Definition: hash.h:61
intptr_t initial
Initial value.
Definition: set.h:139
void(* cst_destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
typedef cst_destroy - Destroy a config item
Definition: set.h:123
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:247
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:153
intptr_t data
Extra variable data.
Definition: set.h:140
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name)
Create in inherited config item.
Definition: set.c:304
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:116
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:76
Config item definition.
Definition: set.h:134
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_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
Register a set of config items.
Definition: set.c:275
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:168
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:344
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:614
const char * name
User-visible name.
Definition: set.h:136
cst_native_get native_get
Get the variable&#39;s value as a C-native type.
Definition: set.h:155
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:542
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(* 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:97
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:453
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:202
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:154
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:152
cs_validator validator
Validator callback function.
Definition: set.h:141
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:87
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:787
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:154
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:591
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:413
cst_destroy destroy
Free the resources for a variable.
Definition: set.h:157
Subset of Config Items.
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:734
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:329
void * var
Pointer to the global variable.
Definition: set.h:138
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:137
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:390
const char * name
Name of the type, e.g. "String".
Definition: set.h:151
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:479
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:107
The item stored in a Hash Table.
Definition: hash.h:42
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:187
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:835