X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fconf.h;h=c56cea48113ce0148a4b4f5670b7b45a20b17017;hb=b4d79987a979bcbf749294c706fdc8c4ae8f9304;hp=033b75908f89856557cceb4d331c269b2943b599;hpb=a86e328ab75068b1c27e17e3fb33a9b5845f63aa;p=libucw.git diff --git a/lib/conf.h b/lib/conf.h index 033b7590..c56cea48 100644 --- a/lib/conf.h +++ b/lib/conf.h @@ -1,5 +1,5 @@ /* - * UCW Library -- Reading of configuration files + * UCW Library -- Configuration files * * (c) 2001--2006 Robert Spalek * (c) 2003--2006 Martin Mares @@ -17,7 +17,8 @@ enum cf_class { CC_DYNAMIC, // dynamically allocated array CC_PARSER, // arbitrary parser function CC_SECTION, // section appears exactly once - CC_LIST // list with 0..many nodes + CC_LIST, // list with 0..many nodes + CC_BITMAP // of up to 32 items }; enum cf_type { @@ -99,6 +100,8 @@ struct cf_section { #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.sec = s } #define CF_LIST(n,p,s) { .cls = CC_LIST, .name = n, .number = 1, .ptr = CHECK_PTR_TYPE(p,clist*), .u.sec = s } +#define CF_BITMAP_INT(n,p) { .cls = CC_BITMAP, .type = CT_INT, .name = n, .number = 1, .ptr = CHECK_PTR_TYPE(p,u32*) } +#define CF_BITMAP_LOOKUP(n,p,t) { .cls = CC_BITMAP, .type = CT_LOOKUP, .name = n, .number = 1, .ptr = CHECK_PTR_TYPE(p,u32*), .u.lookup = t } /* 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) @@ -124,18 +127,16 @@ struct cf_section { #define CF_USER(n,p,t) { .cls = CC_STATIC, .type = CT_USER, .name = n, .number = 1, .ptr = p, .u.utype = t } #define CF_USER_ARY(n,p,t,c) { .cls = CC_STATIC, .type = CT_USER, .name = n, .number = c, .ptr = p, .u.utype = t } #define CF_USER_DYN(n,p,t,c) { .cls = CC_DYNAMIC, .type = CT_USER, .name = n, .number = c, .ptr = p, .u.utype = t } - // Beware that CF_USER_DYN can only be used on user-defined types of size at least 4 /* If you aren't picky about the number of parameters */ #define CF_ANY_NUM -0x7fffffff -#define DARY_LEN(a) *(uns*)(a-1) +#define DARY_LEN(a) ((uns*)a)[-1] // length of a dynamic array -#define DARY_ALLOC(type,len,val...) (type[]) { (type)len, ##val } + 1 +#define DARY_ALLOC(type,len,val...) ((struct { uns l; type a[len]; }) { .l = len, .a = { val } }).a // creates a static instance of a dynamic array - // FIXME: overcast doesn't work for the double type -/* Memory allocation */ +/* Memory allocation: conf-alloc.c */ struct mempool; extern struct mempool *cf_pool; void *cf_malloc(uns size); @@ -143,21 +144,16 @@ void *cf_malloc_zero(uns size); byte *cf_strdup(byte *s); byte *cf_printf(char *fmt, ...) FORMAT_CHECK(printf,1,2); -/* Undo journal for error recovery */ +/* Undo journal for error recovery: conf-journal.c */ extern uns cf_need_journal; void cf_journal_block(void *ptr, uns len); #define CF_JOURNAL_VAR(var) cf_journal_block(&(var), sizeof(var)) -struct cf_journal_item; -struct cf_journal_item *cf_journal_new_transaction(uns new_pool); -void cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj); -void cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj); - -/* Declaration */ +/* Declaration: conf-section.c */ void cf_declare_section(byte *name, struct cf_section *sec, uns allow_unknown); void cf_init_section(byte *name, struct cf_section *sec, void *ptr, uns do_bzero); -/* Parsers for basic types */ +/* Parsers for basic types: conf-parse.c */ byte *cf_parse_int(byte *str, int *ptr); byte *cf_parse_u64(byte *str, u64 *ptr); byte *cf_parse_double(byte *str, double *ptr);