2 * Insane tester of reading configuration files
4 * (c) 2006 Robert Spalek <robert@ucw.cz>
9 #include "lib/clists.h"
23 struct sub_sect_1 *s = ptr;
31 commit_sec_1(void *ptr)
33 struct sub_sect_1 *s = ptr;
34 if (s->confidence < 0 || s->confidence > 10)
35 return "Well, this can't be";
39 static struct cf_section cf_sec_1 = {
40 .size = sizeof(struct sub_sect_1),
42 .commit = commit_sec_1,
43 .cfg = (struct cf_item[]) {
44 #define F(x) CF_FIELD(struct sub_sect_1, x)
45 CF_STRING("name", F(name)),
46 CF_STRING("level", F(level)),
47 CF_INT("confidence", F(confidence)),
54 static int *nrs1 = ARRAY_ALLOC(int, 5, 5, 4, 3, 2, 1);
56 static byte *str1 = "no worries";
57 static byte **str2 = ARRAY_ALLOC(byte *, 2, "Alice", "Bob");
58 static u64 u1 = 0xCafeBeefDeadC00ll;
59 static double d1 = -1.1;
60 static struct sub_sect_1 sec1 = { "Charlie", "WBAFC", 0 };
61 static struct clist secs;
65 commit_top(void *ptr UNUSED)
68 return "Don't touch my variable!";
73 time_parser(byte *name UNUSED, uns number, byte **pars, void *ptr)
75 * (time_t*) ptr = number ? atoi(pars[0]) : time(NULL);
79 static struct cf_section cf_top = {
81 .cfg = (struct cf_item []) {
83 CF_INT_AR("nrs1", &nrs1, 5),
84 CF_INT_AR("nrs2", &nrs2, -1000),
85 CF_STRING("str1", &str1),
86 CF_STRING_AR("str2", &str2, 2),
89 CF_PARSER("FirstTime", &t1, time_parser, -1),
90 CF_PARSER("SecondTime", &t2, time_parser, 1),
91 CF_SUB_SECTION("master", &sec1, &cf_sec_1),
92 CF_LINK_LIST("slaves", &secs, &cf_sec_1),