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/filemap.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/filemap.c')
-rw-r--r-- | lib/filemap.c | 58 |
1 files changed, 46 insertions, 12 deletions
diff --git a/lib/filemap.c b/lib/filemap.c index bced0d4..aa2fa6d 100644 --- a/lib/filemap.c +++ b/lib/filemap.c @@ -23,30 +23,63 @@ struct filemap { struct grecs_locus locus; }; +static struct grecs_keyword filemap_kw[] = { + { "type", "'file", "Set map type", + grecs_type_null }, + { "file", NULL, "File name", + grecs_type_string, GRECS_DFLT, NULL, + offsetof(struct filemap, name) }, + { NULL } +}; + +static void +filemap_confhelp() +{ + static struct grecs_keyword filemap_top[] = { + { "map", "name: string", + "Configuration for a file map", + grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, + filemap_kw }, + { NULL } + }; + grecs_print_statement_array(filemap_top, 1, 0, stdout); +} + +static void +filemap_free(int dbg, void *data) +{ + struct filemap *filemap = data; + free(filemap->name); + free(filemap); +} + static int filemap_config(int dbg, struct grecs_node *node, void *data) { struct filemap *filemap, **return_filemap = data; + int i; const char *filename; struct grecs_node *p; - if (eclat_get_string_node(node, "file", 0, &p)) - return eclat_map_failure; filemap = grecs_malloc(sizeof(*filemap)); - filemap->name = grecs_strdup(p->v.value->v.string); + for (i = 0; filemap_kw[i].ident; i++) + filemap_kw[i].varptr = filemap; + if (grecs_tree_process(node->down, filemap_kw)) { + filemap_free(dbg, filemap); + return eclat_map_failure; + } + if (!filemap->name) { + grecs_error(&node->locus, 0, "file not specified"); + filemap_free(dbg, filemap); + return eclat_map_failure; + } + if (eclat_get_string_node(node, "file", 0, &p)) + abort(); /* shouldn't happen */ filemap->locus = p->locus; *return_filemap = filemap; return eclat_map_ok; } -static void -filemap_free(int dbg, void *data) -{ - struct filemap *filemap = data; - free(filemap->name); - free(filemap); -} - static int filemap_open(int dbg, void *data) { @@ -135,6 +168,7 @@ struct eclat_map_drv eclat_map_drv_file = { filemap_open, filemap_close, filemap_get, - filemap_free + filemap_free, + filemap_confhelp }; |