2 * UCW Library -- Interface between command-line options and configuration
4 * (c) 2013 Jan Moskyto Matejka <mq@ucw.cz>
5 * (c) 2014 Martin Mares <mj@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
13 #include <ucw/opt-internal.h>
15 #include <ucw/conf-internal.h>
16 #include <ucw/fastbuf.h>
21 static void opt_conf_end_of_options(struct cf_context *cc) {
23 if (cc->postpone_commit && cf_close_group())
24 opt_failure("Loading of configuration failed");
27 void opt_handle_config(struct opt_item * opt UNUSED, const char * value, void * data UNUSED)
30 exit(1); // Error message is already printed by cf_load()
33 void opt_handle_set(struct opt_item * opt UNUSED, const char * value, void * data UNUSED)
35 struct cf_context *cc = cf_get_context();
38 opt_failure("Cannot set %s", value);
41 void opt_handle_dumpconfig(struct opt_item * opt UNUSED, const char * value UNUSED, void * data UNUSED)
43 struct cf_context *cc = cf_get_context();
44 opt_conf_end_of_options(cc);
45 struct fastbuf *b = bfdopen(1, 4096);
51 void opt_conf_hook_internal(struct opt_item * opt, uns event, const char * value UNUSED, void * data UNUSED) {
56 } state = OPT_CONF_HOOK_BEGIN;
57 struct cf_context *cc = cf_get_context();
59 if (event == OPT_HOOK_FINAL) {
60 opt_conf_end_of_options(cc);
64 ASSERT(event == OPT_HOOK_BEFORE_VALUE);
66 bool confopt = opt->flags & OPT_BEFORE_CONFIG;
69 case OPT_CONF_HOOK_BEGIN:
71 state = OPT_CONF_HOOK_CONFIG;
73 opt_conf_end_of_options(cc);
74 state = OPT_CONF_HOOK_OTHERS;
77 case OPT_CONF_HOOK_CONFIG:
79 opt_conf_end_of_options(cc);
80 state = OPT_CONF_HOOK_OTHERS;
83 case OPT_CONF_HOOK_OTHERS:
85 opt_failure("Config options must stand before other options.");