From: Robert Spalek Date: Thu, 20 Apr 2006 11:52:46 +0000 (+0200) Subject: macros don't end by a comma, and CF_ITEMS/CF_END reintroduced X-Git-Tag: holmes-import~645^2~11^2~105 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=0a1dd2323cb1abb5666d00f1e620336d497217bc;p=libucw.git macros don't end by a comma, and CF_ITEMS/CF_END reintroduced the reason is auto-indentation. in this setting, editors don't get confused and indent everything well --- diff --git a/lib/conf2-test.c b/lib/conf2-test.c index 87bf4dc3..fdeb0d18 100644 --- a/lib/conf2-test.c +++ b/lib/conf2-test.c @@ -37,16 +37,17 @@ commit_sec_1(struct sub_sect_1 *s) } static struct cf_section cf_sec_1 = { - CF_TYPE(struct sub_sect_1) - CF_INIT(init_sec_1) - CF_COMMIT(commit_sec_1) + CF_TYPE(struct sub_sect_1), + CF_INIT(init_sec_1), + CF_COMMIT(commit_sec_1), #define F(x) PTR_TO(struct sub_sect_1, x) - CF_START_ITEMS - CF_STRING("name", F(name)) - CF_STRING("level", F(level)) - CF_INT_ARY("confidence", F(confidence[0]), 2) // XXX: the [0] is needed for the sake of macros :-( - CF_DOUBLE_DYN("list", F(list), 100) - CF_END_ITEMS + CF_ITEMS { + CF_STRING("name", F(name)), + CF_STRING("level", F(level)), + CF_INT_ARY("confidence", F(confidence[0]), 2), // XXX: the [0] is needed for the sake of type checking + CF_DOUBLE_DYN("list", F(list), 100), + CF_END + } #undef F }; @@ -77,20 +78,21 @@ time_parser(uns number, byte **pars, time_t *ptr) } static struct cf_section cf_top UNUSED = { - CF_COMMIT(commit_top) - CF_START_ITEMS - CF_INT("nr1", &nr1) - CF_INT_DYN("nrs1", &nrs1, 1000) - CF_INT_ARY("nrs2", nrs2, 5) - CF_STRING("str1", &str1) - CF_STRING_DYN("str2", &str2, 2) - CF_U64("u1", &u1) - CF_DOUBLE("d1", &d1) - CF_PARSER("FirstTime", &t1, time_parser, -1) - CF_PARSER("SecondTime", &t2, time_parser, 1) - CF_SECTION("master", &sec1, &cf_sec_1) - CF_LIST("slaves", &secs, &cf_sec_1) - CF_END_ITEMS + CF_COMMIT(commit_top), + CF_ITEMS { + CF_INT("nr1", &nr1), + CF_INT_DYN("nrs1", &nrs1, 1000), + CF_INT_ARY("nrs2", nrs2, 5), + CF_STRING("str1", &str1), + CF_STRING_DYN("str2", &str2, 2), + CF_U64("u1", &u1), + CF_DOUBLE("d1", &d1), + CF_PARSER("FirstTime", &t1, time_parser, -1), + CF_PARSER("SecondTime", &t2, time_parser, 1), + CF_SECTION("master", &sec1, &cf_sec_1), + CF_LIST("slaves", &secs, &cf_sec_1), + CF_END + } }; int diff --git a/lib/conf2.h b/lib/conf2.h index 7caa2061..16d6dd99 100644 --- a/lib/conf2.h +++ b/lib/conf2.h @@ -57,22 +57,22 @@ struct cf_section { uns size; // 0 for a global block, sizeof(struct) for a section cf_hook *init; // fills in default values (otherwise 0's are used) cf_hook *commit; // verifies parsed data (optional) - struct cf_item *cfg; // CT_END-terminated array of items + struct cf_item *cfg; // CC_END-terminated array of items }; /* Declaration of cf_section */ -#define CF_TYPE(s) .size = sizeof(s), -#define CF_INIT(f) .init = (cf_hook*) f, -#define CF_COMMIT(f) .commit = (cf_hook*) f, -#define CF_START_ITEMS .cfg = ( struct cf_item[] ) { -#define CF_END_ITEMS { .cls = CC_END } }, +#define CF_TYPE(s) .size = sizeof(s) +#define CF_INIT(f) .init = (cf_hook*) f +#define CF_COMMIT(f) .commit = (cf_hook*) f +#define CF_ITEMS .cfg = ( struct cf_item[] ) +#define CF_END { .cls = CC_END } /* Configuration items */ struct clist; -#define CF_STATIC(n,p,T,t,c) { .cls = CC_STATIC, .name = n, .number = c, .ptr = CHECK_PTR_TYPE(p,t*), .u.type = CT_##T }, -#define CF_DYNAMIC(n,p,T,t,c) { .cls = CC_DYNAMIC, .name = n, .number = c, .ptr = CHECK_PTR_TYPE(p,t**), .u.type = CT_##T }, -#define CF_PARSER(n,p,f,c) { .cls = CC_PARSER, .name = n, .number = c, .ptr = p, .u.par = (cf_parser*) f }, -#define CF_SECTION(n,p,s) { .cls = CC_SECTION, .name = n, .number = 1, .ptr = p, .u.sub = s }, -#define CF_LIST(n,p,s) { .cls = CC_LIST, .name = n, .number = 1, .ptr = CHECK_PTR_TYPE(p,struct clist*), .u.sub = s }, +#define CF_STATIC(n,p,T,t,c) { .cls = CC_STATIC, .name = n, .number = c, .ptr = CHECK_PTR_TYPE(p,t*), .u.type = CT_##T } +#define CF_DYNAMIC(n,p,T,t,c) { .cls = CC_DYNAMIC, .name = n, .number = c, .ptr = CHECK_PTR_TYPE(p,t**), .u.type = CT_##T } +#define CF_PARSER(n,p,f,c) { .cls = CC_PARSER, .name = n, .number = c, .ptr = p, .u.par = (cf_parser*) f } +#define CF_SECTION(n,p,s) { .cls = CC_SECTION, .name = n, .number = 1, .ptr = p, .u.sub = s } +#define CF_LIST(n,p,s) { .cls = CC_LIST, .name = n, .number = 1, .ptr = CHECK_PTR_TYPE(p,struct clist*), .u.sub = s } /* Configuration items for basic types */ #define CF_INT(n,p) CF_STATIC(n,p,INT,int,1) #define CF_INT_ARY(n,p,c) CF_STATIC(n,p,INT,int,c)