13typedef struct config_pair
20typedef struct config_section
35 while (
isspace((
unsigned char)*str))
45 end = str +
strlen(str) - 1;
46 while (end > str &&
isspace((
unsigned char)*end))
122 if (line[0] ==
'\0' || line[0] ==
'#' || line[0] ==
';')
129 char* end =
strchr(line,
']');
156 currentSection = section;
160 char* equals =
strchr(line,
'=');
161 if (equals ==
NULL || currentSection ==
NULL)
231 if (config ==
NULL || section ==
NULL)
233 *outValue = fallback;
241 *outValue = fallback;
250 if (currentIndex == index)
252 *outValue = pair->
value;
259 *outValue = fallback;
300 if (end == str || *end !=
'\0')
344 if (str ==
NULL || str[0] ==
'\0')
357 array->
items = (
char**)(array + 1);
360 char*
data = (
char*)(array->
items + length);
365 while (
isspace((
unsigned char)*str))
375 const char*
start = str;
377 while (*str !=
'\0' && *str !=
',')
382 const char* end = str;
384 while (end >
start &&
isspace((
unsigned char)*(end - 1)))
#define MAX_PATH
Maximum length of filepaths.
_PUBLIC int isspace(int c)
config_array_t * config_get_array(config_t *config, const char *section, const char *key)
Get an array of strings from a configuration file.
config_t * config_open(const char *prefix, const char *name)
Open a configuration file.
int64_t config_get_int(config_t *config, const char *section, const char *key, int64_t fallback)
Get an integer value from a configuration file.
const char * config_get_string(config_t *config, const char *section, const char *key, const char *fallback)
Get a string value from a configuration file.
void config_array_free(config_array_t *array)
Free a configuration array.
bool config_get_bool(config_t *config, const char *section, const char *key, bool fallback)
Get a boolean value from a configuration file.
void config_close(config_t *config)
Close a configuration file.
void config_get(config_t *config, const char *section, uint64_t index, const char *fallback, const char **outValue, const char **outKey)
Get a value as a string by index from a configuration file.
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
static list_entry_t * list_pop_first(list_t *list)
Pops the first entry from the list.
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
static void list_init(list_t *list)
Initializes a list.
#define NULL
Pointer error value.
#define CONTAINER_OF(ptr, type, member)
Container of macro.
static config_section_t * config_find_section(config_t *cfg, const char *section)
static config_pair_t * config_find_pair(config_section_t *sec, const char *key)
static char * config_trim_whitespace(char *str)
static char lineBuffer[LOG_MAX_BUFFER]
_PUBLIC char * fgets(char *_RESTRICT s, int n, FILE *_RESTRICT stream)
_PUBLIC FILE * fopen(const char *_RESTRICT filename, const char *_RESTRICT mode)
_PUBLIC int fclose(FILE *stream)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC long long int strtoll(const char *_RESTRICT nptr, char **_RESTRICT endptr, int base)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
char * strdup(const char *src)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)
_PUBLIC int strcmp(const char *s1, const char *s2)
_PUBLIC char * strchr(const char *s, int c)
int strcasecmp(const char *s1, const char *s2)
Configuration array structure.
Opaque configuration structure.
A entry in a doubly linked list.