A collection of config items. More...
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "types.h"
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 ConfigSet * | cs_new (size_t size) |
Create a new Config Set. | |
void | cs_free (struct ConfigSet **ptr) |
Free a Config Set. | |
struct HashElem * | cs_get_base (struct HashElem *he) |
Find the root Config Item. | |
struct HashElem * | cs_get_elem (const struct ConfigSet *cs, const char *name) |
Get the HashElem representing a config item. | |
const struct ConfigSetType * | cs_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 HashElem * | cs_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 HashElem * | cs_create_variable (const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err) |
Create and register one config item. | |
struct HashElem * | cs_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. | |
A collection of config items.
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.
#define CSR_INV_VALIDATOR (1 << 5) |
#define CSV_INV_NOT_IMPL (1 << 6) |
#define CSR_RESULT | ( | x | ) | ((x) & CSR_RESULT_MASK) |
struct ConfigSet * cs_new | ( | size_t | size | ) |
Create a new Config Set.
size | Number of expected config items |
ptr | New ConfigSet object |
Definition at line 127 of file set.c.
void cs_free | ( | struct ConfigSet ** | ptr | ) |
Find the root Config Item.
he | Config Item to examine |
ptr | Root Config Item |
Given an inherited HashElem, find the HashElem representing the original Config Item.
Definition at line 160 of file set.c.
Get the HashElem representing a config item.
cs | Config items |
name | Name of config item |
ptr | HashElem representing the config item |
Definition at line 175 of file set.c.
const struct ConfigSetType * cs_get_type_def | ( | const struct ConfigSet * | cs, |
unsigned int | type | ||
) |
Get the definition for a type.
cs | Config items |
type | Type to lookup, e.g. DT_NUMBER |
ptr | ConfigSetType representing the type |
Definition at line 198 of file set.c.
bool cs_register_type | ( | struct ConfigSet * | cs, |
const struct ConfigSetType * | cst | ||
) |
Register a type of config item.
cs | Config items |
cst | Structure defining the type |
true | Type was registered successfully |
Definition at line 219 of file set.c.
struct HashElem * cs_register_variable | ( | const struct ConfigSet * | cs, |
struct ConfigDef * | cdef, | ||
struct Buffer * | err | ||
) |
Register one config item.
cs | Config items |
cdef | Variable definition |
err | Buffer for error messages |
ptr | New HashElem representing the config item |
Similar to cs_create_variable() but assumes that cdef lives indefinitely.
Definition at line 249 of file set.c.
Register a set of config items.
cs | Config items |
vars | Variable definition |
true | All variables were registered successfully |
Definition at line 281 of file set.c.
struct HashElem * cs_create_variable | ( | const struct ConfigSet * | cs, |
struct ConfigDef * | cdef, | ||
struct Buffer * | err | ||
) |
Create and register one config item.
cs | Config items |
cdef | Variable definition |
err | Buffer for error messages |
ptr | New 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.
struct HashElem * cs_inherit_variable | ( | const struct ConfigSet * | cs, |
struct HashElem * | he_parent, | ||
const char * | name | ||
) |
Create in inherited config item.
cs | Config items |
he_parent | HashElem of parent config item |
name | Name of account-specific config item |
ptr | New HashElem representing the inherited config item |
Definition at line 347 of file set.c.
void cs_uninherit_variable | ( | const struct ConfigSet * | cs, |
const char * | name | ||
) |
Remove an inherited config item.
cs | Config items |
name | Name of config item to remove |
Definition at line 376 of file set.c.
Get the initial, or parent, value of a config item.
cs | Config items |
he | HashElem representing config item |
result | Buffer for results or error messages |
num | Result, 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.
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.
cs | Config items |
he | HashElem representing config item |
value | Value to set |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 461 of file set.c.
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.
cs | Config items |
he | HashElem representing config item |
err | Buffer for results or error messages |
intptr_t | Native pointer/value |
INT_MIN | Error |
Definition at line 813 of file set.c.
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.
cs | Config items |
he | HashElem representing config item |
value | Native pointer/value to set |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 708 of file set.c.
Reset a config item to its initial value.
num | Result, e.g. CSR_SUCCESS |
Definition at line 391 of file set.c.
Get a config item as a string.
cs | Config items |
he | HashElem representing config item |
result | Buffer for results or error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 663 of file set.c.
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.
cs | Config items |
he | HashElem representing config item |
value | Value to set |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 923 of file set.c.
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.
cs | Config items |
he | HashElem representing config item |
value | Value to set |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 864 of file set.c.
int cs_he_string_set | ( | const struct ConfigSet * | cs, |
struct HashElem * | he, | ||
const char * | value, | ||
struct Buffer * | err | ||
) |
Set a config item by string.
cs | Config items |
he | HashElem representing config item |
value | Value to set |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 588 of file set.c.
Delete config item from a config set.
num | Result, e.g. CSR_SUCCESS |
Definition at line 981 of file set.c.
Get the initial, or parent, value of a config item.
cs | Config items |
name | Name of config item |
result | Buffer for results or error messages |
num | Result, 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.
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.
cs | Config items |
name | Name of config item |
value | Value to set |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 503 of file set.c.
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.
cs | Config items |
name | Name of config item |
value | Native pointer/value to set |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 760 of file set.c.
Reset a config item to its initial value.
cs | Config items |
name | Name of config item |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 438 of file set.c.
int cs_str_string_set | ( | const struct ConfigSet * | cs, |
const char * | name, | ||
const char * | value, | ||
struct Buffer * | err | ||
) |
Set a config item by string.
cs | Config items |
name | Name of config item |
value | Value to set |
err | Buffer for error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 640 of file set.c.
Validator function for D_ON_STARTUP.
cdef | Variable definition |
err | Buffer for error messages |
true | Variable may only be set at startup |
Definition at line 296 of file set.h.