File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / confuse / examples / parsebuf.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:49:17 2021 UTC (3 years, 9 months ago) by misho
Branches: confuse, MAIN
CVS tags: v3_3, HEAD
confuse 3.3

/* 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);
}


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>