2 * Insane tester of reading configuration files
4 * (c) 2006 Robert Spalek <robert@ucw.cz>
9 #include "lib/clists.h"
23 init_sec_1(struct sub_sect_1 *s)
29 // leave s->list==NULL
34 commit_sec_1(struct sub_sect_1 *s)
36 if (s->confidence[0] < 0 || s->confidence[0] > 10)
37 return "Well, this can't be";
41 static struct cf_section cf_sec_1 = {
42 CF_TYPE(struct sub_sect_1),
44 CF_COMMIT(commit_sec_1),
45 #define F(x) PTR_TO(struct sub_sect_1, x)
47 CF_STRING("name", F(name)),
48 CF_STRING("level", F(level)),
49 CF_INT_ARY("confidence", F(confidence[0]), 2), // XXX: the [0] is needed for the sake of type checking
50 CF_DOUBLE_DYN("list", F(list), 100),
57 static int *nrs1 = DYN_ALLOC(int, 5, 5, 4, 3, 2, 1);
59 static byte *str1 = "no worries";
60 static byte **str2 = DYN_ALLOC(byte *, 2, "Alice", "Bob");
61 static u64 u1 = 0xCafeBeefDeadC00ll;
62 static double d1 = -1.1;
63 static struct sub_sect_1 sec1 = { {}, "Charlie", "WBAFC", { 0, -1} };
64 static struct clist secs;
68 init_top(void *ptr UNUSED)
70 for (uns i=0; i<5; i++)
72 struct sub_sect_1 *s = cf_malloc(sizeof(struct sub_sect_1));
73 cf_init_section("slaves", &cf_sec_1, s);
75 clist_add_tail(&secs, &s->n);
81 commit_top(void *ptr UNUSED)
84 return "Don't touch my variable!";
89 time_parser(uns number, byte **pars, time_t *ptr)
91 *ptr = number ? atoi(pars[0]) : time(NULL);
95 static struct cf_section cf_top UNUSED = {
97 CF_COMMIT(commit_top),
100 CF_INT_DYN("nrs1", &nrs1, 1000),
101 CF_INT_ARY("nrs2", nrs2, 5),
102 CF_STRING("str1", &str1),
103 CF_STRING_DYN("str2", &str2, 2),
105 CF_DOUBLE("d1", &d1),
106 CF_PARSER("FirstTime", &t1, time_parser, -1),
107 CF_PARSER("SecondTime", &t2, time_parser, 1),
108 CF_SECTION("master", &sec1, &cf_sec_1),
109 CF_LIST("slaves", &secs, &cf_sec_1),