aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-10-08 23:00:42 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-10-08 23:00:42 +0300
commite2bb02092abe1321c534ad8a6c168b2803245cc5 (patch)
tree080290a3d844cabb433156b17aca805e2260950a
parent9b56a5b05db6630a667ad0c9b16ec45a4e52044d (diff)
downloadeclat-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.
m---------grecs0
-rw-r--r--lib/filemap.c58
-rw-r--r--lib/gdbmmap.c75
-rw-r--r--lib/ldapmap.c29
-rw-r--r--lib/libeclat.h2
-rw-r--r--lib/map.c15
-rw-r--r--src/config.c3
7 files changed, 131 insertions, 51 deletions
diff --git a/grecs b/grecs
-Subproject 4b49dd31f76faf42aa0771af2aeb8161e38f2fe
+Subproject bef65e80588f71b1fe5247869e6cab20d334aa6
diff --git a/lib/filemap.c b/lib/filemap.c
index bced0d4..aa2fa6d 100644
--- a/lib/filemap.c
+++ b/lib/filemap.c
@@ -25,2 +25,32 @@ struct filemap {
+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
@@ -29,2 +59,3 @@ filemap_config(int dbg, struct grecs_node *node, void *data)
struct filemap *filemap, **return_filemap = data;
+ int i;
const char *filename;
@@ -32,6 +63,16 @@ filemap_config(int dbg, struct grecs_node *node, void *data)
- 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;
@@ -41,10 +82,2 @@ filemap_config(int dbg, struct grecs_node *node, void *data)
-static void
-filemap_free(int dbg, void *data)
-{
- struct filemap *filemap = data;
- free(filemap->name);
- free(filemap);
-}
-
static int
@@ -137,3 +170,4 @@ struct eclat_map_drv eclat_map_drv_file = {
filemap_get,
- filemap_free
+ filemap_free,
+ filemap_confhelp
};
diff --git a/lib/gdbmmap.c b/lib/gdbmmap.c
index 4fdaa33..7ecb88c 100644
--- a/lib/gdbmmap.c
+++ b/lib/gdbmmap.c
@@ -29,2 +29,35 @@ struct gdbm_map {
+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
@@ -33,22 +66,21 @@ 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;
@@ -57,10 +89,2 @@ gdbm_map_config(int dbg, struct grecs_node *node, void *data)
-static void
-gdbm_map_free(int dbg, void *data)
-{
- struct gdbm_map *gdbm_map = data;
- free(gdbm_map->name);
- free(gdbm_map);
-}
-
static int
@@ -114,3 +138,4 @@ struct eclat_map_drv eclat_map_drv_gdbm = {
gdbm_map_get,
- gdbm_map_free
+ gdbm_map_free,
+ gdbm_map_confhelp
};
diff --git a/lib/ldapmap.c b/lib/ldapmap.c
index 8d687e4..5ef20cb 100644
--- a/lib/ldapmap.c
+++ b/lib/ldapmap.c
@@ -44,12 +44,2 @@ static void ldap_map_free(int dbg, void *data);
static int
-cb_null(enum grecs_callback_command cmd,
- grecs_locus_t *locus,
- void *varptr,
- grecs_value_t *value,
- void *cb_data)
-{
- return 0;
-}
-
-static int
cb_tls(enum grecs_callback_command cmd,
@@ -84,4 +74,3 @@ static char *typestr;
static struct grecs_keyword ldapmap_kw[] = {
- { "type", "arg", "Set map type",
- grecs_type_string, GRECS_DFLT, NULL, 0, cb_null },
+ { "type", "'ldap", "Set map type", grecs_type_null },
{ "uri", "arg",
@@ -170,2 +159,15 @@ ldap_map_config(int dbg, struct grecs_node *node, void *data)
+static void
+ldap_map_confhelp()
+{
+ static struct grecs_keyword ldapmap_top[] = {
+ { "map", "name: string",
+ "Configuration for an LDAP map",
+ grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL,
+ ldapmap_kw },
+ { NULL }
+ };
+ grecs_print_statement_array(ldapmap_top, 1, 0, stdout);
+
+}
@@ -632,3 +634,4 @@ struct eclat_map_drv eclat_map_drv_ldap = {
ldap_map_get,
- ldap_map_free
+ ldap_map_free,
+ ldap_map_confhelp
};
diff --git a/lib/libeclat.h b/lib/libeclat.h
index 2b40f43..ecbb844 100644
--- a/lib/libeclat.h
+++ b/lib/libeclat.h
@@ -117,2 +117,3 @@ struct eclat_map_drv {
void (*map_free)(int, void *);
+ void (*map_confhelp)(void);
};
@@ -144,2 +145,3 @@ void eclat_map_foreach(int (*fun)(struct eclat_map *, void *), void *data);
void eclat_map_free_all(void);
+void eclat_map_confhelp(void);
diff --git a/lib/map.c b/lib/map.c
index c8acfee..f723cd9 100644
--- a/lib/map.c
+++ b/lib/map.c
@@ -327,2 +327,17 @@ eclat_map_free_all()
}
+
+static int
+drv_help(void *data, void *unused)
+{
+ struct eclat_map_drv *drv = data;
+ if (drv->map_confhelp)
+ drv->map_confhelp();
+ return 0;
+}
+
+void
+eclat_map_confhelp()
+{
+ grecs_symtab_enumerate(mapdrv_symtab, drv_help, NULL);
+}
diff --git a/src/config.c b/src/config.c
index 7271b36..e781f34 100644
--- a/src/config.c
+++ b/src/config.c
@@ -175,3 +175,3 @@ static struct grecs_keyword eclat_kw[] = {
};
-
+
void
@@ -184,2 +184,3 @@ config_help()
grecs_print_statement_array(eclat_kw, 1, 0, stdout);
+ eclat_map_confhelp();
}

Return to:

Send suggestions and report system problems to the System administrator.