File: parsebuf.c

package info (click to toggle)
libconfuse 3.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,192 kB
  • sloc: ansic: 5,532; lex: 451; xml: 439; makefile: 213; sh: 39
file content (36 lines) | stat: -rw-r--r-- 780 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* 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);
}