squareball  0.2.0.53-dd5b
A general-purpose library for C99
sb-configparser.h File Reference

Functions to parse INI-style configuration files. More...

#include <stdlib.h>
#include "sb-error.h"
#include "sb-slist.h"
#include "sb-trie.h"

Go to the source code of this file.

typedef struct _sb_config_t sb_config_t
 
sb_config_tsb_config_parse (const char *src, size_t src_len, const char *list_sections[], sb_error_t **err)
 
char ** sb_config_list_sections (sb_config_t *config)
 
char ** sb_config_list_keys (sb_config_t *config, const char *section)
 
const char * sb_config_get (sb_config_t *config, const char *section, const char *key)
 
const char * sb_config_get_with_default (sb_config_t *config, const char *section, const char *key, const char *default_)
 
char ** sb_config_get_list (sb_config_t *config, const char *section)
 
void sb_config_free (sb_config_t *config)
 

Detailed Description

Functions to parse INI-style configuration files.

Typedef Documentation

typedef struct _sb_config_t sb_config_t

Configuration opaque structure.

Function Documentation

void sb_config_free ( sb_config_t config)

Function that frees the memory allocated for a configuration object.

Parameters
configThe configuration object.
Examples:
hello_configparser.c.
const char* sb_config_get ( sb_config_t config,
const char *  section,
const char *  key 
)

Function that returns the value of a given configuration key, for a given configuration section.

Parameters
configA sb_config_t object.
sectionA configuration section.
keyA configuration key.
Returns
The value of the given configuration key, or NULL.
Examples:
hello_configparser.c.
char** sb_config_get_list ( sb_config_t config,
const char *  section 
)

Function that returns an array of values parsed as a list from a given section.

The section must be included in the list_sections when calling sb_config_parse.

Parameters
configA sb_config_t object.
sectionA configuration section.
Returns
An NULL-terminated array of strings, that should be free'd with sb_strv_free.
const char* sb_config_get_with_default ( sb_config_t config,
const char *  section,
const char *  key,
const char *  default_ 
)

Function that returns the value of a given configuration key, for a given configuration section, or returns a default value if the key and/or section does not exists.

Parameters
configA sb_config_t object.
sectionA configuration section.
keyA configuration key.
default_A default value to be returned, if the ken and/or section does not exists.
Returns
The value of the given configuration key, or default_.
char** sb_config_list_keys ( sb_config_t config,
const char *  section 
)

Function that returns an array with configuration keys found in a given configuration section.

Parameters
configA sb_config_t object.
sectionA configuration section.
Returns
An array of strings, or NULL. Must be free'd with sb_strv_free.
Examples:
hello_configparser.c.
char** sb_config_list_sections ( sb_config_t config)

Function that returns an array with configuration sections.

Parameters
configA sb_config_t object.
Returns
An array of strings, or NULL. Must be free'd with sb_strv_free.
Examples:
hello_configparser.c.
sb_config_t* sb_config_parse ( const char *  src,
size_t  src_len,
const char *  list_sections[],
sb_error_t **  err 
)

Function that parses INI-style configuration from a string.

Parameters
srcString with the content to be parsed.
src_lenString length.
list_sectionsList of strings with sections that should be parsed as lists.
errReturn location for a sb_error_t, or NULL.
Returns
An object with the parsed data, or NULL.
Examples:
hello_configparser.c.