#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
Go to the source code of this file.
|
struct ConfigSet * | cs_new (size_t size) |
| Create a new Config Set. More...
|
|
void | cs_free (struct ConfigSet **ptr) |
| Free a Config Set. More...
|
|
struct HashElem * | cs_get_base (struct HashElem *he) |
| Find the root Config Item. More...
|
|
struct HashElem * | cs_get_elem (const struct ConfigSet *cs, const char *name) |
| Get the HashElem representing a config item. More...
|
|
const struct ConfigSetType * | cs_get_type_def (const struct ConfigSet *cs, unsigned int type) |
| Get the definition for a type. More...
|
|
bool | cs_register_type (struct ConfigSet *cs, const struct ConfigSetType *cst) |
| Register a type of config item. More...
|
|
bool | cs_register_variables (const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags) |
| Register a set of config items. More...
|
|
struct HashElem * | cs_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...
|
|
A collection of config items
- Authors
-
- Copyright
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
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.
◆ CSR_SUCCESS
Action completed successfully.
Definition at line 35 of file set.h.
◆ CSR_ERR_CODE
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
Definition at line 52 of file set.h.
◆ IP
Definition at line 54 of file set.h.
◆ cs_new()
Create a new Config Set.
- Parameters
-
size | Number of expected config items |
- Return values
-
Definition at line 166 of file set.c.
◆ cs_free()
Free a Config Set.
- Parameters
-
Definition at line 180 of file set.c.
◆ cs_get_base()
Find the root Config Item.
- Parameters
-
- Return values
-
Given an inherited HashElem, find the HashElem representing the original Config Item.
Definition at line 199 of file set.c.
◆ cs_get_elem()
Get the HashElem representing a config item.
- Parameters
-
cs | Config items |
name | Name of config item |
- Return values
-
ptr | HashElem representing the config item |
Definition at line 214 of file set.c.
◆ cs_get_type_def()
Get the definition for a type.
- Parameters
-
cs | Config items |
type | Type to lookup, e.g. DT_NUMBER |
- Return values
-
Definition at line 237 of file set.c.
◆ cs_register_type()
Register a type of config item.
- Parameters
-
cs | Config items |
cst | Structure defining the type |
- Return values
-
bool | True, if type was registered successfully |
Definition at line 258 of file set.c.
◆ cs_register_variables()
bool cs_register_variables |
( |
const struct ConfigSet * |
cs, |
|
|
struct ConfigDef |
vars[], |
|
|
uint32_t |
flags |
|
) |
| |
Register a set of config items.
- Parameters
-
cs | Config items |
vars | Variable definition |
flags | Flags, e.g. DT_NO_VARIABLE |
- Return values
-
bool | True, if all variables were registered successfully |
Definition at line 286 of file set.c.
295 for (
size_t i = 0; vars[i].
name; i++)
297 vars[i].
type |= flags;
◆ cs_inherit_variable()
Create in inherited config item.
- Parameters
-
cs | Config items |
parent | HashElem of parent config item |
name | Name of account-specific config item |
- Return values
-
ptr | New HashElem representing the inherited config item |
Definition at line 316 of file set.c.
◆ cs_uninherit_variable()
void cs_uninherit_variable |
( |
const struct ConfigSet * |
cs, |
|
|
const char * |
name |
|
) |
| |
Remove an inherited config item.
- Parameters
-
cs | Config items |
name | Name of config item to remove |
Definition at line 341 of file set.c.
◆ cs_he_initial_get()
Get the initial, or parent, value of a config item.
- Parameters
-
cs | Config items |
he | HashElem representing config item |
result | Buffer for results or error messages |
- Return values
-
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 499 of file set.c.
501 if (!cs || !he || !result)
510 cdef = he_base->
data;
522 return cst->
string_get(cs, NULL, cdef, result);
◆ 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
-
cs | Config items |
he | HashElem representing config item |
value | Value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 431 of file set.c.
442 cdef = he_base->
data;
458 int rc = cst->
string_set(cs, NULL, cdef, value, err);
◆ cs_he_native_get()
Natively get the value of a HashElem config item.
- Parameters
-
cs | Config items |
he | HashElem representing config item |
err | Buffer for results or error messages |
- Return values
-
intptr_t | Native pointer/value |
INT_MIN | Error |
Definition at line 817 of file set.c.
836 cdef = he_base->
data;
◆ cs_he_native_set()
Natively set the value of a HashElem config item.
- Parameters
-
cs | Config items |
he | HashElem representing config item |
value | Native pointer/value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 706 of file set.c.
720 cdef = he_base->
data;
743 int rc = cst->
native_set(cs, var, cdef, value, err);
◆ cs_he_reset()
Reset a config item to its initial value.
- Parameters
-
cs | Config items |
he | HashElem representing config item |
err | Buffer for error messages |
- Return values
-
Definition at line 356 of file set.c.
392 rc = cst->
reset(cs, &cdef->
var, cdef, err);
394 rc = cst->
reset(cs, cdef->
var, cdef, err);
◆ cs_he_string_get()
Get a config item as a string.
- Parameters
-
cs | Config items |
he | HashElem representing config item |
result | Buffer for results or error messages |
- Return values
-
Definition at line 636 of file set.c.
638 if (!cs || !he || !result)
655 cdef = he_base->
data;
673 return cst->
string_get(cs, var, cdef, result);
◆ 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
-
cs | Config items |
he | HashElem representing config item |
value | Value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 974 of file set.c.
988 cdef = he_base->
data;
◆ 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
-
cs | Config items |
he | HashElem representing config item |
value | Value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 888 of file set.c.
902 cdef = he_base->
data;
◆ 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
-
cs | Config items |
he | HashElem representing config item |
value | Value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 558 of file set.c.
572 cdef = he_base->
data;
595 int rc = cst->
string_set(cs, var, cdef, value, err);
◆ 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
-
cs | Config items |
name | Name of config item |
result | Buffer for results or error messages |
- Return values
-
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 535 of file set.c.
◆ 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
-
cs | Config items |
name | Name of config item |
value | Value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 473 of file set.c.
◆ 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
-
cs | Config items |
name | Name of config item |
err | Buffer for error messages |
- Return values
-
intptr_t | Native pointer/value |
INT_MIN | Error |
Definition at line 871 of file set.c.
◆ 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
-
cs | Config items |
name | Name of config item |
value | Native pointer/value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 761 of file set.c.
782 cdef = he_base->
data;
796 if (!cst || !var || !cdef)
799 int rc = cst->
native_set(cs, var, cdef, value, err);
◆ 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
-
cs | Config items |
name | Name of config item |
err | Buffer for error messages |
- Return values
-
Definition at line 408 of file set.c.
◆ 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
-
cs | Config items |
name | Name of config item |
result | Buffer for results or error messages |
- Return values
-
Definition at line 683 of file set.c.
◆ 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
-
cs | Config items |
name | Name of config item |
value | Value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 1036 of file set.c.
◆ 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
-
cs | Config items |
name | Name of config item |
value | Value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 950 of file set.c.
◆ 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
-
cs | Config items |
name | Name of config item |
value | Value to set |
err | Buffer for error messages |
- Return values
-
Definition at line 613 of file set.c.
struct ConfigSetType types[18]
All the defined config types.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
const char * name
Name of this config item.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
String manipulation buffer.
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.
void mutt_hash_set_destructor(struct HashTable *table, hash_hdata_free_t fn, intptr_t fn_data)
Set the destructor for a Hash Table.
static void destroy(int type, void *obj, intptr_t data)
Callback function for the Hash Table - Implements hash_hdata_free_t.
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
#define CSR_SUCCESS
Action completed successfully.
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
void * data
User-supplied data.
int(* string_set)(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a config item by string.
struct HashElem * parent
HashElem of parent config item.
#define DTYPE(x)
Mask for the Data Type.
struct HashTable * hash
HashTable storing the config items.
char * mutt_str_dup(const char *str)
Copy a string, safely.
@ LL_DEBUG1
Log at debug level 1.
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(* string_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a config item as a string.
An inherited config item.
#define mutt_array_size(x)
int(* reset)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a config item to its initial value.
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.
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.
int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
const char * name
User-visible name.
#define DT_SYNONYM
synonym for another variable
int type
Data type, e.g. DT_STRING.
#define DT_INHERITED
Config item is inherited.
const char * name
Name of the type, e.g. "String".
#define mutt_debug(LEVEL,...)
intptr_t(* native_get)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get a string from a config item.
int type
Type of data stored in Hash Table, e.g. DT_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.
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "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.
void(* destroy)(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy a config item.
intptr_t var
(Pointer to) value, of config item
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
#define CSR_ERR_CODE
Problem with the code.
#define MUTT_HASH_NO_FLAGS
No flags are set.
The item stored in a Hash Table.
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.
Type definition for a config item.
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.
Container for lots of config items.
#define DT_NO_VARIABLE
Config item doesn't have a backing global variable.
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.
#define CSR_ERR_INVALID
Value hasn't been set.
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
#define CSR_ERR_UNKNOWN
Unrecognised config item.
#define CSV_INV_NOT_IMPL
Operation not permitted for the type.
uint32_t type
Variable type, e.g. DT_STRING.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
static struct HashElem * reg_one_var(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Register one config item.
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.
void * var
Pointer to the global variable.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
struct HashElem * mutt_hash_find_elem(const struct HashTable *table, const char *strkey)
Find the HashElem in a Hash Table element using a key.