A collection of config items. More...
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
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 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[], int 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.
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 166 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 199 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 214 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 237 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 |
bool | True, if type was registered successfully |
Definition at line 258 of file set.c.
Register a set of config items.
cs | Config items |
vars | Variable definition |
flags | Flags, e.g. DT_NO_VARIABLE |
bool | True, if all variables were registered successfully |
Definition at line 286 of file set.c.
struct HashElem* cs_inherit_variable | ( | const struct ConfigSet * | cs, |
struct HashElem * | parent, | ||
const char * | name | ||
) |
Create in inherited config item.
cs | Config items |
parent | HashElem of parent config item |
name | Name of account-specific config item |
ptr | New HashElem representing the inherited config item |
Definition at line 316 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 341 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 499 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 431 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 817 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 706 of file set.c.
Reset a config item to its initial value.
num | Result, e.g. CSR_SUCCESS |
Definition at line 356 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 636 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 974 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 888 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 558 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 535 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 473 of file set.c.
Natively get the value of a string config item.
cs | Config items |
name | Name of config item |
err | Buffer for error messages |
intptr_t | Native pointer/value |
INT_MIN | Error |
Definition at line 871 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 761 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 408 of file set.c.
Get a config item as a string.
cs | Config items |
name | Name of config item |
result | Buffer for results or error messages |
num | Result, e.g. CSR_SUCCESS |
Definition at line 683 of file set.c.
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.
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 1036 of file set.c.
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.
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 950 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 613 of file set.c.