libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
|
Go to the source code of this file.
Functions | |
conf_t * | conf_create_empty (void) |
conf_t * | conf_create_copy (const conf_t *conf2) |
void | conf_free (conf_t *conf) |
conf_t * | conf_read_file (const char *filename, int *errline) |
conf_t * | conf_read (FILE *fp, int *errline) |
conf_t * | conf_read2 (void *fp, int *errline, bool_t compressed) |
conf_t * | conf_read_buf (const void *buf, size_t cap, int *errline) |
bool_t | conf_write_file (const conf_t *conf, const char *filename) |
bool_t | conf_write_file2 (const conf_t *conf, const char *filename, bool_t compressed) |
bool_t | conf_write (const conf_t *conf, FILE *fp) |
size_t | conf_write_buf (const conf_t *conf, void *buf, size_t cap) |
void | conf_merge (const conf_t *conf_from, conf_t *conf_to) |
bool_t | conf_get_str (const conf_t *conf, const char *key, const char **value) |
bool_t | conf_get_i (const conf_t *conf, const char *key, int *value) |
bool_t | conf_get_lli (const conf_t *conf, const char *key, long long *value) |
bool_t | conf_get_f (const conf_t *conf, const char *key, float *value) |
bool_t | conf_get_d (const conf_t *conf, const char *key, double *value) |
bool_t | conf_get_da (const conf_t *conf, const char *key, double *value) |
bool_t | conf_get_b (const conf_t *conf, const char *key, bool_t *value) |
size_t | conf_get_data (const conf_t *conf, const char *key, void *buf, size_t cap) |
void | conf_set_str (conf_t *conf, const char *key, const char *value) |
void | conf_set_i (conf_t *conf, const char *key, int value) |
void | conf_set_lli (conf_t *conf, const char *key, long long value) |
void | conf_set_f (conf_t *conf, const char *key, float value) |
void | conf_set_d (conf_t *conf, const char *key, double value) |
void | conf_set_da (conf_t *conf, const char *key, double value) |
void | conf_set_b (conf_t *conf, const char *key, bool_t value) |
void | conf_set_data (conf_t *conf, const char *key, const void *buf, size_t sz) |
bool_t | conf_get_str_v (const conf_t *conf, const char *fmt, const char **value,...) |
bool_t | conf_get_i_v (const conf_t *conf, const char *fmt, int *value,...) |
bool_t | conf_get_lli_v (const conf_t *conf, const char *fmt, long long *value,...) |
bool_t | conf_get_f_v (const conf_t *conf, const char *fmt, float *value,...) |
bool_t | conf_get_d_v (const conf_t *conf, const char *fmt, double *value,...) |
bool_t | conf_get_da_v (const conf_t *conf, const char *fmt, double *value,...) |
bool_t | conf_get_b_v (const conf_t *conf, const char *fmt, bool_t *value,...) |
size_t | conf_get_data_v (const conf_t *conf, const char *fmt, void *buf, size_t cap,...) |
void | conf_set_str_v (conf_t *conf, const char *fmt, const char *value,...) |
void | conf_set_i_v (conf_t *conf, const char *fmt, int value,...) |
void | conf_set_lli_v (conf_t *conf, const char *fmt, long long value,...) |
void | conf_set_f_v (conf_t *conf, const char *fmt, double value,...) |
void | conf_set_d_v (conf_t *conf, const char *fmt, double value,...) |
void | conf_set_da_v (conf_t *conf, const char *fmt, double value,...) |
void | conf_set_b_v (conf_t *conf, const char *fmt, bool_t value,...) |
void | conf_set_data_v (conf_t *conf, const char *fmt, const void *buf, size_t sz,...) |
bool_t | conf_walk (const conf_t *conf, const char **key, const char **value, void **cookie) |
This is a general-purpose configuration store. It's really just a key-value pair dictionary that can be read from and written to a file.
The file format is very simple, consisting of a simple sequence of lines like the following:
key = value
In addition to being able to return the full-text values of keys, this set functions also allows you to easily parse the data in a variety of formats (integers, floats, booleans, etc.). The file format also allows for comments, so it is usable as a user-written configuration parser. Lines beginning with "#" or "--" are automatically skipped.
Definition in file conf.h.
conf_t * conf_create_copy | ( | const conf_t * | conf2 | ) |
conf_t * conf_create_empty | ( | void | ) |
void conf_free | ( | conf_t * | conf | ) |
bool_t conf_get_b | ( | const conf_t * | conf, |
const char * | key, | ||
bool_t * | value | ||
) |
bool_t conf_get_b_v | ( | const conf_t * | conf, |
const char * | fmt, | ||
bool_t * | value, | ||
... | |||
) |
bool_t conf_get_d | ( | const conf_t * | conf, |
const char * | key, | ||
double * | value | ||
) |
bool_t conf_get_d_v | ( | const conf_t * | conf, |
const char * | fmt, | ||
double * | value, | ||
... | |||
) |
bool_t conf_get_da | ( | const conf_t * | conf, |
const char * | key, | ||
double * | value | ||
) |
Retrieves the 64-bit float value previously stored using conf_set_da. If found, the value is placed in value
.
Due to a limitation in MinGW, we can't use 'a' here. Instead, we directly write the binary representation of the double value. Since IEEE754 is used on all our supported platforms, that makes it portable. As future-proofing for big endian platforms, we always enforce storing the value in LE.
bool_t conf_get_da_v | ( | const conf_t * | conf, |
const char * | fmt, | ||
double * | value, | ||
... | |||
) |
size_t conf_get_data | ( | const conf_t * | conf, |
const char * | key, | ||
void * | buf, | ||
size_t | cap | ||
) |
Retrieves a binary buffer value of a configuration key.
buf | The buffer which will be filled with the configuration data. You must pre-allocate the buffer appropriately to hold the data, otherwise it will be truncated. |
cap | The capacity of buf in bytes. This function will never write more than cap bytes to buf . Use the return value of this function to determine if the value was truncated. |
buf
if it had been large enough to contain the entire value. If the key doesn't exist in the configuration, returns 0 instead. Example how to allocate an appropriately-sized buffer first, before retrieving the configuration data "for real": size_t conf_get_data_v | ( | const conf_t * | conf, |
const char * | fmt, | ||
void * | buf, | ||
size_t | cap, | ||
... | |||
) |
bool_t conf_get_f | ( | const conf_t * | conf, |
const char * | key, | ||
float * | value | ||
) |
bool_t conf_get_f_v | ( | const conf_t * | conf, |
const char * | fmt, | ||
float * | value, | ||
... | |||
) |
bool_t conf_get_i | ( | const conf_t * | conf, |
const char * | key, | ||
int * | value | ||
) |
bool_t conf_get_i_v | ( | const conf_t * | conf, |
const char * | fmt, | ||
int * | value, | ||
... | |||
) |
bool_t conf_get_lli | ( | const conf_t * | conf, |
const char * | key, | ||
long long * | value | ||
) |
bool_t conf_get_lli_v | ( | const conf_t * | conf, |
const char * | fmt, | ||
long long * | value, | ||
... | |||
) |
bool_t conf_get_str | ( | const conf_t * | conf, |
const char * | key, | ||
const char ** | value | ||
) |
bool_t conf_get_str_v | ( | const conf_t * | conf, |
const char * | fmt, | ||
const char ** | value, | ||
... | |||
) |
void conf_merge | ( | const conf_t * | conf_from, |
conf_t * | conf_to | ||
) |
Given two configurations, takes all values in ‘conf_from’ and inserts them into ‘conf_to’, in essence, merging the two configurations. After this call, ‘conf_to’ will contain all the values present in ‘conf_from’, as well as any pre-existing values that were already in ‘conf_to’. If a value exists in both ‘conf_to’ and ‘conf_from’, the value in ‘conf_from’ replaces the value in ‘conf_to’.
conf_t * conf_read | ( | FILE * | fp, |
int * | errline | ||
) |
Parses a configuration from a file. The file is structured as a series of "key = value" lines. The parser understands "#" and "--" comments.
conf_t * conf_read2 | ( | void * | fp, |
int * | errline, | ||
bool_t | compressed | ||
) |
Parses a configuration from a file. The file is structured as a series of "key = value" lines. The parser understands "#" and "--" comments.
conf_t * conf_read_buf | ( | const void * | buf, |
size_t | cap, | ||
int * | errline | ||
) |
Same as conf_read(), but takes an in-memory buffer containing the text of the configuration.
buf | The memory buffer containing the configuration file text. The buffer DOESN'T need to be NUL-terminated. |
cap | The number of bytes in buf . |
errline | Optional return argument, which will be the filled with the failing line number, if a parsing error occurs. |
conf_t * conf_read_file | ( | const char * | filename, |
int * | errline | ||
) |
Same as conf_read, but serves as a shorthand for reading directly from a file path on disk. If the file cannot be opened for reading and errline is not NULL, it will be set to -1.
NULL
if reading failed. You must free the returned configuration using conf_free() when you are done with it. void conf_set_b | ( | conf_t * | conf, |
const char * | key, | ||
bool_t | value | ||
) |
void conf_set_b_v | ( | conf_t * | conf, |
const char * | fmt, | ||
bool_t | value, | ||
... | |||
) |
void conf_set_d | ( | conf_t * | conf, |
const char * | key, | ||
double | value | ||
) |
void conf_set_d_v | ( | conf_t * | conf, |
const char * | fmt, | ||
double | value, | ||
... | |||
) |
void conf_set_da | ( | conf_t * | conf, |
const char * | key, | ||
double | value | ||
) |
void conf_set_da_v | ( | conf_t * | conf, |
const char * | fmt, | ||
double | value, | ||
... | |||
) |
void conf_set_data | ( | conf_t * | conf, |
const char * | key, | ||
const void * | buf, | ||
size_t | sz | ||
) |
Same as conf_set_str(), but allows you to pass an arbitrary binary data buffer to be set for the configuration key.
buf | The data buffer to set for the key's value. If you pass NULL here instead, the key-value pair will be removed (if present). |
sz | The number of bytes in buf . If you pass 0 here instead, the key-value pair will be removed (if present). |
void conf_set_data_v | ( | conf_t * | conf, |
const char * | fmt, | ||
const void * | buf, | ||
size_t | sz, | ||
... | |||
) |
void conf_set_f | ( | conf_t * | conf, |
const char * | key, | ||
float | value | ||
) |
void conf_set_f_v | ( | conf_t * | conf, |
const char * | fmt, | ||
double | value, | ||
... | |||
) |
void conf_set_i | ( | conf_t * | conf, |
const char * | key, | ||
int | value | ||
) |
void conf_set_i_v | ( | conf_t * | conf, |
const char * | fmt, | ||
int | value, | ||
... | |||
) |
void conf_set_lli | ( | conf_t * | conf, |
const char * | key, | ||
long long | value | ||
) |
void conf_set_lli_v | ( | conf_t * | conf, |
const char * | fmt, | ||
long long | value, | ||
... | |||
) |
void conf_set_str | ( | conf_t * | conf, |
const char * | key, | ||
const char * | value | ||
) |
Sets up a key-value pair in the conf_t structure with a string value.
key | The key name for which to set the value. If the key already exists, it will be overwritten. |
value | The value to set for the new key. If you pass NULL , this will instead remove the key-value pair (if present). |
void conf_set_str_v | ( | conf_t * | conf, |
const char * | fmt, | ||
const char * | value, | ||
... | |||
) |
bool_t conf_walk | ( | const conf_t * | conf, |
const char ** | key, | ||
const char ** | value, | ||
void ** | cookie | ||
) |
Walks all configuration key-value pairs. You must NOT add or remove key-value pairs in the configuration during the walk.
Caveat: this function skips data-type keys (created with conf_set_data()).
cookie | A helper pointer so the function knows how far it has progressed. You MUST set it to NULL before the first call. |
key | Return parameter, which will be filled with the next key it has found. |
value | Return parameter, which will be filled with the next string value it has found. |
key
and value, or
B_FALSE` if no more key-value have been found.Proper usage of this function:
bool_t conf_write | ( | const conf_t * | conf, |
FILE * | fp | ||
) |
size_t conf_write_buf | ( | const conf_t * | conf, |
void * | buf, | ||
size_t | cap | ||
) |
Writes a conf_t object to an in-memory buffer.
buf | The buffer into which to write the configuration. This must be sized sufficiently large to contain the entire configuration file. Please note that the written buffer is not explicitly NUL-terminated, so you mustn't treat it as a char string. |
cap | Capacity of buf in bytes. This function will never write more than cap bytes, even if that means cutting the configuration file short. You should check the return value of the function and allocate enough space in buf to contain the entire configuration. |
bool_t conf_write_file | ( | const conf_t * | conf, |
const char * | filename | ||
) |