diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-10-08 23:00:42 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-10-08 23:00:42 +0300 |
commit | e2bb02092abe1321c534ad8a6c168b2803245cc5 (patch) | |
tree | 080290a3d844cabb433156b17aca805e2260950a /lib/gdbmmap.c | |
parent | 9b56a5b05db6630a667ad0c9b16ec45a4e52044d (diff) | |
download | eclat-e2bb02092abe1321c534ad8a6c168b2803245cc5.tar.gz eclat-e2bb02092abe1321c534ad8a6c168b2803245cc5.tar.bz2 |
Improve configuration syntax help.
* grecs: Upgrade.
* lib/filemap.c: Revamp configuration routine.
Provide configuration syntax help.
* lib/gdbmmap.c: Likewamp.
* lib/ldapmap.c: Provide configuration syntax help.
* lib/libeclat.h (eclat_map_drv) <map_confhelp>: New member.
(eclat_map_confhelp): New proto.
* lib/map.c (eclat_map_confhelp): New function.
* src/config.c (config_help): Call eclat_map_confhelp.
Diffstat (limited to 'lib/gdbmmap.c')
-rw-r--r-- | lib/gdbmmap.c | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/lib/gdbmmap.c b/lib/gdbmmap.c index 4fdaa33..7ecb88c 100644 --- a/lib/gdbmmap.c +++ b/lib/gdbmmap.c @@ -27,42 +27,66 @@ struct gdbm_map { int nullflag; }; +static struct grecs_keyword gdbm_map_kw[] = { + { "type", "'gdbm", "Set map type", + grecs_type_null }, + { "file", NULL, "Database file name", + grecs_type_string, GRECS_DFLT, NULL, + offsetof(struct gdbm_map, name) }, + { "null", NULL, "Count terminating null as part of the key", + grecs_type_bool, GRECS_DFLT, NULL, + offsetof(struct gdbm_map, nullflag) }, + { NULL } +}; + +static void +gdbm_map_free(int dbg, void *data) +{ + struct gdbm_map *gdbm_map = data; + free(gdbm_map->name); + free(gdbm_map); +} + +static void +gdbm_map_confhelp() +{ + static struct grecs_keyword gdbm_map_top[] = { + { "map", "name: string", + "Configuration for a GDBM map", + grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, + gdbm_map_kw }, + { NULL } + }; + grecs_print_statement_array(gdbm_map_top, 1, 0, stdout); +} + static int gdbm_map_config(int dbg, struct grecs_node *node, void *data) { struct gdbm_map *gdbm_map, **return_gdbm_map = data; - const char *filename; struct grecs_node *p; - - if (eclat_get_string_node(node, "file", 0, &p)) - return eclat_map_failure; + int i; + gdbm_map = grecs_malloc(sizeof(*gdbm_map)); - gdbm_map->name = grecs_strdup(p->v.value->v.string); - gdbm_map->locus = p->locus; - switch (eclat_get_string_node(node, "null", 1, &p)) { - case eclat_map_failure: + for (i = 0; gdbm_map_kw[i].ident; i++) + gdbm_map_kw[i].varptr = gdbm_map; + if (grecs_tree_process(node->down, gdbm_map_kw)) { + gdbm_map_free(dbg, gdbm_map); + return eclat_map_failure; + } + if (!gdbm_map->name) { + grecs_error(&node->locus, 0, "file not specified"); + gdbm_map_free(dbg, gdbm_map); return eclat_map_failure; - case eclat_map_not_found: - break; - case eclat_map_ok: - if (grecs_string_convert(&gdbm_map->nullflag, grecs_type_bool, - p->v.value->v.string, - &p->locus)) - return eclat_map_failure; } - + + if (eclat_get_string_node(node, "file", 0, &p)) + abort(); + gdbm_map->locus = p->locus; *return_gdbm_map = gdbm_map; return eclat_map_ok; } -static void -gdbm_map_free(int dbg, void *data) -{ - struct gdbm_map *gdbm_map = data; - free(gdbm_map->name); - free(gdbm_map); -} - static int gdbm_map_open(int dbg, void *data) { @@ -112,5 +136,6 @@ struct eclat_map_drv eclat_map_drv_gdbm = { gdbm_map_open, gdbm_map_close, gdbm_map_get, - gdbm_map_free + gdbm_map_free, + gdbm_map_confhelp }; |