diff options
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 }; |