NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "mutt/lib.h"
30#include "types.h"
31
32struct ConfigSet;
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
117 int (*string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
118
136 int (*string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result);
137
154 int (*native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
155
172 intptr_t (*native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
173
190 int (*string_plus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
191
208 int (*string_minus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
209
225 int (*reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err);
226
240 void (*destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef);
241};
242
252{
253 struct HashTable *hash;
254 struct ConfigSetType types[18];
255};
256
257struct ConfigSet *cs_new(size_t size);
258void cs_free(struct ConfigSet **ptr);
259
260struct HashElem * cs_get_base (struct HashElem *he);
261struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
262const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
263
264bool cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst);
265struct HashElem *cs_register_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err);
266bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[]);
267struct HashElem *cs_create_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err);
268struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *he_parent, const char *name);
269void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
270
271int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
272int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
273intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
274int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
275int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
276int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
277int cs_he_string_minus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
278int cs_he_string_plus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
279int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
280int cs_he_delete (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
281
282int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
283int cs_str_initial_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
284int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
285int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
286int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
287
288extern bool StartupComplete;
289
296static inline bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
297{
298 if ((cdef->type & D_ON_STARTUP) && StartupComplete)
299 {
300 buf_printf(err, _("Option %s may only be set at startup"), cdef->name);
301 return true;
302 }
303
304 return false;
305}
306
307#endif /* MUTT_CONFIG_SET_H */
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
static bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
Validator function for D_ON_STARTUP.
Definition: set.h:296
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:565
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:175
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:503
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:864
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:141
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:438
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:127
struct HashElem * cs_create_variable(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Create and register one config item.
Definition: set.c:318
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:391
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:198
int cs_he_delete(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Delete config item from a config set.
Definition: set.c:981
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:640
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:588
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:760
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
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:708
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:813
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *he_parent, const char *name)
Create in inherited config item.
Definition: set.c:347
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[])
Register a set of config items.
Definition: set.c:281
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:663
bool StartupComplete
When the config has been read.
Definition: main.c:189
struct HashElem * cs_register_variable(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Register one config item.
Definition: set.c:249
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:461
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:529
bool cs_register_type(struct ConfigSet *cs, const struct ConfigSetType *cst)
Register a type of config item.
Definition: set.c:219
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:923
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:376
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
String manipulation buffer.
Definition: buffer.h:36
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:136
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:154
int(* string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:117
int(* string_plus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:190
int(* string_minus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:208
int(* reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition: set.h:225
void(* destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Definition: set.h:240
intptr_t(* native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition: set.h:172
const char * name
Name of the type, e.g. "String".
Definition: set.h:98
Container for lots of config items.
Definition: set.h:252
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:254
struct HashTable * hash
Hash Table: "$name" -> ConfigDef.
Definition: set.h:253
The item stored in a Hash Table.
Definition: hash.h:43
A Hash Table.
Definition: hash.h:97
Constants for all the config types.
#define D_ON_STARTUP
May only be set at startup.
Definition: types.h:79