X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=ucw%2Fconf.h;h=11026b7a6fdf7d0bffde4468412e485ee11a12a8;hb=959566090f98dd31eaa67d3d5959b641e5fe902b;hp=2e8a5ca8889e77066556234f584feaf5d2bb8afe;hpb=a4f8b029b86d2ca1612a9c2e2795ccea27b15276;p=libucw.git diff --git a/ucw/conf.h b/ucw/conf.h index 2e8a5ca8..11026b7a 100644 --- a/ucw/conf.h +++ b/ucw/conf.h @@ -2,7 +2,7 @@ * UCW Library -- Configuration files * * (c) 2001--2006 Robert Spalek - * (c) 2003--2012 Martin Mares + * (c) 2003--2014 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -12,6 +12,7 @@ #define _UCW_CONF_H #include +#include #ifdef CONFIG_UCW_CLEAN_ABI #define cf_close_group ucw_cf_close_group @@ -71,7 +72,7 @@ struct cf_context *cf_new_context(void); * All configuration settings made within the context are rolled back * (except when journalling is turned off). All memory allocated on behalf * of the context is freed, which includes memory obtained by calls to - * cf_malloc(). + * @cf_malloc(). **/ void cf_delete_context(struct cf_context *cc); @@ -99,7 +100,7 @@ int cf_load(const char *file); /** * Reload configuration from @file, replace the old one. * If @file is NULL, reload all loaded configuration files and re-apply - * bits of configuration passed to cf_set(). + * bits of configuration passed to @cf_set(). * Returns a non-zero value upon error. In that case, all configuration * settings are rolled back to the state before calling this function. **/ @@ -126,7 +127,7 @@ int cf_set(const char *string); void cf_open_group(void); /** - * Close a group opened by cf_open_group(). Returns a non-zero value upon error, + * Close a group opened by @cf_open_group(). Returns a non-zero value upon error, * which usually means that a commit hook has failed. **/ int cf_close_group(void); @@ -166,7 +167,7 @@ struct fastbuf; * @cf_journal_block() on the overwritten memory block. It returns an error * message or NULL if everything is all right. **/ -typedef char *cf_parser(uns number, char **pars, void *ptr); +typedef char *cf_parser(uint number, char **pars, void *ptr); /** * A parser function for user-defined types gets a string and a pointer to * the destination variable. It must store the value within [ptr,ptr+size), @@ -196,7 +197,7 @@ typedef void cf_dumper1(struct fastbuf *fb, void *ptr); typedef char *cf_copier(void *dest, void *src); struct cf_user_type { /** Structure to store information about user-defined variable type. **/ - uns size; // of the parsed attribute + uint size; // of the parsed attribute char *name; // name of the type (for dumping) cf_parser1 *parser; // how to parse it cf_dumper1 *dumper; // how to dump the type @@ -218,12 +219,12 @@ struct cf_item { /** Single configuration item. **/ }; struct cf_section { /** A section. **/ - uns size; // 0 for a global block, sizeof(struct) for a section + uint size; // 0 for a global block, sizeof(struct) for a section cf_hook *init; // fills in default values (no need to bzero) cf_hook *commit; // verifies parsed data (optional) cf_copier *copy; // copies values from another instance (optional, no need to copy basic attributes) struct cf_item *cfg; // CC_END-terminated array of items - uns flags; // for internal use only + uint flags; // for internal use only }; /*** @@ -255,7 +256,7 @@ struct cf_section { /** A section. **/ * struct list_node { * cnode n; // This one is for the list itself * char *name; - * uns value; + * uint value; * }; * * static struct clist nodes; @@ -264,7 +265,7 @@ struct cf_section { /** A section. **/ * CF_TYPE(struct list_node), * CF_ITEMS { * CF_STRING("name", PTR_TO(struct list_node, name)), - * CF_UNS("value", PTR_TO(struct list_node, value)), + * CF_UINT("value", PTR_TO(struct list_node, value)), * CF_END * } * }; @@ -343,9 +344,9 @@ struct cf_section { /** A section. **/ #define CF_INT(n,p) CF_STATIC(n,p,INT,int,1) /** Single `int` value. **/ #define CF_INT_ARY(n,p,c) CF_STATIC(n,p,INT,int,c) /** Static array of integers. **/ #define CF_INT_DYN(n,p,c) CF_DYNAMIC(n,p,INT,int,c) /** Dynamic array of integers. **/ -#define CF_UNS(n,p) CF_STATIC(n,p,INT,uns,1) /** Single `uns` (`unsigned`) value. **/ -#define CF_UNS_ARY(n,p,c) CF_STATIC(n,p,INT,uns,c) /** Static array of unsigned integers. **/ -#define CF_UNS_DYN(n,p,c) CF_DYNAMIC(n,p,INT,uns,c) /** Dynamic array of unsigned integers. **/ +#define CF_UINT(n,p) CF_STATIC(n,p,INT,uint,1) /** Single `uint` (`unsigned`) value. **/ +#define CF_UINT_ARY(n,p,c) CF_STATIC(n,p,INT,uint,c) /** Static array of unsigned integers. **/ +#define CF_UINT_DYN(n,p,c) CF_DYNAMIC(n,p,INT,uint,c) /** Dynamic array of unsigned integers. **/ #define CF_U64(n,p) CF_STATIC(n,p,U64,u64,1) /** Single unsigned 64bit integer (`u64`). **/ #define CF_U64_ARY(n,p,c) CF_STATIC(n,p,U64,u64,c) /** Static array of u64s. **/ #define CF_U64_DYN(n,p,c) CF_DYNAMIC(n,p,U64,u64,c) /** Dynamic array of u64s. **/ @@ -355,6 +356,12 @@ struct cf_section { /** A section. **/ #define CF_IP(n,p) CF_STATIC(n,p,IP,u32,1) /** Single IPv4 address. **/ #define CF_IP_ARY(n,p,c) CF_STATIC(n,p,IP,u32,c) /** Static array of IP addresses. **/. #define CF_IP_DYN(n,p,c) CF_DYNAMIC(n,p,IP,u32,c) /** Dynamic array of IP addresses. **/ + +/* FIXME: Backwards compatibility only, should not be used at is will be removed soon. */ +#define CF_UNS CF_UINT +#define CF_UNS_ARY CF_UINT_ARY +#define CF_UNS_DYN CF_UINT_DYN + /** * A string. * You provide a pointer to a `char *` variable and it will fill it with @@ -423,9 +430,7 @@ struct cf_section { /** A section. **/ **/ #define CF_ANY_NUM -0x7fffffff -#define DARY_LEN(a) ((uns*)a)[-1] /** Length of an dynamic array. **/ -#define DARY_ALLOC(type,len,val...) ((struct { byte pad[ALIGN_TO(sizeof(uns), CPU_STRUCT_ALIGN) - sizeof(uns)]; uns l; type a[len]; }) { .l = len, .a = { val } }).a - // creates a static instance of a dynamic array +#define DARY_LEN(a) GARY_SIZE(a) /** Length of an dynamic array. An alias for `GARY_SIZE`. **/ /*** * [[alloc]] @@ -445,8 +450,8 @@ struct cf_section { /** A section. **/ * cf_set(), or cf_getopt() on the particular context. ***/ struct mempool *cf_get_pool(void); /** Return a pointer to the current configuration pool. **/ -void *cf_malloc(uns size); /** Returns @size bytes of memory allocated from the current configuration pool. **/ -void *cf_malloc_zero(uns size); /** Like @cf_malloc(), but zeroes the memory. **/ +void *cf_malloc(uint size); /** Returns @size bytes of memory allocated from the current configuration pool. **/ +void *cf_malloc_zero(uint size); /** Like @cf_malloc(), but zeroes the memory. **/ char *cf_strdup(const char *s); /** Copy a string into @cf_malloc()ed memory. **/ char *cf_printf(const char *fmt, ...) FORMAT_CHECK(printf,1,2); /** printf() into @cf_malloc()ed memory. **/ @@ -479,7 +484,7 @@ void cf_set_journalling(int enable); * <> do not need to call it, it is called * before them. **/ -void cf_journal_block(void *ptr, uns len); +void cf_journal_block(void *ptr, uint len); #define CF_JOURNAL_VAR(var) cf_journal_block(&(var), sizeof(var)) // Store a single value into the journal struct cf_journal_item; /** Opaque identifier of the journal state. **/ @@ -488,7 +493,7 @@ struct cf_journal_item; /** Opaque identifier of the journal state. **/ * get back to it. The @new_pool parameter tells if a new memory pool * should be created and used from now. **/ -struct cf_journal_item *cf_journal_new_transaction(uns new_pool); +struct cf_journal_item *cf_journal_new_transaction(uint new_pool); /** * Marks current state as a complete transaction. The @new_pool * parameter tells if the transaction was created with new memory pool @@ -497,7 +502,7 @@ struct cf_journal_item *cf_journal_new_transaction(uns new_pool); * is the journal state returned from last * @cf_journal_new_transaction() call. **/ -void cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj); +void cf_journal_commit_transaction(uint new_pool, struct cf_journal_item *oldj); /** * Returns to an old journal state, reverting anything the current * transaction did. The @new_pool parameter must be the same as the @@ -505,7 +510,7 @@ void cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj); * is the journal state you got from @cf_journal_new_transaction() -- * it is the state to return to. **/ -void cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj); +void cf_journal_rollback_transaction(uint new_pool, struct cf_journal_item *oldj); /*** * [[declare]] @@ -524,13 +529,13 @@ void cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj) * Please note that a single section definition cannot be used in multiple * configuration contexts simultaneously. **/ -void cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown); +void cf_declare_section(const char *name, struct cf_section *sec, uint allow_unknown); /** * Like @cf_declare_section(), but instead of item pointers, the section * contains offsets relative to @ptr. In other words, it does the same * as `CF_SECTION`, but for top-level sections. **/ -void cf_declare_rel_section(const char *name, struct cf_section *sec, void *ptr, uns allow_unknown); +void cf_declare_rel_section(const char *name, struct cf_section *sec, void *ptr, uint allow_unknown); /** * If you have a section in a structure and you want to initialize it * (eg. if you want a copy of default values outside the configuration), @@ -538,7 +543,7 @@ void cf_declare_rel_section(const char *name, struct cf_section *sec, void *ptr, * * This is used mostly internally. You probably do not need it. **/ -void cf_init_section(const char *name, struct cf_section *sec, void *ptr, uns do_bzero); +void cf_init_section(const char *name, struct cf_section *sec, void *ptr, uint do_bzero); /*** * [[bparser]]