Annotation of embedaddon/confuse/doc/listing5.c, revision 1.1
1.1 ! misho 1: #include <stdio.h>
! 2: #include <confuse.h>
! 3:
! 4: int main(void)
! 5: {
! 6: cfg_opt_t greet_opts[] =
! 7: {
! 8: CFG_STR_LIST("targets", "{World}", CFGF_NONE),
! 9: CFG_INT("repeat", 1, CFGF_NONE),
! 10: CFG_END()
! 11: };
! 12: cfg_opt_t opts[] =
! 13: {
! 14: CFG_SEC("greeting", greet_opts, CFGF_TITLE | CFGF_MULTI),
! 15: CFG_END()
! 16: };
! 17: cfg_t *cfg, *cfg_greet;
! 18: int repeat;
! 19: int i, j;
! 20:
! 21: cfg = cfg_init(opts, CFGF_NONE);
! 22: if(cfg_parse(cfg, "hello.conf") == CFG_PARSE_ERROR)
! 23: return 1;
! 24:
! 25: for(j = 0; j < cfg_size(cfg, "greeting"); j++)
! 26: {
! 27: cfg_greet = cfg_getnsec(cfg, "greeting", j);
! 28:
! 29: repeat = cfg_getint(cfg_greet, "repeat");
! 30: while(repeat--)
! 31: {
! 32: printf("%s", cfg_title(cfg_greet));
! 33: for(i = 0; i < cfg_size(cfg_greet, "targets"); i++)
! 34: printf(", %s", cfg_getnstr(cfg_greet, "targets", i));
! 35: printf("!\n");
! 36: }
! 37: }
! 38:
! 39: cfg_free(cfg);
! 40: return 0;
! 41: }
! 42:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>