NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
set.h
Go to the documentation of this file.
1
22
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#define CSR_INV_WARNING (1 << 7)
49
51#define CSR_RESULT_MASK 0x0F
53#define CSR_RESULT(x) ((x) & CSR_RESULT_MASK)
54
55#define IP (intptr_t)
56
65{
66 const char *name;
67 uint32_t type;
68 intptr_t initial;
69 intptr_t data;
70
82 int (*validator)(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
115 int (*string_set)(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
116
132 int (*string_get)(void *var, const struct ConfigDef *cdef, struct Buffer *result);
133
148 int (*native_set)(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
149
164 intptr_t (*native_get)(void *var, const struct ConfigDef *cdef, struct Buffer *err);
165
180 int (*string_plus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
181
196 int (*string_minus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
197
211 bool (*has_been_set)(void *var, const struct ConfigDef *cdef);
212
226 int (*reset)(void *var, const struct ConfigDef *cdef, struct Buffer *err);
227
239 void (*destroy)(void *var, const struct ConfigDef *cdef);
240};
241
251{
252 struct HashTable *hash;
253 struct ConfigSetType types[18];
254};
255
256struct ConfigSet *cs_new(size_t size);
257void cs_free(struct ConfigSet **ptr);
258
259struct HashElem * cs_get_base (struct HashElem *he);
260struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
261const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
262
263bool cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst);
264struct HashElem *cs_register_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err);
265bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[]);
266struct HashElem *cs_create_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err);
267struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *he_parent, const char *name);
268void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
269
270bool cs_he_has_been_set (const struct ConfigSet *cs, struct HashElem *he);
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
282bool cs_str_has_been_set (const struct ConfigSet *cs, const char *name);
283int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
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:594
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition set.c:176
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:893
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition set.c:142
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:447
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition set.c:128
struct HashElem * cs_create_variable(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Create and register one config item.
Definition set.c:327
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:494
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:400
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition set.c:199
int cs_he_delete(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Delete config item from a config set.
Definition set.c:1010
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:669
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:617
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:789
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition set.c:161
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:469
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:737
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:842
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *he_parent, const char *name)
Create in inherited config item.
Definition set.c:356
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[])
Register a set of config items.
Definition set.c:290
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:692
bool StartupComplete
When the config has been read.
Definition address.c:11
struct HashElem * cs_register_variable(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Register one config item.
Definition set.c:250
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:514
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:558
bool cs_register_type(struct ConfigSet *cs, const struct ConfigSetType *cst)
Register a type of config item.
Definition set.c:220
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:952
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition set.c:385
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
String manipulation buffer.
Definition buffer.h:36
const char * name
User-visible name.
Definition set.h:66
intptr_t var
Storage for the variable.
Definition set.h:85
int(* validator)(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition set.h:82
intptr_t data
Extra variable data.
Definition set.h:69
intptr_t initial
Initial value.
Definition set.h:68
uint32_t type
Variable type, e.g. DT_STRING.
Definition set.h:67
const char * docs
One-liner description.
Definition set.h:84
int(* string_set)(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition set.h:115
int(* native_set)(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition set.h:148
intptr_t(* native_get)(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition set.h:164
int(* string_plus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition set.h:180
int type
Data type, e.g. DT_STRING.
Definition set.h:97
bool(* has_been_set)(void *var, const struct ConfigDef *cdef)
Definition set.h:211
int(* reset)(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition set.h:226
int(* string_get)(void *var, const struct ConfigDef *cdef, struct Buffer *result)
Definition set.h:132
void(* destroy)(void *var, const struct ConfigDef *cdef)
Definition set.h:239
int(* string_minus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition set.h:196
const char * name
Name of the type, e.g. "String".
Definition set.h:98
Container for lots of config items.
Definition set.h:251
struct ConfigSetType types[18]
All the defined config types.
Definition set.h:253
struct HashTable * hash
Hash Table: "$name" -> ConfigDef.
Definition set.h:252
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:79