NeoMutt  2024-04-25-89-g194907
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
set.h File Reference

A collection of config items. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "types.h"
+ Include dependency graph for set.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ConfigDef
 
struct  ConfigSetType
 
struct  ConfigSet
 Container for lots of config items. More...
 

Macros

#define CSR_SUCCESS   0
 Action completed successfully.
 
#define CSR_ERR_CODE   1
 Problem with the code.
 
#define CSR_ERR_UNKNOWN   2
 Unrecognised config item.
 
#define CSR_ERR_INVALID   3
 Value hasn't been set.
 
#define CSR_SUC_INHERITED   (1 << 4)
 Value is inherited.
 
#define CSR_SUC_EMPTY   (1 << 5)
 Value is empty/unset.
 
#define CSR_SUC_WARNING   (1 << 6)
 Notify the user of a warning.
 
#define CSR_SUC_NO_CHANGE   (1 << 7)
 The value hasn't changed.
 
#define CSR_INV_TYPE   (1 << 4)
 Value is not valid for the type.
 
#define CSR_INV_VALIDATOR   (1 << 5)
 Value was rejected by the validator.
 
#define CSV_INV_NOT_IMPL   (1 << 6)
 Operation not permitted for the type.
 
#define CSR_RESULT_MASK   0x0F
 
#define CSR_RESULT(x)   ((x) & CSR_RESULT_MASK)
 
#define IP   (intptr_t)
 

Functions

struct ConfigSetcs_new (size_t size)
 Create a new Config Set.
 
void cs_free (struct ConfigSet **ptr)
 Free a Config Set.
 
struct HashElemcs_get_base (struct HashElem *he)
 Find the root Config Item.
 
struct HashElemcs_get_elem (const struct ConfigSet *cs, const char *name)
 Get the HashElem representing a config item.
 
const struct ConfigSetTypecs_get_type_def (const struct ConfigSet *cs, unsigned int type)
 Get the definition for a type.
 
bool cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst)
 Register a type of config item.
 
struct HashElemcs_register_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
 Register one config item.
 
bool cs_register_variables (const struct ConfigSet *cs, struct ConfigDef vars[])
 Register a set of config items.
 
struct HashElemcs_create_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
 Create and register one config item.
 
struct HashElemcs_inherit_variable (const struct ConfigSet *cs, struct HashElem *he_parent, const char *name)
 Create in inherited config item.
 
void cs_uninherit_variable (const struct ConfigSet *cs, const char *name)
 Remove an inherited config item.
 
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.
 
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.
 
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.
 
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.
 
int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
 Reset a config item to its initial value.
 
int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
 Get a config item as a string.
 
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.
 
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.
 
int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
 Set a config item by string.
 
int cs_he_delete (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
 Delete config item from a config set.
 
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.
 
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.
 
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.
 
int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err)
 Reset a config item to its initial value.
 
int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
 Set a config item by string.
 
static bool startup_only (const struct ConfigDef *cdef, struct Buffer *err)
 Validator function for D_ON_STARTUP.
 

Variables

bool StartupComplete
 When the config has been read.
 

Detailed Description

A collection of config items.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file set.h.

Macro Definition Documentation

◆ CSR_SUCCESS

#define CSR_SUCCESS   0

Action completed successfully.

Definition at line 35 of file set.h.

◆ CSR_ERR_CODE

#define CSR_ERR_CODE   1

Problem with the code.

Definition at line 36 of file set.h.

◆ CSR_ERR_UNKNOWN

#define CSR_ERR_UNKNOWN   2

Unrecognised config item.

Definition at line 37 of file set.h.

◆ CSR_ERR_INVALID

#define CSR_ERR_INVALID   3

Value hasn't been set.

Definition at line 38 of file set.h.

◆ CSR_SUC_INHERITED

#define CSR_SUC_INHERITED   (1 << 4)

Value is inherited.

Definition at line 41 of file set.h.

◆ CSR_SUC_EMPTY

#define CSR_SUC_EMPTY   (1 << 5)

Value is empty/unset.

Definition at line 42 of file set.h.

◆ CSR_SUC_WARNING

#define CSR_SUC_WARNING   (1 << 6)

Notify the user of a warning.

Definition at line 43 of file set.h.

◆ CSR_SUC_NO_CHANGE

#define CSR_SUC_NO_CHANGE   (1 << 7)

The value hasn't changed.

Definition at line 44 of file set.h.

◆ CSR_INV_TYPE

#define CSR_INV_TYPE   (1 << 4)

Value is not valid for the type.

Definition at line 47 of file set.h.

◆ CSR_INV_VALIDATOR

#define CSR_INV_VALIDATOR   (1 << 5)

Value was rejected by the validator.

Definition at line 48 of file set.h.

◆ CSV_INV_NOT_IMPL

#define CSV_INV_NOT_IMPL   (1 << 6)

Operation not permitted for the type.

Definition at line 49 of file set.h.

◆ CSR_RESULT_MASK

#define CSR_RESULT_MASK   0x0F

Definition at line 51 of file set.h.

◆ CSR_RESULT

#define CSR_RESULT (   x)    ((x) & CSR_RESULT_MASK)

Definition at line 52 of file set.h.

◆ IP

#define IP   (intptr_t)

Definition at line 54 of file set.h.

Function Documentation

◆ cs_new()

struct ConfigSet * cs_new ( size_t  size)

Create a new Config Set.

Parameters
sizeNumber of expected config items
Return values
ptrNew ConfigSet object

Definition at line 127 of file set.c.

128{
129 struct ConfigSet *cs = mutt_mem_calloc(1, sizeof(*cs));
130
133
134 return cs;
135}
static void cs_hashelem_free(int type, void *obj, intptr_t data)
Free our hash table data - Implements hash_hdata_free_t -.
Definition: set.c:46
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition: hash.c:259
void mutt_hash_set_destructor(struct HashTable *table, hash_hdata_free_t fn, intptr_t fn_data)
Set the destructor for a Hash Table.
Definition: hash.c:301
#define MUTT_HASH_NO_FLAGS
No flags are set.
Definition: hash.h:109
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
Container for lots of config items.
Definition: set.h:252
struct HashTable * hash
Hash Table: "$name" -> ConfigDef.
Definition: set.h:253
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_free()

void cs_free ( struct ConfigSet **  ptr)

Free a Config Set.

Parameters
[out]ptrConfig items

Definition at line 141 of file set.c.

142{
143 if (!ptr || !*ptr)
144 return;
145
146 struct ConfigSet *cs = *ptr;
147
148 mutt_hash_free(&cs->hash);
149 FREE(ptr);
150}
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
#define FREE(x)
Definition: memory.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_get_base()

struct HashElem * cs_get_base ( struct HashElem he)

Find the root Config Item.

Parameters
heConfig Item to examine
Return values
ptrRoot Config Item

Given an inherited HashElem, find the HashElem representing the original Config Item.

Definition at line 160 of file set.c.

161{
162 if (!(he->type & D_INTERNAL_INHERITED))
163 return he;
164
165 struct Inheritance *i = he->data;
166 return cs_get_base(i->parent);
167}
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:44
void * data
User-supplied data.
Definition: hash.h:46
An inherited config item.
Definition: inheritance.h:32
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define D_INTERNAL_INHERITED
Config item is inherited.
Definition: types.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_get_elem()

struct HashElem * cs_get_elem ( const struct ConfigSet cs,
const char *  name 
)

Get the HashElem representing a config item.

Parameters
csConfig items
nameName of config item
Return values
ptrHashElem representing the config item

Definition at line 175 of file set.c.

176{
177 if (!cs || !name)
178 return NULL;
179
180 struct HashElem *he = mutt_hash_find_elem(cs->hash, name);
181 if (!he)
182 return NULL;
183
184 if (DTYPE(he->type) != DT_SYNONYM)
185 return he;
186
187 const struct ConfigDef *cdef = he->data;
188
189 return (struct HashElem *) cdef->var;
190}
struct HashElem * mutt_hash_find_elem(const struct HashTable *table, const char *strkey)
Find the HashElem in a Hash Table element using a key.
Definition: hash.c:377
Definition: set.h:64
intptr_t var
Storage for the variable.
Definition: set.h:85
The item stored in a Hash Table.
Definition: hash.h:43
#define DTYPE(t)
Definition: types.h:50
@ DT_SYNONYM
synonym for another variable
Definition: types.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_get_type_def()

const struct ConfigSetType * cs_get_type_def ( const struct ConfigSet cs,
unsigned int  type 
)

Get the definition for a type.

Parameters
csConfig items
typeType to lookup, e.g. DT_NUMBER
Return values
ptrConfigSetType representing the type

Definition at line 198 of file set.c.

199{
200 if (!cs)
201 return NULL;
202
203 type = DTYPE(type);
204 if (type >= mutt_array_size(cs->types))
205 return NULL; // LCOV_EXCL_LINE
206
207 if (!cs->types[type].name)
208 return NULL;
209
210 return &cs->types[type];
211}
#define mutt_array_size(x)
Definition: memory.h:38
const char * name
Name of the type, e.g. "String".
Definition: set.h:98
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:254
+ Here is the caller graph for this function:

◆ cs_register_type()

bool cs_register_type ( struct ConfigSet cs,
const struct ConfigSetType cst 
)

Register a type of config item.

Parameters
csConfig items
cstStructure defining the type
Return values
trueType was registered successfully

Definition at line 219 of file set.c.

220{
221 if (!cs || !cst)
222 return false;
223
224 if (!cst->name || !cst->string_set || !cst->string_get || !cst->reset ||
225 !cst->native_set || !cst->native_get)
226 {
227 return false;
228 }
229
230 if (cst->type >= mutt_array_size(cs->types))
231 return false;
232
233 if (cs->types[cst->type].name)
234 return false; /* already registered */
235
236 cs->types[cst->type] = *cst;
237 return true;
238}
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(* reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition: set.h:225
intptr_t(* native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Definition: set.h:172

◆ cs_register_variable()

struct HashElem * cs_register_variable ( const struct ConfigSet cs,
struct ConfigDef cdef,
struct Buffer err 
)

Register one config item.

Parameters
csConfig items
cdefVariable definition
errBuffer for error messages
Return values
ptrNew HashElem representing the config item

Similar to cs_create_variable() but assumes that cdef lives indefinitely.

Definition at line 249 of file set.c.

251{
252 if (!cs || !cdef)
253 return NULL; /* LCOV_EXCL_LINE */
254
255 if (DTYPE(cdef->type) == DT_SYNONYM)
256 return create_synonym(cs, cdef, err);
257
258 const struct ConfigSetType *cst = cs_get_type_def(cs, cdef->type);
259 if (!cst)
260 {
261 buf_printf(err, _("Option %s has an invalid type %d"), cdef->name, cdef->type);
262 return NULL;
263 }
264
265 struct HashElem *he = mutt_hash_typed_insert(cs->hash, cdef->name, cdef->type, cdef);
266 if (!he)
267 return NULL; /* LCOV_EXCL_LINE */
268
269 if (cst->reset)
270 cst->reset(cs, &cdef->var, cdef, err);
271
272 return he;
273}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:198
static struct HashElem * create_synonym(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Create an alternative name for a config item.
Definition: set.c:99
struct HashElem * mutt_hash_typed_insert(struct HashTable *table, const char *strkey, int type, void *data)
Insert a string with type info into a Hash Table.
Definition: hash.c:317
#define _(a)
Definition: message.h:28
const char * name
User-visible name.
Definition: set.h:65
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_register_variables()

bool cs_register_variables ( const struct ConfigSet cs,
struct ConfigDef  vars[] 
)

Register a set of config items.

Parameters
csConfig items
varsVariable definition
Return values
trueAll variables were registered successfully

Definition at line 281 of file set.c.

282{
283 if (!cs || !vars)
284 return false;
285
286 struct Buffer *err = buf_pool_get();
287
288 bool rc = true;
289
290 for (size_t i = 0; vars[i].name; i++)
291 {
292 if (!cs_register_variable(cs, &vars[i], err))
293 {
294 mutt_debug(LL_DEBUG1, "%s\n", buf_string(err));
295 rc = false;
296 }
297 }
298
299 buf_pool_release(&err);
300 return rc;
301}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
struct HashElem * cs_register_variable(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Register one config item.
Definition: set.c:249
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_create_variable()

struct HashElem * cs_create_variable ( const struct ConfigSet cs,
struct ConfigDef cdef,
struct Buffer err 
)

Create and register one config item.

Parameters
csConfig items
cdefVariable definition
errBuffer for error messages
Return values
ptrNew HashElem representing the config item

Similar to cs_register_variable() but copies the ConfigDef first. Allowing the caller to free it and its parts afterwards.

This function does not know anything about how the internal representation of the type must be handled. Thus, the fields 'initial', 'data', 'var' must be copyable. If they need allocation, then the caller must set them after the variable is created, e.g. with cs_he_initial_set(), cs_he_native_set.

Definition at line 318 of file set.c.

320{
321 struct ConfigDef *cdef_copy = mutt_mem_calloc(1, sizeof(struct ConfigDef));
322 cdef_copy->name = mutt_str_dup(cdef->name);
323 cdef_copy->type = cdef->type | D_INTERNAL_FREE_CONFIGDEF;
324 cdef_copy->initial = cdef->initial;
325 cdef_copy->data = cdef->data;
326 cdef_copy->validator = cdef->validator;
327 cdef_copy->docs = mutt_str_dup(cdef->name);
328 cdef_copy->var = cdef->var;
329
330 struct HashElem *he = cs_register_variable(cs, cdef_copy, err);
331 if (!he)
332 {
333 FREE(&cdef_copy->name);
334 FREE(&cdef_copy->docs);
335 FREE(&cdef_copy);
336 }
337 return he;
338}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
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
const char * docs
One-liner description.
Definition: set.h:84
#define D_INTERNAL_FREE_CONFIGDEF
Config item must have its ConfigDef freed.
Definition: types.h:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_inherit_variable()

struct HashElem * cs_inherit_variable ( const struct ConfigSet cs,
struct HashElem he_parent,
const char *  name 
)

Create in inherited config item.

Parameters
csConfig items
he_parentHashElem of parent config item
nameName of account-specific config item
Return values
ptrNew HashElem representing the inherited config item

Definition at line 347 of file set.c.

349{
350 if (!cs || !he_parent)
351 return NULL;
352
353 /* MyVars cannot be inherited, as they might get deleted */
354 if (DTYPE(he_parent->type) == DT_MYVAR)
355 return NULL;
356
357 struct Inheritance *i = mutt_mem_calloc(1, sizeof(*i));
358 i->parent = he_parent;
359 i->name = mutt_str_dup(name);
360
362 if (!he)
363 {
364 FREE(&i->name);
365 FREE(&i);
366 }
367
368 return he;
369}
const char * name
Name of this config item.
Definition: inheritance.h:34
@ DT_MYVAR
a user-defined variable (my_foo)
Definition: types.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_uninherit_variable()

void cs_uninherit_variable ( const struct ConfigSet cs,
const char *  name 
)

Remove an inherited config item.

Parameters
csConfig items
nameName of config item to remove

Definition at line 376 of file set.c.

377{
378 if (!cs || !name)
379 return;
380
381 mutt_hash_delete(cs->hash, name, NULL);
382}
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition: hash.c:427
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_initial_get()

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.

Parameters
csConfig items
heHashElem representing config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

If a config item is inherited from another, then this will get the parent's value. Otherwise, it will get the config item's initial value.

Definition at line 529 of file set.c.

530{
531 if (!cs || !he || !result)
532 return CSR_ERR_CODE;
533
534 const struct ConfigDef *cdef = NULL;
535 const struct ConfigSetType *cst = NULL;
536
537 if (he->type & D_INTERNAL_INHERITED)
538 {
539 struct HashElem *he_base = cs_get_base(he);
540 cdef = he_base->data;
541 cst = cs_get_type_def(cs, he_base->type);
542 }
543 else
544 {
545 cdef = he->data;
546 cst = cs_get_type_def(cs, he->type);
547 }
548
549 if (!cst)
550 return CSR_ERR_CODE; // LCOV_EXCL_LINE
551
552 return cst->string_get(cs, NULL, cdef, result);
553}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_initial_set()

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.

Parameters
csConfig items
heHashElem representing config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 461 of file set.c.

463{
464 if (!cs || !he)
465 return CSR_ERR_CODE;
466
467 struct ConfigDef *cdef = NULL;
468
469 if (he->type & D_INTERNAL_INHERITED)
470 {
471 struct HashElem *he_base = cs_get_base(he);
472 cdef = he_base->data;
473 mutt_debug(LL_DEBUG1, "Variable '%s' is inherited type\n", cdef->name);
474 return CSR_ERR_CODE;
475 }
476
477 cdef = he->data;
478 if (!cdef)
479 return CSR_ERR_CODE; // LCOV_EXCL_LINE
480
481 const struct ConfigSetType *cst = cs_get_type_def(cs, he->type);
482 if (!cst)
483 {
484 mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
485 return CSR_ERR_CODE;
486 }
487
488 int rc = cst->string_set(cs, NULL, cdef, value, err);
489 if (CSR_RESULT(rc) != CSR_SUCCESS)
490 return rc;
491
492 return CSR_SUCCESS;
493}
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_native_get()

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.

Parameters
csConfig items
heHashElem representing config item
errBuffer for results or error messages
Return values
intptr_tNative pointer/value
INT_MINError

Definition at line 813 of file set.c.

814{
815 if (!cs || !he)
816 return INT_MIN;
817
818 struct ConfigDef *cdef = NULL;
819 const struct ConfigSetType *cst = NULL;
820 void *var = NULL;
821
822 if (he->type & D_INTERNAL_INHERITED)
823 {
824 struct Inheritance *i = he->data;
825
826 // inherited, value not set
827 if (DTYPE(he->type) == 0)
828 return cs_he_native_get(cs, i->parent, err);
829
830 // inherited, value set
831 struct HashElem *he_base = cs_get_base(he);
832 cdef = he_base->data;
833 cst = cs_get_type_def(cs, he_base->type);
834 var = &i->var;
835 }
836 else
837 {
838 // not inherited
839 cdef = he->data;
840 cst = cs_get_type_def(cs, he->type);
841 var = &cdef->var;
842 }
843
844 if (!var || !cdef)
845 return INT_MIN; // LCOV_EXCL_LINE
846
847 if (!cst)
848 {
849 buf_printf(err, _("Option %s has an invalid type %d"), cdef->name, he->type);
850 return INT_MIN;
851 }
852
853 return cst->native_get(cs, var, cdef, err);
854}
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
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_native_set()

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.

Parameters
csConfig items
heHashElem representing config item
valueNative pointer/value to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 708 of file set.c.

710{
711 if (!cs || !he)
712 return CSR_ERR_CODE;
713
714 struct ConfigDef *cdef = NULL;
715 const struct ConfigSetType *cst = NULL;
716 void *var = NULL;
717
718 if (he->type & D_INTERNAL_INHERITED)
719 {
720 struct Inheritance *i = he->data;
721 struct HashElem *he_base = cs_get_base(he);
722 cdef = he_base->data;
723 cst = cs_get_type_def(cs, he_base->type);
724 var = &i->var;
725 }
726 else
727 {
728 cdef = he->data;
729 cst = cs_get_type_def(cs, he->type);
730 var = &cdef->var;
731 }
732
733 if (!cst)
734 {
735 mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
736 return CSR_ERR_CODE;
737 }
738
739 if (!var || !cdef)
740 return CSR_ERR_CODE; // LCOV_EXCL_LINE
741
742 int rc = cst->native_set(cs, var, cdef, value, err);
743 if (CSR_RESULT(rc) != CSR_SUCCESS)
744 return rc;
745
746 if (he->type & D_INTERNAL_INHERITED)
747 he->type = cdef->type | D_INTERNAL_INHERITED;
748
749 return rc;
750}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_reset()

int cs_he_reset ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer err 
)

Reset a config item to its initial value.

Parameters
csConfig items
heHashElem representing config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 391 of file set.c.

392{
393 if (!cs || !he)
394 return CSR_ERR_CODE;
395
396 /* An inherited var that's already pointing to its parent.
397 * Return 'success', but don't send a notification. */
398 if ((he->type & D_INTERNAL_INHERITED) && (DTYPE(he->type) == 0))
399 return CSR_SUCCESS;
400
401 int rc = CSR_SUCCESS;
402
403 if (he->type & D_INTERNAL_INHERITED)
404 {
405 struct Inheritance *i = he->data;
406 struct HashElem *he_base = cs_get_base(he);
407 struct ConfigDef *cdef = he_base->data;
408 if (!cdef)
409 return CSR_ERR_CODE; // LCOV_EXCL_LINE
410
411 const struct ConfigSetType *cst = cs_get_type_def(cs, he_base->type);
412 if (cst && cst->destroy)
413 cst->destroy(cs, (void **) &i->var, cdef);
414
416 }
417 else
418 {
419 struct ConfigDef *cdef = he->data;
420 if (!cdef)
421 return CSR_ERR_CODE; // LCOV_EXCL_LINE
422
423 const struct ConfigSetType *cst = cs_get_type_def(cs, he->type);
424 if (cst)
425 rc = cst->reset(cs, &cdef->var, cdef, err);
426 }
427
428 return rc;
429}
void(* destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Definition: set.h:240
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_string_get()

int cs_he_string_get ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer result 
)

Get a config item as a string.

Parameters
csConfig items
heHashElem representing config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 663 of file set.c.

664{
665 if (!cs || !he || !result)
666 return CSR_ERR_CODE;
667
668 struct ConfigDef *cdef = NULL;
669 const struct ConfigSetType *cst = NULL;
670 void *var = NULL;
671
672 if (he->type & D_INTERNAL_INHERITED)
673 {
674 struct Inheritance *i = he->data;
675
676 // inherited, value not set
677 if (DTYPE(he->type) == 0)
678 return cs_he_string_get(cs, i->parent, result);
679
680 // inherited, value set
681 struct HashElem *he_base = cs_get_base(he);
682 cdef = he_base->data;
683 cst = cs_get_type_def(cs, he_base->type);
684 var = &i->var;
685 }
686 else
687 {
688 // not inherited
689 cdef = he->data;
690 cst = cs_get_type_def(cs, he->type);
691 var = &cdef->var;
692 }
693
694 if (!cdef || !cst)
695 return CSR_ERR_CODE; // LCOV_EXCL_LINE
696
697 return cst->string_get(cs, var, cdef, result);
698}
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_string_minus_equals()

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.

Parameters
csConfig items
heHashElem representing config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 923 of file set.c.

925{
926 if (!cs || !he)
927 return CSR_ERR_CODE;
928
929 struct ConfigDef *cdef = NULL;
930 const struct ConfigSetType *cst = NULL;
931 void *var = NULL;
932
933 if (he->type & D_INTERNAL_INHERITED)
934 {
935 struct Inheritance *i = he->data;
936 struct HashElem *he_base = cs_get_base(he);
937 cdef = he_base->data;
938 cst = cs_get_type_def(cs, he_base->type);
939 var = &i->var;
940 }
941 else
942 {
943 cdef = he->data;
944 cst = cs_get_type_def(cs, he->type);
945 var = &cdef->var;
946 }
947
948 if (!var || !cdef)
949 return INT_MIN; // LCOV_EXCL_LINE
950
951 if (!cst)
952 {
953 mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
954 return CSR_ERR_CODE;
955 }
956
957 if (!cst->string_minus_equals)
958 {
959 // L10N: e.g. Type 'boolean' doesn't support operation '+='
960 buf_printf(err, _("Type '%s' doesn't support operation '%s'"), cst->name, "-=");
962 }
963
964 int rc = cst->string_minus_equals(cs, var, cdef, value, err);
965 if (CSR_RESULT(rc) != CSR_SUCCESS)
966 return rc;
967
968 if (he->type & D_INTERNAL_INHERITED)
969 he->type = cdef->type | D_INTERNAL_INHERITED;
970
971 return rc;
972}
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSV_INV_NOT_IMPL
Operation not permitted for the type.
Definition: set.h:49
int(* string_minus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:208
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_string_plus_equals()

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.

Parameters
csConfig items
heHashElem representing config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 864 of file set.c.

866{
867 if (!cs || !he)
868 return CSR_ERR_CODE;
869
870 struct ConfigDef *cdef = NULL;
871 const struct ConfigSetType *cst = NULL;
872 void *var = NULL;
873
874 if (he->type & D_INTERNAL_INHERITED)
875 {
876 struct Inheritance *i = he->data;
877 struct HashElem *he_base = cs_get_base(he);
878 cdef = he_base->data;
879 cst = cs_get_type_def(cs, he_base->type);
880 var = &i->var;
881 }
882 else
883 {
884 cdef = he->data;
885 cst = cs_get_type_def(cs, he->type);
886 var = &cdef->var;
887 }
888
889 if (!var || !cdef)
890 return INT_MIN; // LCOV_EXCL_LINE
891
892 if (!cst)
893 {
894 mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
895 return CSR_ERR_CODE;
896 }
897
898 if (!cst->string_plus_equals)
899 {
900 // L10N: e.g. Type 'boolean' doesn't support operation '+='
901 buf_printf(err, _("Type '%s' doesn't support operation '%s'"), cst->name, "+=");
903 }
904
905 int rc = cst->string_plus_equals(cs, var, cdef, value, err);
906 if (CSR_RESULT(rc) != CSR_SUCCESS)
907 return rc;
908
909 if (he->type & D_INTERNAL_INHERITED)
910 he->type = cdef->type | D_INTERNAL_INHERITED;
911
912 return rc;
913}
int(* string_plus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Definition: set.h:190
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_string_set()

int cs_he_string_set ( const struct ConfigSet cs,
struct HashElem he,
const char *  value,
struct Buffer err 
)

Set a config item by string.

Parameters
csConfig items
heHashElem representing config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 588 of file set.c.

590{
591 if (!cs || !he)
592 return CSR_ERR_CODE;
593
594 struct ConfigDef *cdef = NULL;
595 const struct ConfigSetType *cst = NULL;
596 void *var = NULL;
597
598 if (he->type & D_INTERNAL_INHERITED)
599 {
600 struct Inheritance *i = he->data;
601 struct HashElem *he_base = cs_get_base(he);
602 cdef = he_base->data;
603 cst = cs_get_type_def(cs, he_base->type);
604 var = &i->var;
605 }
606 else
607 {
608 cdef = he->data;
609 cst = cs_get_type_def(cs, he->type);
610 var = &cdef->var;
611 }
612
613 if (!cdef)
614 return CSR_ERR_CODE; // LCOV_EXCL_LINE
615
616 if (!cst)
617 {
618 mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
619 return CSR_ERR_CODE;
620 }
621
622 int rc = cst->string_set(cs, var, cdef, value, err);
623 if (CSR_RESULT(rc) != CSR_SUCCESS)
624 return rc;
625
626 if (he->type & D_INTERNAL_INHERITED)
627 he->type = cdef->type | D_INTERNAL_INHERITED;
628
629 return rc;
630}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_delete()

int cs_he_delete ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer err 
)

Delete config item from a config set.

Parameters
csConfig items
heHashElem representing config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 981 of file set.c.

982{
983 if (!cs || !he)
984 return CSR_ERR_CODE;
985
986 mutt_hash_delete(cs->hash, he->key.strkey, he->data);
987 return CSR_SUCCESS;
988}
union HashKey key
Key representing the data.
Definition: hash.h:45
const char * strkey
String key.
Definition: hash.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_initial_get()

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.

Parameters
csConfig items
nameName of config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

If a config item is inherited from another, then this will get the parent's value. Otherwise, it will get the config item's initial value.

Definition at line 565 of file set.c.

566{
567 if (!cs || !name)
568 return CSR_ERR_CODE;
569
570 struct HashElem *he = cs_get_elem(cs, name);
571 if (!he)
572 {
573 buf_printf(result, _("Unknown option %s"), name);
574 return CSR_ERR_UNKNOWN;
575 }
576
577 return cs_he_initial_get(cs, he, result);
578}
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_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
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_initial_set()

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.

Parameters
csConfig items
nameName of config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 503 of file set.c.

505{
506 if (!cs || !name)
507 return CSR_ERR_CODE;
508
509 struct HashElem *he = cs_get_elem(cs, name);
510 if (!he)
511 {
512 buf_printf(err, _("Unknown option %s"), name);
513 return CSR_ERR_UNKNOWN;
514 }
515
516 return cs_he_initial_set(cs, he, value, err);
517}
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_native_set()

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.

Parameters
csConfig items
nameName of config item
valueNative pointer/value to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 760 of file set.c.

762{
763 if (!cs || !name)
764 return CSR_ERR_CODE;
765
766 struct HashElem *he = cs_get_elem(cs, name);
767 if (!he)
768 {
769 buf_printf(err, _("Unknown option %s"), name);
770 return CSR_ERR_UNKNOWN;
771 }
772
773 struct ConfigDef *cdef = NULL;
774 const struct ConfigSetType *cst = NULL;
775 void *var = NULL;
776
777 if (he->type & D_INTERNAL_INHERITED)
778 {
779 struct Inheritance *i = he->data;
780 struct HashElem *he_base = cs_get_base(he);
781 cdef = he_base->data;
782 cst = cs_get_type_def(cs, he_base->type);
783 var = &i->var;
784 }
785 else
786 {
787 cdef = he->data;
788 cst = cs_get_type_def(cs, he->type);
789 var = &cdef->var;
790 }
791
792 if (!cst || !var || !cdef)
793 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
794
795 int rc = cst->native_set(cs, var, cdef, value, err);
796 if (CSR_RESULT(rc) != CSR_SUCCESS)
797 return rc;
798
799 if (he->type & D_INTERNAL_INHERITED)
800 he->type = cdef->type | D_INTERNAL_INHERITED;
801
802 return rc;
803}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_reset()

int cs_str_reset ( const struct ConfigSet cs,
const char *  name,
struct Buffer err 
)

Reset a config item to its initial value.

Parameters
csConfig items
nameName of config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 438 of file set.c.

439{
440 if (!cs || !name)
441 return CSR_ERR_CODE;
442
443 struct HashElem *he = cs_get_elem(cs, name);
444 if (!he)
445 {
446 buf_printf(err, _("Unknown option %s"), name);
447 return CSR_ERR_UNKNOWN;
448 }
449
450 return cs_he_reset(cs, he, err);
451}
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_string_set()

int cs_str_string_set ( const struct ConfigSet cs,
const char *  name,
const char *  value,
struct Buffer err 
)

Set a config item by string.

Parameters
csConfig items
nameName of config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 640 of file set.c.

642{
643 if (!cs || !name)
644 return CSR_ERR_CODE;
645
646 struct HashElem *he = cs_get_elem(cs, name);
647 if (!he)
648 {
649 buf_printf(err, _("Unknown option %s"), name);
650 return CSR_ERR_UNKNOWN;
651 }
652
653 return cs_he_string_set(cs, he, value, err);
654}
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startup_only()

static bool startup_only ( const struct ConfigDef cdef,
struct Buffer err 
)
inlinestatic

Validator function for D_ON_STARTUP.

Parameters
cdefVariable definition
errBuffer for error messages
Return values
trueVariable may only be set at startup

Definition at line 296 of file set.h.

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}
bool StartupComplete
When the config has been read.
Definition: main.c:192
#define D_ON_STARTUP
May only be set at startup.
Definition: types.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ StartupComplete

bool StartupComplete
extern

When the config has been read.

Definition at line 192 of file main.c.