From 0f4c3eff68aeece7745ea3972384f1261acdfcbb Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Wed, 19 Apr 2006 12:00:02 +0200 Subject: [PATCH] - added prototypes of memory allocation and journal functions - rearranged some declarations - added proper copyright --- lib/conf2.h | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/conf2.h b/lib/conf2.h index 20daf32a..ae1d1705 100644 --- a/lib/conf2.h +++ b/lib/conf2.h @@ -1,7 +1,8 @@ /* * UCW Library -- Reading of configuration files * - * (c) 2006 Robert Spalek + * (c) 2001--2006 Robert Spalek + * (c) 2003--2006 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -19,7 +20,6 @@ enum cf_type { CT_LIST // list with 0..many nodes }; -struct cf_section; typedef byte *cf_hook(void *ptr); /* An init- or commit-hook gets a pointer to the section or NULL if this * is the global section. It returns an error message or NULL if everything @@ -29,6 +29,7 @@ typedef byte *cf_parser(uns number, byte **pars, void *ptr); * way it likes into *ptr. It returns an error message or NULL if everything * is all right. */ +struct cf_section; struct cf_item { enum cf_type type; byte *name; @@ -47,12 +48,7 @@ struct cf_section { struct cf_item *cfg; // CT_END-terminated array of items }; -#define ARRAY_ALLOC(type,len,val...) (type[]) { (type)len, ##val } + 1 - // creates an array with an allocated space in the front for the (Pascal-like) length -#define ARRAY_LEN(a) *(uns*)(a-1) - // length of the array - -/* Declaration of cf_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, @@ -67,10 +63,26 @@ struct cf_section { #define CF_U64_ARY(n,p,c) { .type = CT_U64, .name = n, .number = c, .ptr = CHECK_PTR_TYPE(p,u64**) }, #define CF_DOUBLE_ARY(n,p,c) { .type = CT_DOUBLE, .name = n, .number = c, .ptr = CHECK_PTR_TYPE(p,double**) }, #define CF_STRING_ARY(n,p,c) { .type = CT_STRING, .name = n, .number = c, .ptr = CHECK_PTR_TYPE(p,byte***) }, + +#define ARRAY_ALLOC(type,len,val...) (type[]) { (type)len, ##val } + 1 + // creates an array with an allocated space in the front for the (Pascal-like) length +#define ARRAY_LEN(a) *(uns*)(a-1) + // length of the array + /* Configuration items for sections, lists, and parsed items */ struct clist; #define CF_PARSER(n,p,f,c) { .type = CT_PARSER, .name = n, .number = c, .ptr = p, .ptr2.par = (cf_parser*) f }, #define CF_SECTION(n,p,s) { .type = CT_SECTION, .name = n, .number = 1, .ptr = p, .ptr2.sub = s }, #define CF_LIST(n,p,s) { .type = CT_LIST, .name = n, .number = 1, .ptr = CHECK_PTR_TYPE(p,struct clist*), .ptr2.sub = s }, +/* Memory allocation */ +void *cf_malloc(uns size); +void *cf_malloc_zero(uns size); +byte *cf_strdup(byte *s); +byte *cf_printf(char *fmt, ...); + +/* Undo journal for error recovery */ +uns cf_journal_active(uns flag); +void cf_journal_block(void *ptr, uns len); + #endif -- 2.39.2