aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-19 11:28:28 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-19 18:30:01 +0300
commit1153970626892573e5966e135e8d81185f4ea53c (patch)
tree773fdf5a8d00ec2ef752c3a8fd5f32c79829cf23 /src/config.c
downloadeclat-1153970626892573e5966e135e8d81185f4ea53c.tar.gz
eclat-1153970626892573e5966e135e8d81185f4ea53c.tar.bz2
Initial commit
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
new file mode 100644
index 0000000..184b42a
--- /dev/null
+++ b/src/config.c
@@ -0,0 +1,110 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "eclat.h"
+
+struct config_finish_hook_entry
+{
+ struct config_finish_hook_entry *next;
+ config_finish_hook_t fun;
+ void *data;
+};
+
+static struct config_finish_hook_entry *cfh_head, *cfh_tail;
+
+void
+add_config_finish_hook(config_finish_hook_t fun, void *data)
+{
+ struct config_finish_hook_entry *ent = grecs_malloc(sizeof(*ent));
+ ent->next = NULL;
+ ent->fun = fun;
+ ent->data = data;
+ if (cfh_tail)
+ cfh_tail->next = ent;
+ else
+ cfh_head = ent;
+ cfh_tail = ent;
+}
+
+int
+run_config_finish_hooks()
+{
+ struct config_finish_hook_entry *p;
+ int rc = 0;
+
+ for (p = cfh_head; p; p = p->next)
+ rc |= p->fun(p->data);
+ return rc;
+}
+
+static struct grecs_keyword eclat_kw[] = {
+ { "host", "hostname",
+ "Send queries to <hostname> instead of the default host",
+ grecs_type_string, GRECS_DFLT, &default_host },
+ { "access-file", "file",
+ "Specify a file containing `accessID:accessKey' pairs",
+ grecs_type_string, GRECS_DFLT, &access_file_name },
+ { "region", "name",
+ "Define default AWS region",
+ grecs_type_string, GRECS_DFLT, &region_name },
+
+ { NULL }
+};
+
+void
+config_help()
+{
+ static char docstring[] =
+ N_("Configuration file structure for eclat.\n"
+ "For more information, use `info eclat configuration'.");
+ grecs_print_docstring(docstring, 0, stdout);
+ grecs_print_statement_array(eclat_kw, 1, 0, stdout);
+}
+
+static void
+grecs_print_diag(grecs_locus_t const *locus, int err, int errcode,
+ const char *msg)
+{
+ diag(locus, err ? NULL : "warning", "%s", msg);
+}
+
+void
+config_init()
+{
+ grecs_include_path_setup(DEFAULT_VERSION_INCLUDE_DIR,
+ DEFAULT_INCLUDE_DIR, NULL);
+ grecs_preprocessor = DEFAULT_PREPROCESSOR;
+ grecs_log_to_stderr = 1;
+ grecs_adjust_string_locations = 1;
+ grecs_print_diag_fun = grecs_print_diag;
+}
+
+void
+config_finish(struct grecs_node *tree)
+{
+ struct grecs_node *node;
+
+ grecs_tree_reduce(tree, eclat_kw, GRECS_AGGR);
+ if (debug_level[ECLAT_DEBCAT_CONF]) {
+ grecs_print_node(tree, GRECS_NODE_FLAG_DEFAULT, stderr);
+ fputc('\n', stdout);
+ }
+ if (grecs_error_count || run_config_finish_hooks())
+ exit(EX_CONFIG);
+}
+
+
+

Return to:

Send suggestions and report system problems to the System administrator.