#include <err.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
const char *file = "env.conf";
};
int rc;
if (argc > 1)
file = argv[1];
cfg = cfg_init(opts, 0);
if (!cfg)
err(1, "Failed cfg_init()");
rc = cfg_parse(cfg, file);
err(1, "Failed opening %s", file);
errx(1, "Failed parsing %s", file);
}
sec = cfg_getsec(cfg, "env");
if (sec) {
unsigned int i;
for (i = 0; i < cfg_num(sec); i++) {
printf("%s = \"%s\"\n", cfg_opt_name(opt), cfg_opt_getstr(opt));
}
}
cfg_free(cfg);
return 0;
}
A configuration file parser library.
#define CFGF_KEYSTRVAL
section has free-form key=value string options created when parsing file
Definition confuse.h:98
#define CFG_SEC(_name, _opts, _flags)
Initialize a section.
Definition confuse.h:790
#define CFG_SUCCESS
Success, all OK (POSIX '0')
Definition confuse.h:103
#define CFG_END()
Terminate list of options.
Definition confuse.h:858
#define CFG_FILE_ERROR
Error opening the configuration file.
Definition confuse.h:105
Data structure holding information about an option.
Definition confuse.h:324
Data structure holding information about a "section".
Definition confuse.h:250