File: example_buffer.c

package info (click to toggle)
confetti 20120731-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 264 kB
  • ctags: 183
  • sloc: ansic: 2,404; lex: 568; yacc: 539; makefile: 123; perl: 13
file content (49 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include <prscfg.h>
#include <my_product_cfg.h>

void
out_warning(ConfettyError r __attribute__ ((unused)), char *format, ...) {
    va_list args;

	va_start(args, format);
	vfprintf(stderr, format, args);
	va_end(args);
}


int
main(int argc __attribute__ ((unused)), char* argv[] __attribute__ ((unused))) {
	my_product	cfg;
	my_product_iterator_t	*i;
	char		*key, *value;
	int			nAccepted, nSkipped, nOptional;

	fill_default_my_product(&cfg);

	parse_cfg_buffer_my_product(
		&cfg,
		"asdf.array[2].subarray[3].subkey = 123456789 "
		"root_array[3].ra = 12 "
		"asdf.k2=\"NEWVALUE\" " 
		"opt no_such_param = 123",
		0, &nAccepted, &nSkipped, &nOptional
	);

	printf("==========Accepted: %d; Skipped: %d; Optional: %d===========\n", nAccepted, nSkipped, nOptional);

	i = my_product_iterator_init();
	while ( (key = my_product_iterator_next(i, &cfg, &value)) != NULL ) {
		if (value) {
			printf("%s => '%s'\n", key, value);
			free(value);
		} else {
			printf("%s => (null)\n", key);
		}
	}

	return 0;
}