Loading...
Searching...
No Matches
parsebuf.c
/* Very simple example for parse buf example */
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include "confuse.h"
int main(void)
{
cfg_t *cfg;
cfg_opt_t arg_opts[] = {
CFG_STR("value", "default", CFGF_NONE),
CFG_END()
};
cfg_opt_t opts[] = {
CFG_INT("delay", 3, CFGF_NONE),
CFG_STR("message", "This is a message", CFGF_NONE),
CFG_SEC("argument", arg_opts, CFGF_MULTI | CFGF_TITLE),
CFG_END()
};
char *buf =
" delay = 3\n"
"# message = 'asdfasfasfd tersf'\n"
" argument one { value = bar }\n"
" argument two { value=foo}\n";
cfg = cfg_init(opts, 0);
if (cfg_parse_buf(cfg, buf) != CFG_SUCCESS) {
fprintf(stderr, "Failed parsing configuration: %s\n", strerror(errno));
exit(1);
}
cfg_print(cfg, stdout);
return cfg_free(cfg);
}
confuse.h
A configuration file parser library.
CFG_SEC
#define CFG_SEC(_name, _opts, _flags)
Initialize a section.
Definition confuse.h:790
CFGF_TITLE
#define CFGF_TITLE
option has a title (only applies to sections)
Definition confuse.h:86
CFGF_NONE
#define CFGF_NONE
Flags.
Definition confuse.h:82
CFG_SUCCESS
#define CFG_SUCCESS
Success, all OK (POSIX '0').
Definition confuse.h:103
CFG_END
#define CFG_END()
Terminate list of options.
Definition confuse.h:858
CFGF_MULTI
#define CFGF_MULTI
option may be specified multiple times (only applies to sections)
Definition confuse.h:83
CFG_STR
#define CFG_STR(name, def, flags)
Initialize a string option.
Definition confuse.h:367
CFG_INT
#define CFG_INT(name, def, flags)
Initialize an integer option.
Definition confuse.h:473
cfg_opt_t
Data structure holding information about an option.
Definition confuse.h:324
cfg_t
Data structure holding information about a "section".
Definition confuse.h:250