36 int config_handler(
void *user,
const char *section,
const char *name,
const char *value) {
44 for (
int i = 0; i < c->
numsects; ++i) {
55 cs->
name = strdup(section);
61 perror(
"config_handler");
67 cs->
name = strdup(section);
70 cs = &(c->
sects[sectFound]);
86 perror(
"config_handler");
109 if (c == NULL) {
return false; }
112 if (c->
sects == NULL) {
115 perror(
"new_config");
130 perror(
"new_config");
143 if (c == NULL) {
return; }
145 for (
int i = 0; i < c->
numsects; ++i) {
147 for (
int j = 0; j < cs->
numopts; ++j) {
164 if (c == NULL) {
return; }
166 for (
int i = 0; i < c->
numsects; ++i) {
168 if (strcmp(
"", cs->
name) != 0) { fprintf(stdout,
"[%s]\n", cs->
name); }
169 for (
int j = 0; j < cs->
numopts; ++j) {
172 fprintf(stdout,
"\n");
187 for (
int i = 0; i < in->
numsects; i++) {
189 if (strcasecmp(sn, cs->
name) == 0) {
return cs; }
205 for (
int i = 0; i < cs->
numopts; i++) {
207 if (strcasecmp(kn, k->
key) == 0) {
return k; }
224 if (cs == NULL) {
return NULL; }
241 if (b == NULL || (strcmp(b,
"") == 0)) {
return -1; }
272 size_t sl = strlen(c);
273 if (((c[0] ==
'"') && (c[sl - 1] ==
'"')) || ((c[0] ==
'\'') && (c[sl - 1] ==
'\''))) {
275 return strndup(&(c[1]), sl - 2);
bool new_config(ini_config *c)
Initialise a new ini_config instance.
void destroy_config(ini_config *c)
Destroy ini_config instance.
void print_config(ini_config *c)
Print ini_config instance to stdout.
int config_parse_bool(const char *b)
Parse string to boolean.
char * config_qstrdup(const char *c)
Duplicate string, stripping optional leading/trailing quote marks.
config_kv * config_get_option(const ini_config *in, const char *sn, const char *kn)
Find configuration option by section and key names.
int config_handler(void *user, const char *section, const char *name, const char *value)
Populate ini_config instance with values from file.
config_section * config_get_section(const ini_config *in, const char *sn)
Find configuration section by name.
config_kv * config_get_key(const config_section *cs, const char *kn)
Find configugration key within specific section, by name.
Represent a key=value pair.
char * value
Configuration item value.
char * key
Configuration item key.
Configuration file section.
int numopts
Number of *opts in use.
config_kv * opts
Key=value pairs belonging to this section.
char * name
Section [tag].
size_t optsize
Allocated size of *opts.
Representation of a parsed .ini file.
config_section * sects
Array of sections.
int numsects
Number of sections defined.
size_t sectsize
Allocated size of *sects.