Annotation of embedaddon/confuse/examples/reread.c, revision 1.1
1.1 ! misho 1: #include "confuse.h"
! 2: #include <string.h>
! 3: #include <signal.h>
! 4: #include <unistd.h>
! 5:
! 6: cfg_t *cfg = 0;
! 7: const char *config_filename = "./reread.conf";
! 8:
! 9: void read_config(void)
! 10: {
! 11: cfg_opt_t arg_opts[] = {
! 12: CFG_STR("value", "default", CFGF_NONE),
! 13: CFG_END()
! 14: };
! 15: cfg_opt_t opts[] = {
! 16: CFG_INT("delay", 3, CFGF_NONE),
! 17: CFG_STR("message", "This is a message", CFGF_NONE),
! 18: CFG_SEC("argument", arg_opts, CFGF_MULTI | CFGF_TITLE),
! 19: CFG_END()
! 20: };
! 21: int ret;
! 22:
! 23: char *buf = "" \
! 24: " delay = 3\n" \
! 25: "# message = \"asdfasfasfd tersf\"\n" \
! 26: " argument one { value = 1 }\n" \
! 27: " argument two { value=foo}\n";
! 28:
! 29: cfg_free(cfg);
! 30:
! 31: cfg = cfg_init(opts, 0);
! 32: ret = cfg_parse_buf(cfg, buf);
! 33: ret = cfg_parse(cfg, config_filename);
! 34: }
! 35:
! 36: void sighandler(int sig)
! 37: {
! 38: read_config();
! 39: signal(SIGHUP, sighandler);
! 40: }
! 41:
! 42: static int loop = 1;
! 43:
! 44: void usr1handler(int sig)
! 45: {
! 46: loop = 0;
! 47: }
! 48:
! 49: int main(void)
! 50: {
! 51: unsigned int i;
! 52:
! 53: read_config();
! 54: signal(SIGHUP, sighandler);
! 55: signal(SIGUSR1, usr1handler);
! 56:
! 57: while(loop)
! 58: {
! 59: printf("Message: %s", cfg_getstr(cfg, "message"));
! 60: for(i = 0; i < cfg_size(cfg, "argument"); i++)
! 61: {
! 62: cfg_t *arg = cfg_getnsec(cfg, "argument", i);
! 63: printf(", %s", cfg_getstr(arg, "value"));
! 64: }
! 65: printf("\n");
! 66:
! 67: sleep(cfg_getint(cfg, "delay"));
! 68: }
! 69:
! 70: cfg_free(cfg);
! 71: cfg = 0;
! 72:
! 73: return 0;
! 74: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>