20 #include <t3config/config_api.h>
21 #include <t3config/config_errors.h>
52 #define T3_CONFIG_VERSION 0
88 FILE *(*open)(
const char *name,
void *data);
97 #define T3_CONFIG_VERBOSE_ERROR (1<<0)
101 #define T3_CONFIG_INCLUDE_DFLT (1<<1)
105 #define T3_CONFIG_INCLUDE_USER (1<<2)
107 #define T3_CONFIG_ERROR_FILE_NAME (1<<3)
125 #define T3_ERR_OUT_OF_RANGE (-80)
127 #define T3_ERR_PARSE_ERROR (-79)
129 #define T3_ERR_DUPLICATE_KEY (-78)
132 #define T3_ERR_INVALID_CONSTRAINT (-77)
134 #define T3_ERR_INVALID_KEY_TYPE (-76)
136 #define T3_ERR_INVALID_KEY (-75)
138 #define T3_ERR_CONSTRAINT_VIOLATION (-74)
140 #define T3_ERR_RECURSIVE_TYPE (-73)
142 #define T3_ERR_RECURSIVE_INCLUDE (-72)
145 #if INT_MAX < 2147483647
146 typedef long t3_config_int_t;
147 #define T3_CONFIG_INT_MAX LONG_MAX
148 #define T3_CONFIG_INT_MIN LONG_MIN
149 #define T3_CONFIG_INT_PRI "l"
151 typedef int t3_config_int_t;
152 #define T3_CONFIG_INT_MAX INT_MAX
153 #define T3_CONFIG_INT_MIN INT_MIN
154 #define T3_CONFIG_INT_PRI ""
406 #define T3_CONFIG_SPLIT_PATH (1<<0)
412 #define T3_CONFIG_CLEAN_NAME (1<<1)
436 T3_CONFIG_XDG_CONFIG_HOME,
437 T3_CONFIG_XDG_DATA_HOME,
438 T3_CONFIG_XDG_CACHE_HOME,
439 T3_CONFIG_XDG_RUNTIME_DIR
492 const char *file_name);
t3_config_t * t3_config_read_file(FILE *file, t3_config_error_t *error, const t3_config_opts_t *opts)
Read a config from a FILE.
Definition: config.c:94
t3_config_t * t3_config_get_next(const t3_config_t *config)
Get the next sub-config from a section or list.
Definition: config.c:445
int t3_config_set_list_type(t3_config_t *config, t3_config_type_t type)
Set the type of list of an existing list-type (sub-)config.
Definition: config.c:372
FILE * t3_config_get_write_file(t3_config_write_file_t *file)
Get the FILE member of a t3_config_write_file_t returned by t3_config_open_write or t3_config_xdg_ope...
Definition: xdg.c:295
void t3_config_erase(t3_config_t *config, const char *name)
Erase an item from a (sub-)config.
Definition: config.c:198
A list of un-named items.
Definition: config.h:61
const char * t3_config_get_string(const t3_config_t *config)
Get the string value from a config with T3_CONFIG_STRING type.
int line_number
The line number where the error occured.
Definition: config.h:117
Floating point value (double).
Definition: config.h:60
t3_config_write_file_t * t3_config_open_write(const char *file_name)
Open a configuration file for writing.
Definition: xdg.c:248
t3_bool t3_config_get_bool(const t3_config_t *config)
Get the boolean value from a config with T3_CONFIG_BOOL type.
FILE * t3_config_xdg_open_read(t3_config_xdg_dirs_t xdg_dir, const char *program_dir, const char *file_name)
Open a configuration file for reading in one of the XDG Base Directory Specification directories...
Definition: xdg.c:180
t3_config_type_t t3_config_get_type(const t3_config_t *config)
Get the type of a (sub-)config.
Definition: config.c:397
t3_config_write_file_t * t3_config_xdg_open_write(t3_config_xdg_dirs_t xdg_dir, const char *program_dir, const char *file_name)
Open a configuration file for writing in one of the XDG Base Directory Specification directories...
Definition: xdg.c:200
t3_config_schema_t * t3_config_read_schema_file(FILE *file, t3_config_error_t *error, const t3_config_opts_t *opts)
Read a schema from a FILE.
Definition: schema.c:333
void * data
Data passed to the callback function.
Definition: config.h:89
t3_bool t3_config_close_write(t3_config_write_file_t *file, t3_bool cancel_rename, t3_bool force)
Close a t3_config_write_file_t returned by t3_config_open_write or t3_config_xdg_open_write.
Definition: xdg.c:299
t3_config_t * t3_config_add_plist(t3_config_t *config, const char *name, int *error)
Add (or overwrite) a plist to the (sub-)config.
t3_config_t * t3_config_unlink_from_list(t3_config_t *list, t3_config_t *item)
Unlink an item from a (sub-)config or list.
Definition: config.c:172
A list of un-named items, written using % notation.
Definition: config.h:63
char * file_name
File in which the error occured.
Definition: config.h:119
An opaque struct representing a schema.
t3_config_xdg_dirs_t
Constants for t3_config_xdg_open_read and t3_config_xdg_open_write.
Definition: config.h:435
t3_bool t3_config_xdg_supported(void)
Query whether this library instance supports the XDG Base Directory Specification support functions...
Definition: xdg.c:101
t3_config_int_t t3_config_get_int_dflt(const t3_config_t *config, t3_config_int_t dflt)
Get the integer value from a config with T3_CONFIG_INT type.
t3_config_t * t3_config_new(void)
Create a new config.
Definition: config.c:31
int t3_config_add_bool(t3_config_t *config, const char *name, t3_bool value)
Add (or overwrite) a boolean value to a (sub-)config.
A structure representing an error, with line number.
Definition: config.h:115
t3_bool t3_config_get_bool_dflt(const t3_config_t *config, t3_bool dflt)
Get the boolean value from a config with T3_CONFIG_BOOL type.
t3_config_t * t3_config_find(const t3_config_t *config, t3_bool(*predicate)(const t3_config_t *, const void *), const void *data, t3_config_t *start_from)
Find a specific value in a section or list.
Definition: config.c:457
A list of named items.
Definition: config.h:62
double t3_config_get_number_dflt(const t3_config_t *config, double dflt)
Get the floating point value from a config with T3_CONFIG_NUMBER type.
String value.
Definition: config.h:59
t3_bool t3_config_is_list(const t3_config_t *config)
Check if a (sub-)config is a T3_CONFIG_LIST or T3_CONFIG_PLIST.
Definition: config.c:401
char * t3_config_xdg_get_path(t3_config_xdg_dirs_t xdg_dir, const char *program_dir, size_t file_name_len)
Get a variable containing a specific XDG directory path.
Definition: xdg.c:120
char * extra
Further information about the error or NULL, but only if T3_CONFIG_VERBOSE_ERROR was set...
Definition: config.h:118
An opaque struct representing a config or sub-config.
Definition: config_internal.h:25
const char * t3_config_get_file_name(const t3_config_t *config)
Get the file name in which the (sub-)configuration item was defined.
Definition: config.c:511
int t3_config_get_line(const t3_config_t *config)
Get the line number at which the (sub-)config was defined.
Definition: config.c:409
Options struct used when reading a file.
Definition: config.h:77
int t3_config_get_length(const t3_config_t *config)
Get the number of elements in a section or list.
Definition: config.c:449
t3_config_schema_t * t3_config_read_schema_buffer(const char *buffer, size_t size, t3_config_error_t *error, const t3_config_opts_t *opts)
Read a schema from memory.
Definition: schema.c:340
const char * t3_config_get_string_dflt(const t3_config_t *config, const char *dflt)
Get the string value from a config with T3_CONFIG_STRING type.
Integer value, at least 32 bits wide.
Definition: config.h:58
A structure representing file to write to.
Definition: xdg.c:83
void t3_config_delete_schema(t3_config_schema_t *schema)
Free all memory used by schema.
Definition: schema.c:349
FILE * t3_config_xdg_get_file(t3_config_write_file_t *file)
Get the FILE member of a t3_config_write_file_t returned by t3_config_xdg_open_write.
Definition: xdg.c:238
t3_config_t * t3_config_read_buffer(const char *buffer, size_t size, t3_config_error_t *error, const t3_config_opts_t *opts)
Read a config from memory.
Definition: config.c:105
int t3_config_add_string(t3_config_t *config, const char *name, const char *value)
Add (or overwrite) a string value to a (sub-)config.
Definition: config.c:303
Boolean value.
Definition: config.h:57
t3_config_type_t
Types of values that can be stored in a config.
Definition: config.h:55
t3_bool t3_config_validate(t3_config_t *config, const t3_config_schema_t *schema, t3_config_error_t *error, int flags)
Validate that a config adheres to a schema.
Definition: schema.c:143
long t3_config_get_version(void)
Get the value of T3_CONFIG_VERSION corresponding to the actual used library.
Definition: config.c:478
int error
An integer indicating what went wrong.
Definition: config.h:116
t3_config_int_t t3_config_get_int(const t3_config_t *config)
Get the integer value from a config with T3_CONFIG_INT type.
int t3_config_add_int(t3_config_t *config, const char *name, t3_config_int_t value)
Add (or overwrite) an integer value to a (sub-)config.
t3_config_t * t3_config_add_section(t3_config_t *config, const char *name, int *error)
Add (or overwrite) a section to the (sub-)config.
const char * t3_config_get_name(const t3_config_t *config)
Get the name of the (sub-)config.
Definition: config.c:405
void t3_config_delete(t3_config_t *config)
Free all memory used by a (sub-)config.
Definition: config.c:118
char t3_bool
A boolean type that does not clash with C++ or C99 bool.
Definition: config_api.h:47
int t3_config_add_existing(t3_config_t *config, const char *name, t3_config_t *value)
Add (or overwrite) an existing value to the (sub-)config.
Definition: config.c:348
const char ** path
The NULL-terminated array of search paths, passed to t3_config_open_from_path.
Definition: config.h:83
int t3_config_add_number(t3_config_t *config, const char *name, double value)
Add (or overwrite) an floating point number value to a (sub-)config.
Only used for uninitialized values, or as error value.
Definition: config.h:56
t3_bool t3_config_xdg_close_write(t3_config_write_file_t *file, t3_bool cancel_rename, t3_bool force)
Close a t3_config_write_file_t returned by t3_config_xdg_open_write.
Definition: xdg.c:242
int flags
Set of flags, or 0 for defaults.
Definition: config.h:78
FILE * t3_config_open_from_path(const char **path, const char *name, int flags)
Open a file for reading using a search path.
Definition: pathsearch.c:89
double t3_config_get_number(const t3_config_t *config)
Get the floating point value from a config with T3_CONFIG_NUMBER type.
t3_config_t * t3_config_add_list(t3_config_t *config, const char *name, int *error)
Add (or overwrite) a list to the (sub-)config.
void t3_config_erase_from_list(t3_config_t *list, t3_config_t *item)
Erase an item from a (sub-)config or list.
Definition: config.c:202
t3_config_t * t3_config_unlink(t3_config_t *config, const char *name)
Unlink an item from a (sub-)config.
Definition: config.c:146
t3_config_t * t3_config_get(const t3_config_t *config, const char *name)
Retrieve a sub-config.
Definition: config.c:381
int t3_config_get_line_number(const t3_config_t *config)
Get the line number at which the (sub-)configuration item was defined.
Definition: config.c:507
char * t3_config_take_string(t3_config_t *config)
Take ownership of the string value from a config with T3_CONFIG_STRING type.
Definition: config.c:433
const char * t3_config_strerror(int error)
Get a string description for an error code.
Definition: config.c:482
int t3_config_write_file(t3_config_t *config, FILE *file)
Write a config to a FILE.
Definition: write.c:275