PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
Config files

System configuration files. More...

Collaboration diagram for Config files:

Detailed Description

System configuration files.

Patchwork uses a /cfg folder for all system configuration files. These files are simple INI style text files that store key-value pairs in sections.

Todo:
The current system is rather simplistic and in the future it might, if i can be bothered, be worth implementing a database like configuration system.

Data Structures

struct  config_array_t
 Configuration array structure. More...
 
struct  config_t
 Opaque configuration structure. More...
 

Typedefs

typedef struct config config_t
 

Functions

config_tconfig_open (const char *prefix, const char *name)
 Open 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.
 
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.
 
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.
 
bool config_get_bool (config_t *config, const char *section, const char *key, bool fallback)
 Get a boolean value from a configuration file.
 
config_array_tconfig_get_array (config_t *config, const char *section, const char *key)
 Get an array of strings from a configuration file.
 
void config_array_free (config_array_t *array)
 Free a configuration array.
 

Typedef Documentation

◆ config_t

typedef struct config config_t

Definition at line 31 of file config.h.

Function Documentation

◆ config_open()

config_t * config_open ( const char *  prefix,
const char *  name 
)

Open a configuration file.

All configuration files have this full path: /cfg/<prefix>-<name>.cfg.

The goal is that each system or application uses its own prefix to avoid name collisions.

Parameters
prefixThe prefix of the configuration file, for example theme for theme related settings.
nameThe name of the configuration file, for example colors for color related settings.
Returns
On success, the opened configuration file. On failure, returns NULL.

Definition at line 93 of file config.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_close()

void config_close ( config_t config)

Close a configuration file.

Parameters
configThe configuration file to close.

Definition at line 202 of file config.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_get()

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.

Parameters
configThe configuration file.
sectionThe section to get the value from, case insensitive.
indexThe index of the value to get.
fallbackA default value to return if the index is out of bounds.
outValueThe output value, will be set to fallback if the index is out of bounds.
outKeyThe output key, will be set to fallback if the index is out of bounds.

Definition at line 228 of file config.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_get_string()

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.

The value returned is owned by the configuration system and should not be freed or modified.

Parameters
configThe configuration file.
sectionThe section to get the value from, case insensitive.
keyThe key to get the value for, case insensitive.
fallbackA default value to return if the key is not found.
Returns
The string value if found, or fallback otherwise.

Definition at line 263 of file config.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_get_int()

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.

Parameters
configThe configuration file.
sectionThe section to get the value from, case insensitive.
keyThe key to get the value for, case insensitive.
fallbackA default value to return if the key is not found or cannot be parsed as an integer.
Returns
The integer value if found and parsed, or fallback otherwise.

Definition at line 285 of file config.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_get_bool()

bool config_get_bool ( config_t config,
const char *  section,
const char *  key,
bool  fallback 
)

Get a boolean value from a configuration file.

Recognized "true" values (case-insensitive): "true", "yes", "on", "1". Recognized "false" values (case-insensitive): "false", "no", "off", "0".

Parameters
configThe configuration file.
sectionThe section to get the value from, case insensitive.
keyThe key to get the value for, case insensitive.
fallbackA default value to return if not found or unrecognized.
Returns
The boolean value if found and parsed, or fallback otherwise.

Definition at line 308 of file config.c.

Here is the call graph for this function:

◆ config_get_array()

config_array_t * config_get_array ( config_t config,
const char *  section,
const char *  key 
)

Get an array of strings from a configuration file.

Parses the string value into an array of strings, split by commas and with the whitespace trimmed.

Parameters
configThe configuration file.
sectionThe section to get the value from, case insensitive.
keyThe key to get the value for, case insensitive.
Returns
The configuration array or an empty array, will only be NULL on memory allocation failure.

Definition at line 335 of file config.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ config_array_free()

void config_array_free ( config_array_t array)

Free a configuration array.

Parameters
arrayThe configuration array to free.

Definition at line 423 of file config.c.

Here is the call graph for this function: