NeoMutt  2025-12-11-596-g7cc1dd
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
50#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
81 int (*validator)(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
82
83 const char *docs;
84 intptr_t var;
85};
86
95{
96 int type;
97 const char *name;
98
114 int (*string_set)(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err);
115
131 int (*string_get)(void *var, const struct ConfigDef *cdef, struct Buffer *result);
132
147 int (*native_set)(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
148
163 intptr_t (*native_get)(void *var, const struct ConfigDef *cdef, struct Buffer *err);
164
179 int (*string_plus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
180
195 int (*string_minus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err);
196
210 bool (*has_been_set)(void *var, const struct ConfigDef *cdef);
211
225 int (*reset)(void *var, const struct ConfigDef *cdef, struct Buffer *err);
226
238 void (*destroy)(void *var, const struct ConfigDef *cdef);
239};
240
250{
251 struct HashTable *hash;
252 struct ConfigSetType types[18];
253};
254
255struct ConfigSet *cs_new(size_t size);
256void cs_free(struct ConfigSet **ptr);
257
258struct HashElem * cs_get_base (struct HashElem *he);
259struct HashElem * cs_get_elem (const struct ConfigSet *cs, const char *name);
260const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type);
261
262bool cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst);
263struct HashElem *cs_register_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err);
264bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[]);
265struct HashElem *cs_create_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err);
266struct HashElem *cs_inherit_variable (const struct ConfigSet *cs, struct HashElem *he_parent, const char *name);
267void cs_uninherit_variable(const struct ConfigSet *cs, const char *name);
268
269bool cs_he_has_been_set (const struct ConfigSet *cs, struct HashElem *he);
270int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
271int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
272intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
273int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err);
274int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
275int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
276int cs_he_string_minus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
277int cs_he_string_plus_equals (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
278int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
279int cs_he_delete (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err);
280
281bool cs_str_has_been_set (const struct ConfigSet *cs, const char *name);
282int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result);
283int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err);
284int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err);
285int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err);
286
287extern bool StartupComplete;
288
295static inline bool startup_only(const struct ConfigDef *cdef, struct Buffer *err)
296{
297 if ((cdef->type & D_ON_STARTUP) && StartupComplete)
298 {
299 buf_printf(err, _("Option %s may only be set at startup"), cdef->name);
300 return true;
301 }
302
303 return false;
304}
305
306#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:295
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:65
intptr_t var
Storage for the variable.
Definition set.h:84
int(* validator)(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition set.h:81
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:83
int(* string_set)(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition set.h:114
int(* native_set)(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Definition set.h:147
intptr_t(* native_get)(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition set.h:163
int(* string_plus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition set.h:179
int type
Data type, e.g. DT_STRING.
Definition set.h:96
bool(* has_been_set)(void *var, const struct ConfigDef *cdef)
Definition set.h:210
int(* reset)(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition set.h:225
int(* string_get)(void *var, const struct ConfigDef *cdef, struct Buffer *result)
Definition set.h:131
void(* destroy)(void *var, const struct ConfigDef *cdef)
Definition set.h:238
int(* string_minus_equals)(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition set.h:195
const char * name
Name of the type, e.g. "String".
Definition set.h:97
Container for lots of config items.
Definition set.h:250
struct ConfigSetType types[18]
All the defined config types.
Definition set.h:252
struct HashTable * hash
Hash Table: "$name" -> ConfigDef.
Definition set.h:251
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