NeoMutt  2025-01-09-117-gace867
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
32/* Config Set Results */
33#define CSR_SUCCESS 0
34#define CSR_ERR_CODE 1
35#define CSR_ERR_UNKNOWN 2
36#define CSR_ERR_INVALID 3
37
38/* Flags for CSR_SUCCESS */
39#define CSR_SUC_INHERITED (1 << 4)
40#define CSR_SUC_EMPTY (1 << 5)
41#define CSR_SUC_WARNING (1 << 6)
42#define CSR_SUC_NO_CHANGE (1 << 7)
43
44/* Flags for CSR_INVALID */
45#define CSR_INV_TYPE (1 << 4)
46#define CSR_INV_VALIDATOR (1 << 5)
47#define CSV_INV_NOT_IMPL (1 << 6)
48
49#define CSR_RESULT_MASK 0x0F
50#define CSR_RESULT(x) ((x) & CSR_RESULT_MASK)
51
52#define IP (intptr_t)
53
62{
63 const char *name;
64 uint32_t type;
65 intptr_t initial;
66 intptr_t data;
67
79 int (*validator)(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
80
81 const char *docs;
82 intptr_t var;
83};
84
93{
94 int type;
95 const char *name;
96
112 int (*string_set)(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
113
129 int (*string_get)(void *var, const struct ConfigDef *cdef, struct Buffer *result);
130
145 int (*native_set)(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
146
161 intptr_t (*native_get)(void *var, const struct ConfigDef *cdef, struct Buffer *err);
162
177 int (*string_plus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
178
193 int (*string_minus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
194
208 bool (*has_been_set)(void *var, const struct ConfigDef *cdef);
209
223 int (*reset)(void *var, const struct ConfigDef *cdef, struct Buffer *err);
224
236 void (*destroy)(void *var, const struct ConfigDef *cdef);
237};
238
248{
249 struct HashTable *hash;
250 struct ConfigSetType types[18];
251};
252
253struct ConfigSet *cs_new(size_t size);
254void cs_free(struct ConfigSet **ptr);
255
256struct HashElem * cs_get_base (struct HashElem *he);
257struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
258const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
259
260bool cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst);
261struct HashElem *cs_register_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err);
262bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[]);
263struct HashElem *cs_create_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err);
264struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *he_parent, const char *name);
265void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
266
267bool cs_he_has_been_set (const struct ConfigSet *cs, struct HashElem *he);
268int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
269int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
270intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
271int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
272int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
273int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
274int cs_he_string_minus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
275int cs_he_string_plus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
276int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
277int cs_he_delete (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
278
279bool cs_str_has_been_set (const struct ConfigSet *cs, const char *name);
280int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
281int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
282int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
283int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
284
285extern bool StartupComplete;
286
293static inline bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
294{
295 if ((cdef->type & D_ON_STARTUP) && StartupComplete)
296 {
297 buf_printf(err, _("Option %s may only be set at startup"), cdef->name);
298 return true;
299 }
300
301 return false;
302}
303
304#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:293
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:593
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_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:892
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:446
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:326
bool cs_str_has_been_set(const struct ConfigSet *cs, const char *name)
Is the config value different to its initial value?
Definition: set.c:493
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:399
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:1009
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:668
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:616
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:788
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
bool cs_he_has_been_set(const struct ConfigSet *cs, struct HashElem *he)
Is the config value different to its initial value?
Definition: set.c:468
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:736
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:841
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *he_parent, const char *name)
Create in inherited config item.
Definition: set.c:355
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[])
Register a set of config items.
Definition: set.c:289
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:691
bool StartupComplete
When the config has been read.
Definition: address.c:14
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:513
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:557
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:951
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:384
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
String manipulation buffer.
Definition: buffer.h:36
Definition: set.h:62
const char * name
User-visible name.
Definition: set.h:63
intptr_t var
Storage for the variable.
Definition: set.h:82
int(* validator)(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:79
intptr_t data
Extra variable data.
Definition: set.h:66
intptr_t initial
Initial value.
Definition: set.h:65
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const char * docs
One-liner description.
Definition: set.h:81
int(* string_set)(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:112
int(* native_set)(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition: set.h:145
intptr_t(* native_get)(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition: set.h:161
int(* string_plus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:177
int type
Data type, e.g. DT_STRING.
Definition: set.h:94
bool(* has_been_set)(void *var, const struct ConfigDef *cdef)
Definition: set.h:208
int(* reset)(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition: set.h:223
int(* string_get)(void *var, const struct ConfigDef *cdef, struct Buffer *result)
Definition: set.h:129
void(* destroy)(void *var, const struct ConfigDef *cdef)
Definition: set.h:236
int(* string_minus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:193
const char * name
Name of the type, e.g. "String".
Definition: set.h:95
Container for lots of config items.
Definition: set.h:248
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:250
struct HashTable * hash
Hash Table: "$name" -> ConfigDef.
Definition: set.h:249
The item stored in a Hash Table.
Definition: hash.h:44
A Hash Table.
Definition: hash.h:99
Constants for all the config types.
#define D_ON_STARTUP
May only be set at startup.
Definition: types.h:78