NeoMutt  2020-06-26-250-g349c94
Teaching an old dog new tricks
DOXYGEN
set.h File Reference

A collection of config items. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.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
 Config item definition. More...
 
struct  ConfigSetType
 Type definition for a config item. More...
 
struct  ConfigSet
 Container for lots of config items. More...
 

Macros

#define CSR_SUCCESS   0
 Action completed successfully. More...
 
#define CSR_ERR_CODE   1
 Problem with the code. More...
 
#define CSR_ERR_UNKNOWN   2
 Unrecognised config item. More...
 
#define CSR_ERR_INVALID   3
 Value hasn't been set. More...
 
#define CSR_SUC_INHERITED   (1 << 4)
 Value is inherited. More...
 
#define CSR_SUC_EMPTY   (1 << 5)
 Value is empty/unset. More...
 
#define CSR_SUC_WARNING   (1 << 6)
 Notify the user of a warning. More...
 
#define CSR_SUC_NO_CHANGE   (1 << 7)
 The value hasn't changed. More...
 
#define CSR_INV_TYPE   (1 << 4)
 Value is not valid for the type. More...
 
#define CSR_INV_VALIDATOR   (1 << 5)
 Value was rejected by the validator. More...
 
#define CSV_INV_NOT_IMPL   (1 << 6)
 Operation not permitted for the type. More...
 
#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. More...
 
void cs_free (struct ConfigSet **ptr)
 Free a Config Set. More...
 
struct HashElemcs_get_base (struct HashElem *he)
 Find the root Config Item. More...
 
struct HashElemcs_get_elem (const struct ConfigSet *cs, const char *name)
 Get the HashElem representing a config item. More...
 
const struct ConfigSetTypecs_get_type_def (const struct ConfigSet *cs, unsigned int type)
 Get the definition for a type. More...
 
bool cs_register_type (struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst)
 Register a type of config item. More...
 
bool cs_register_variables (const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
 Register a set of config items. More...
 
struct HashElemcs_inherit_variable (const struct ConfigSet *cs, struct HashElem *parent, const char *name)
 Create in inherited config item. More...
 
void cs_uninherit_variable (const struct ConfigSet *cs, const char *name)
 Remove an inherited config item. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
 Reset a config item to its initial value. More...
 
int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
 Get a config item as a string. More...
 
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. More...
 
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. More...
 
int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
 Set a config item by string. More...
 
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. More...
 
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. More...
 
intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err)
 Natively get the value of a string config item. More...
 
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. More...
 
int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err)
 Reset a config item to its initial value. More...
 
int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result)
 Get a config item as a string. More...
 
int cs_str_string_minus_equals (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
 Remove from a config item by string. More...
 
int cs_str_string_plus_equals (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
 Add to a config item by string. More...
 
int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
 Set a config item by string. More...
 

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 166 of file set.c.

167 {
168  struct ConfigSet *cs = mutt_mem_calloc(1, sizeof(*cs));
169 
171  mutt_hash_set_destructor(cs->hash, destroy, (intptr_t) cs);
172 
173  return cs;
174 }
Container for lots of config items.
Definition: set.h:227
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
static void destroy(int type, void *obj, intptr_t data)
Callback function for the Hash Table - Implements hash_hdata_free_t.
Definition: set.c:47
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:229
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:293
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition: hash.c:251
#define MUTT_HASH_NO_FLAGS
No flags are set.
Definition: hash.h:97
+ 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 180 of file set.c.

181 {
182  if (!ptr || !*ptr)
183  return;
184 
185  struct ConfigSet *cs = *ptr;
186 
187  mutt_hash_free(&cs->hash);
188  FREE(ptr);
189 }
Container for lots of config items.
Definition: set.h:227
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:447
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:229
#define FREE(x)
Definition: memory.h:40
+ 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 199 of file set.c.

200 {
201  if (!(he->type & DT_INHERITED))
202  return he;
203 
204  struct Inheritance *i = he->data;
205  return cs_get_base(i->parent);
206 }
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
An inherited config item.
Definition: inheritance.h:31
void * data
User-supplied data.
Definition: hash.h:47
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
+ 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 214 of file set.c.

215 {
216  if (!cs || !name)
217  return NULL;
218 
219  struct HashElem *he = mutt_hash_find_elem(cs->hash, name);
220  if (!he)
221  return NULL;
222 
223  if (he->type != DT_SYNONYM)
224  return he;
225 
226  const struct ConfigDef *cdef = he->data;
227 
228  return cdef->var;
229 }
const char * name
Name of this config item.
Definition: inheritance.h:34
Config item definition.
Definition: set.h:61
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:369
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:229
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
#define DT_SYNONYM
synonym for another variable
Definition: types.h:42
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
+ 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 237 of file set.c.

238 {
239  if (!cs)
240  return NULL;
241 
242  type = DTYPE(type);
243  if ((type < 1) || (type >= mutt_array_size(cs->types)))
244  return NULL;
245 
246  if (!cs->types[type].name)
247  return NULL;
248 
249  return &cs->types[type];
250 }
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:230
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
#define mutt_array_size(x)
Definition: memory.h:33
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const char * name
Name of the type, e.g. "String".
Definition: set.h:90
+ Here is the caller graph for this function:

◆ cs_register_type()

bool cs_register_type ( struct ConfigSet cs,
unsigned int  type,
const struct ConfigSetType cst 
)

Register a type of config item.

Parameters
csConfig items
typeObject type, e.g. DT_BOOL
cstStructure defining the type
Return values
boolTrue, if type was registered successfully

Definition at line 259 of file set.c.

260 {
261  if (!cs || !cst)
262  return false;
263 
264  if (!cst->name || !cst->string_set || !cst->string_get || !cst->reset ||
265  !cst->native_set || !cst->native_get)
266  {
267  return false;
268  }
269 
270  if (type >= mutt_array_size(cs->types))
271  return false;
272 
273  if (cs->types[type].name)
274  return false; /* already registered */
275 
276  cs->types[type] = *cst;
277  return true;
278 }
int(* string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.h:107
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:230
int(* string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a config item as a string.
Definition: set.h:124
int(* native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Set a config item by string.
Definition: set.h:140
#define mutt_array_size(x)
Definition: memory.h:33
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const char * name
Name of the type, e.g. "String".
Definition: set.h:90
intptr_t(* native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get a string from a config item.
Definition: set.h:156
int(* reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.h:203
+ Here is the caller graph for this function:

◆ cs_register_variables()

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

Register a set of config items.

Parameters
csConfig items
varsVariable definition
flagsFlags, e.g. DT_NO_VARIABLE
Return values
boolTrue, if all variables were registered successfully

Definition at line 287 of file set.c.

288 {
289  if (!cs || !vars)
290  return false;
291 
292  struct Buffer err = mutt_buffer_make(0);
293 
294  bool rc = true;
295 
296  for (size_t i = 0; vars[i].name; i++)
297  {
298  vars[i].type |= flags;
299  if (!reg_one_var(cs, &vars[i], &err))
300  {
301  mutt_debug(LL_DEBUG1, "%s\n", mutt_b2s(&err));
302  rc = false;
303  }
304  }
305 
306  mutt_buffer_dealloc(&err);
307  return rc;
308 }
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
static struct HashElem * reg_one_var(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Register one config item.
Definition: set.c:129
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
const char * name
User-visible name.
Definition: set.h:63
#define mutt_b2s(buf)
Definition: buffer.h:41
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
Log at debug level 1.
Definition: logging.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ 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 parent,
const char *  name 
)

Create in inherited config item.

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

Definition at line 317 of file set.c.

319 {
320  if (!cs || !parent)
321  return NULL;
322 
323  struct Inheritance *i = mutt_mem_calloc(1, sizeof(*i));
324  i->parent = parent;
325  i->name = mutt_str_dup(name);
326 
327  struct HashElem *he = mutt_hash_typed_insert(cs->hash, i->name, DT_INHERITED, i);
328  if (!he)
329  {
330  FREE(&i->name);
331  FREE(&i);
332  }
333 
334  return he;
335 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
const char * name
Name of this config item.
Definition: inheritance.h:34
An inherited config item.
Definition: inheritance.h:31
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:229
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:309
#define FREE(x)
Definition: memory.h:40
The item stored in a Hash Table.
Definition: hash.h:43
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
+ 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 342 of file set.c.

343 {
344  if (!cs || !name)
345  return;
346 
347  mutt_hash_delete(cs->hash, name, NULL);
348 }
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:229
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition: hash.c:419
+ 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 500 of file set.c.

501 {
502  if (!cs || !he || !result)
503  return CSR_ERR_CODE;
504 
505  const struct ConfigDef *cdef = NULL;
506  const struct ConfigSetType *cst = NULL;
507 
508  if (he->type & DT_INHERITED)
509  {
510  struct HashElem *he_base = cs_get_base(he);
511  cdef = he_base->data;
512  cst = cs_get_type_def(cs, he_base->type);
513  }
514  else
515  {
516  cdef = he->data;
517  cst = cs_get_type_def(cs, he->type);
518  }
519 
520  if (!cst)
521  return CSR_ERR_CODE; // LCOV_EXCL_LINE
522 
523  return cst->string_get(cs, NULL, cdef, result);
524 }
Type definition for a config item.
Definition: set.h:88
int(* string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a config item as a string.
Definition: set.h:124
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
Config item definition.
Definition: set.h:61
void * data
User-supplied data.
Definition: hash.h:47
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
+ 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 432 of file set.c.

434 {
435  if (!cs || !he)
436  return CSR_ERR_CODE;
437 
438  struct ConfigDef *cdef = NULL;
439 
440  if (he->type & DT_INHERITED)
441  {
442  struct HashElem *he_base = cs_get_base(he);
443  cdef = he_base->data;
444  mutt_debug(LL_DEBUG1, "Variable '%s' is inherited type\n", cdef->name);
445  return CSR_ERR_CODE;
446  }
447 
448  cdef = he->data;
449  if (!cdef)
450  return CSR_ERR_CODE; // LCOV_EXCL_LINE
451 
452  const struct ConfigSetType *cst = cs_get_type_def(cs, he->type);
453  if (!cst)
454  {
455  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
456  return CSR_ERR_CODE;
457  }
458 
459  int rc = cst->string_set(cs, NULL, cdef, value, err);
460  if (CSR_RESULT(rc) != CSR_SUCCESS)
461  return rc;
462 
463  return CSR_SUCCESS;
464 }
Type definition for a config item.
Definition: set.h:88
int(* string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.h:107
#define CSR_RESULT(x)
Definition: set.h:52
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
Config item definition.
Definition: set.h:61
const char * name
User-visible name.
Definition: set.h:63
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
void * data
User-supplied data.
Definition: hash.h:47
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
Log at debug level 1.
Definition: logging.h:40
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
+ 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 818 of file set.c.

819 {
820  if (!cs || !he)
821  return INT_MIN;
822 
823  struct ConfigDef *cdef = NULL;
824  const struct ConfigSetType *cst = NULL;
825  void *var = NULL;
826 
827  if (he->type & DT_INHERITED)
828  {
829  struct Inheritance *i = he->data;
830 
831  // inherited, value not set
832  if (DTYPE(he->type) == 0)
833  return cs_he_native_get(cs, i->parent, err);
834 
835  // inherited, value set
836  struct HashElem *he_base = cs_get_base(he);
837  cdef = he_base->data;
838  cst = cs_get_type_def(cs, he_base->type);
839  var = &i->var;
840  }
841  else
842  {
843  // not inherited
844  cdef = he->data;
845  cst = cs_get_type_def(cs, he->type);
846  if (cdef->type & DT_NO_VARIABLE)
847  var = &cdef->var;
848  else
849  var = cdef->var;
850  }
851 
852  if (!var || !cdef)
853  return INT_MIN; // LCOV_EXCL_LINE
854 
855  if (!cst)
856  {
857  mutt_buffer_printf(err, _("Variable '%s' has an invalid type %d"), cdef->name, he->type);
858  return INT_MIN;
859  }
860 
861  return cst->native_get(cs, var, cdef, err);
862 }
Type definition for a config item.
Definition: set.h:88
#define DT_NO_VARIABLE
Config item doesn&#39;t have a backing global variable.
Definition: types.h:84
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Config item definition.
Definition: set.h:61
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:63
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
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:818
intptr_t(* native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get a string from a config item.
Definition: set.h:156
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
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 707 of file set.c.

709 {
710  if (!cs || !he)
711  return CSR_ERR_CODE;
712 
713  struct ConfigDef *cdef = NULL;
714  const struct ConfigSetType *cst = NULL;
715  void *var = NULL;
716 
717  if (he->type & DT_INHERITED)
718  {
719  struct Inheritance *i = he->data;
720  struct HashElem *he_base = cs_get_base(he);
721  cdef = he_base->data;
722  cst = cs_get_type_def(cs, he_base->type);
723  var = &i->var;
724  }
725  else
726  {
727  cdef = he->data;
728  cst = cs_get_type_def(cs, he->type);
729  if (cdef->type & DT_NO_VARIABLE)
730  var = &cdef->var;
731  else
732  var = cdef->var;
733  }
734 
735  if (!cst)
736  {
737  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
738  return CSR_ERR_CODE;
739  }
740 
741  if (!var || !cdef)
742  return CSR_ERR_CODE; // LCOV_EXCL_LINE
743 
744  int rc = cst->native_set(cs, var, cdef, value, err);
745  if (CSR_RESULT(rc) != CSR_SUCCESS)
746  return rc;
747 
748  if (he->type & DT_INHERITED)
749  he->type = cdef->type | DT_INHERITED;
750 
751  return rc;
752 }
Type definition for a config item.
Definition: set.h:88
#define DT_NO_VARIABLE
Config item doesn&#39;t have a backing global variable.
Definition: types.h:84
#define CSR_RESULT(x)
Definition: set.h:52
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
Config item definition.
Definition: set.h:61
int(* native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Set a config item by string.
Definition: set.h:140
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:63
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
Log at debug level 1.
Definition: logging.h:40
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
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_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 357 of file set.c.

358 {
359  if (!cs || !he)
360  return CSR_ERR_CODE;
361 
362  /* An inherited var that's already pointing to its parent.
363  * Return 'success', but don't send a notification. */
364  if ((he->type & DT_INHERITED) && (DTYPE(he->type) == 0))
365  return CSR_SUCCESS;
366 
367  int rc = CSR_SUCCESS;
368 
369  if (he->type & DT_INHERITED)
370  {
371  struct Inheritance *i = he->data;
372  struct HashElem *he_base = cs_get_base(he);
373  struct ConfigDef *cdef = he_base->data;
374  if (!cdef)
375  return CSR_ERR_CODE; // LCOV_EXCL_LINE
376 
377  const struct ConfigSetType *cst = cs_get_type_def(cs, he_base->type);
378  if (cst && cst->destroy)
379  cst->destroy(cs, (void **) &i->var, cdef);
380 
381  he->type = DT_INHERITED;
382  }
383  else
384  {
385  struct ConfigDef *cdef = he->data;
386  if (!cdef)
387  return CSR_ERR_CODE; // LCOV_EXCL_LINE
388 
389  const struct ConfigSetType *cst = cs_get_type_def(cs, he->type);
390  if (cst)
391  {
392  if (cdef->type & DT_NO_VARIABLE)
393  rc = cst->reset(cs, &cdef->var, cdef, err);
394  else if (cdef->var)
395  rc = cst->reset(cs, cdef->var, cdef, err);
396  }
397  }
398 
399  return rc;
400 }
Type definition for a config item.
Definition: set.h:88
void(* destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a config item.
Definition: set.h:216
#define DT_NO_VARIABLE
Config item doesn&#39;t have a backing global variable.
Definition: types.h:84
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
Config item definition.
Definition: set.h:61
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
An inherited config item.
Definition: inheritance.h:31
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
int(* reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.h:203
+ 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 637 of file set.c.

638 {
639  if (!cs || !he || !result)
640  return CSR_ERR_CODE;
641 
642  struct ConfigDef *cdef = NULL;
643  const struct ConfigSetType *cst = NULL;
644  void *var = NULL;
645 
646  if (he->type & DT_INHERITED)
647  {
648  struct Inheritance *i = he->data;
649 
650  // inherited, value not set
651  if (DTYPE(he->type) == 0)
652  return cs_he_string_get(cs, i->parent, result);
653 
654  // inherited, value set
655  struct HashElem *he_base = cs_get_base(he);
656  cdef = he_base->data;
657  cst = cs_get_type_def(cs, he_base->type);
658  var = &i->var;
659  }
660  else
661  {
662  // not inherited
663  cdef = he->data;
664  cst = cs_get_type_def(cs, he->type);
665  if (cdef->type & DT_NO_VARIABLE)
666  var = &cdef->var;
667  else
668  var = cdef->var;
669  }
670 
671  if (!cdef || !cst)
672  return CSR_ERR_CODE; // LCOV_EXCL_LINE
673 
674  return cst->string_get(cs, var, cdef, result);
675 }
Type definition for a config item.
Definition: set.h:88
#define DT_NO_VARIABLE
Config item doesn&#39;t have a backing global variable.
Definition: types.h:84
int(* string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a config item as a string.
Definition: set.h:124
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
Config item definition.
Definition: set.h:61
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
An inherited config item.
Definition: inheritance.h:31
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:637
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
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_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 975 of file set.c.

977 {
978  if (!cs || !he)
979  return CSR_ERR_CODE;
980 
981  struct ConfigDef *cdef = NULL;
982  const struct ConfigSetType *cst = NULL;
983  void *var = NULL;
984 
985  if (he->type & DT_INHERITED)
986  {
987  struct Inheritance *i = he->data;
988  struct HashElem *he_base = cs_get_base(he);
989  cdef = he_base->data;
990  cst = cs_get_type_def(cs, he_base->type);
991  var = &i->var;
992  }
993  else
994  {
995  cdef = he->data;
996  cst = cs_get_type_def(cs, he->type);
997  if (cdef->type & DT_NO_VARIABLE)
998  var = &cdef->var;
999  else
1000  var = cdef->var;
1001  }
1002 
1003  if (!var || !cdef)
1004  return INT_MIN; // LCOV_EXCL_LINE
1005 
1006  if (!cst)
1007  {
1008  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
1009  return CSR_ERR_CODE;
1010  }
1011 
1012  if (!cst->string_minus_equals)
1013  {
1014  // L10N: e.g. Type 'boolean' doesn't support operation '+='
1015  mutt_buffer_printf(err, _("Type '%s' doesn't support operation '%s'"), cst->name, "-=");
1017  }
1018 
1019  int rc = cst->string_minus_equals(cs, var, cdef, value, err);
1020  if (CSR_RESULT(rc) != CSR_SUCCESS)
1021  return rc;
1022 
1023  if (he->type & DT_INHERITED)
1024  he->type = cdef->type | DT_INHERITED;
1025 
1026  return rc;
1027 }
Type definition for a config item.
Definition: set.h:88
#define DT_NO_VARIABLE
Config item doesn&#39;t have a backing global variable.
Definition: types.h:84
#define CSR_RESULT(x)
Definition: set.h:52
#define CSV_INV_NOT_IMPL
Operation not permitted for the type.
Definition: set.h:49
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Config item definition.
Definition: set.h:61
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:63
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
int(* string_minus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Remove from a config item as a string.
Definition: set.h:188
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
Log at debug level 1.
Definition: logging.h:40
const char * name
Name of the type, e.g. "String".
Definition: set.h:90
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
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_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 889 of file set.c.

891 {
892  if (!cs || !he)
893  return CSR_ERR_CODE;
894 
895  struct ConfigDef *cdef = NULL;
896  const struct ConfigSetType *cst = NULL;
897  void *var = NULL;
898 
899  if (he->type & DT_INHERITED)
900  {
901  struct Inheritance *i = he->data;
902  struct HashElem *he_base = cs_get_base(he);
903  cdef = he_base->data;
904  cst = cs_get_type_def(cs, he_base->type);
905  var = &i->var;
906  }
907  else
908  {
909  cdef = he->data;
910  cst = cs_get_type_def(cs, he->type);
911  if (cdef->type & DT_NO_VARIABLE)
912  var = &cdef->var;
913  else
914  var = cdef->var;
915  }
916 
917  if (!var || !cdef)
918  return INT_MIN; // LCOV_EXCL_LINE
919 
920  if (!cst)
921  {
922  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
923  return CSR_ERR_CODE;
924  }
925 
926  if (!cst->string_plus_equals)
927  {
928  // L10N: e.g. Type 'boolean' doesn't support operation '+='
929  mutt_buffer_printf(err, _("Type '%s' doesn't support operation '%s'"), cst->name, "+=");
931  }
932 
933  int rc = cst->string_plus_equals(cs, var, cdef, value, err);
934  if (CSR_RESULT(rc) != CSR_SUCCESS)
935  return rc;
936 
937  if (he->type & DT_INHERITED)
938  he->type = cdef->type | DT_INHERITED;
939 
940  return rc;
941 }
Type definition for a config item.
Definition: set.h:88
#define DT_NO_VARIABLE
Config item doesn&#39;t have a backing global variable.
Definition: types.h:84
#define CSR_RESULT(x)
Definition: set.h:52
#define CSV_INV_NOT_IMPL
Operation not permitted for the type.
Definition: set.h:49
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Config item definition.
Definition: set.h:61
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:63
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
Log at debug level 1.
Definition: logging.h:40
const char * name
Name of the type, e.g. "String".
Definition: set.h:90
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
int(* string_plus_equals)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Add to a config item by string.
Definition: set.h:172
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
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_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 559 of file set.c.

561 {
562  if (!cs || !he)
563  return CSR_ERR_CODE;
564 
565  struct ConfigDef *cdef = NULL;
566  const struct ConfigSetType *cst = NULL;
567  void *var = NULL;
568 
569  if (he->type & DT_INHERITED)
570  {
571  struct Inheritance *i = he->data;
572  struct HashElem *he_base = cs_get_base(he);
573  cdef = he_base->data;
574  cst = cs_get_type_def(cs, he_base->type);
575  var = &i->var;
576  }
577  else
578  {
579  cdef = he->data;
580  cst = cs_get_type_def(cs, he->type);
581  if (cdef->type & DT_NO_VARIABLE)
582  var = &cdef->var;
583  else
584  var = cdef->var;
585  }
586 
587  if (!cdef)
588  return CSR_ERR_CODE; // LCOV_EXCL_LINE
589 
590  if (!cst)
591  {
592  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
593  return CSR_ERR_CODE;
594  }
595 
596  int rc = cst->string_set(cs, var, cdef, value, err);
597  if (CSR_RESULT(rc) != CSR_SUCCESS)
598  return rc;
599 
600  if (he->type & DT_INHERITED)
601  he->type = cdef->type | DT_INHERITED;
602 
603  return rc;
604 }
Type definition for a config item.
Definition: set.h:88
#define DT_NO_VARIABLE
Config item doesn&#39;t have a backing global variable.
Definition: types.h:84
int(* string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.h:107
#define CSR_RESULT(x)
Definition: set.h:52
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
Config item definition.
Definition: set.h:61
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:63
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
Log at debug level 1.
Definition: logging.h:40
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
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_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 536 of file set.c.

537 {
538  if (!cs || !name)
539  return CSR_ERR_CODE;
540 
541  struct HashElem *he = cs_get_elem(cs, name);
542  if (!he)
543  {
544  mutt_buffer_printf(result, _("Unknown variable '%s'"), name);
545  return CSR_ERR_UNKNOWN;
546  }
547 
548  return cs_he_initial_get(cs, he, result);
549 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
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:500
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
The item stored in a Hash Table.
Definition: hash.h:43
+ 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 474 of file set.c.

476 {
477  if (!cs || !name)
478  return CSR_ERR_CODE;
479 
480  struct HashElem *he = cs_get_elem(cs, name);
481  if (!he)
482  {
483  mutt_buffer_printf(err, _("Unknown variable '%s'"), name);
484  return CSR_ERR_UNKNOWN;
485  }
486 
487  return cs_he_initial_set(cs, he, value, err);
488 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
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:432
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_native_get()

intptr_t cs_str_native_get ( const struct ConfigSet cs,
const char *  name,
struct Buffer err 
)

Natively get the value of a string config item.

Parameters
csConfig items
nameName of config item
errBuffer for error messages
Return values
intptr_tNative pointer/value
INT_MINError

Definition at line 872 of file set.c.

873 {
874  if (!cs || !name)
875  return INT_MIN;
876 
877  struct HashElem *he = cs_get_elem(cs, name);
878  return cs_he_native_get(cs, he, err);
879 }
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
The item stored in a Hash Table.
Definition: hash.h:43
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:818
+ 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 762 of file set.c.

764 {
765  if (!cs || !name)
766  return CSR_ERR_CODE;
767 
768  struct HashElem *he = cs_get_elem(cs, name);
769  if (!he)
770  {
771  mutt_buffer_printf(err, _("Unknown variable '%s'"), name);
772  return CSR_ERR_UNKNOWN;
773  }
774 
775  struct ConfigDef *cdef = NULL;
776  const struct ConfigSetType *cst = NULL;
777  void *var = NULL;
778 
779  if (he->type & DT_INHERITED)
780  {
781  struct Inheritance *i = he->data;
782  struct HashElem *he_base = cs_get_base(he);
783  cdef = he_base->data;
784  cst = cs_get_type_def(cs, he_base->type);
785  var = &i->var;
786  }
787  else
788  {
789  cdef = he->data;
790  cst = cs_get_type_def(cs, he->type);
791  if (cdef->type & DT_NO_VARIABLE)
792  var = &cdef->var;
793  else
794  var = cdef->var;
795  }
796 
797  if (!cst || !var || !cdef)
798  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
799 
800  int rc = cst->native_set(cs, var, cdef, value, err);
801  if (CSR_RESULT(rc) != CSR_SUCCESS)
802  return rc;
803 
804  if (he->type & DT_INHERITED)
805  he->type = cdef->type | DT_INHERITED;
806 
807  return rc;
808 }
Type definition for a config item.
Definition: set.h:88
#define DT_NO_VARIABLE
Config item doesn&#39;t have a backing global variable.
Definition: types.h:84
#define CSR_RESULT(x)
Definition: set.h:52
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:199
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Config item definition.
Definition: set.h:61
int(* native_set)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Set a config item by string.
Definition: set.h:140
An inherited config item.
Definition: inheritance.h:31
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
void * data
User-supplied data.
Definition: hash.h:47
void * var
Pointer to the global variable.
Definition: set.h:65
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:237
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define DT_INHERITED
Config item is inherited.
Definition: types.h:80
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_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 409 of file set.c.

410 {
411  if (!cs || !name)
412  return CSR_ERR_CODE;
413 
414  struct HashElem *he = cs_get_elem(cs, name);
415  if (!he)
416  {
417  mutt_buffer_printf(err, _("Unknown variable '%s'"), name);
418  return CSR_ERR_UNKNOWN;
419  }
420 
421  return cs_he_reset(cs, he, err);
422 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
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:357
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_string_get()

int cs_str_string_get ( const struct ConfigSet cs,
const char *  name,
struct Buffer result 
)

Get a config item as a string.

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

Definition at line 684 of file set.c.

685 {
686  if (!cs || !name)
687  return CSR_ERR_CODE;
688 
689  struct HashElem *he = cs_get_elem(cs, name);
690  if (!he)
691  {
692  mutt_buffer_printf(result, _("Unknown variable '%s'"), name);
693  return CSR_ERR_UNKNOWN;
694  }
695 
696  return cs_he_string_get(cs, he, result);
697 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
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:637
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_string_minus_equals()

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

Remove from 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 1037 of file set.c.

1039 {
1040  if (!cs || !name)
1041  return CSR_ERR_CODE;
1042 
1043  struct HashElem *he = cs_get_elem(cs, name);
1044  if (!he)
1045  {
1046  mutt_buffer_printf(err, _("Unknown variable '%s'"), name);
1047  return CSR_ERR_UNKNOWN;
1048  }
1049 
1050  return cs_he_string_minus_equals(cs, he, value, err);
1051 }
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:975
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_string_plus_equals()

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

Add to 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 951 of file set.c.

953 {
954  if (!cs || !name)
955  return CSR_ERR_CODE;
956 
957  struct HashElem *he = cs_get_elem(cs, name);
958  if (!he)
959  {
960  mutt_buffer_printf(err, _("Unknown variable '%s'"), name);
961  return CSR_ERR_UNKNOWN;
962  }
963 
964  return cs_he_string_plus_equals(cs, he, value, err);
965 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
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:889
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
The item stored in a Hash Table.
Definition: hash.h:43
+ 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 614 of file set.c.

616 {
617  if (!cs || !name)
618  return CSR_ERR_CODE;
619 
620  struct HashElem *he = cs_get_elem(cs, name);
621  if (!he)
622  {
623  mutt_buffer_printf(err, _("Unknown variable '%s'"), name);
624  return CSR_ERR_UNKNOWN;
625  }
626 
627  return cs_he_string_set(cs, he, value, err);
628 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:37
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
The item stored in a Hash Table.
Definition: hash.h:43
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:559
+ Here is the call graph for this function:
+ Here is the caller graph for this function: