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, 3 months ago) by misho
Branches: confuse, MAIN
CVS tags: v3_3, HEAD
confuse 3.3

    1: /* Very simple example for parse buf example */
    2: #include <errno.h>
    3: #include <string.h>
    4: #include <stdlib.h>
    5: #include "confuse.h"
    6: 
    7: int main(void)
    8: {
    9: 	cfg_t *cfg;
   10: 	cfg_opt_t arg_opts[] = {
   11: 		CFG_STR("value", "default", CFGF_NONE),
   12: 		CFG_END()
   13: 	};
   14: 	cfg_opt_t opts[] = {
   15: 		CFG_INT("delay", 3, CFGF_NONE),
   16: 		CFG_STR("message", "This is a message", CFGF_NONE),
   17: 		CFG_SEC("argument", arg_opts, CFGF_MULTI | CFGF_TITLE),
   18: 		CFG_END()
   19: 	};
   20: 
   21: 	char *buf =
   22: 		" delay = 3\n"
   23: 		"# message = 'asdfasfasfd tersf'\n"
   24: 		" argument one { value = bar }\n"
   25: 		" argument two { value=foo}\n";
   26: 
   27: 	cfg = cfg_init(opts, 0);
   28: 	if (cfg_parse_buf(cfg, buf) != CFG_SUCCESS) {
   29: 		fprintf(stderr, "Failed parsing configuration: %s\n", strerror(errno));
   30: 		exit(1);
   31: 	}
   32: 	cfg_print(cfg, stdout);
   33: 
   34: 	return cfg_free(cfg);
   35: }
   36: 

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