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_conf_internal(struct opt_item * opt, const char * value, void * data UNUSED) {
28 struct cf_context *cc = cf_get_context();
29 switch (opt->letter) {
33 opt_failure("Cannot set %s", value);
37 opt_failure("Cannot load config file %s", value);
39 #ifdef CONFIG_UCW_DEBUG
41 opt_conf_end_of_options(cc);
42 struct fastbuf *b = bfdopen(1, 4096);
51 void opt_conf_hook_internal(struct opt_item * opt, const char * value UNUSED, void * data UNUSED) {
56 } state = OPT_CONF_HOOK_BEGIN;
60 if (opt->letter == 'S' || opt->letter == 'C' || (opt->name && !strcmp(opt->name, "dumpconfig")))
64 case OPT_CONF_HOOK_BEGIN:
66 state = OPT_CONF_HOOK_CONFIG;
68 opt_conf_end_of_options(cf_get_context());
69 state = OPT_CONF_HOOK_OTHERS;
72 case OPT_CONF_HOOK_CONFIG:
74 opt_conf_end_of_options(cf_get_context());
75 state = OPT_CONF_HOOK_OTHERS;
78 case OPT_CONF_HOOK_OTHERS:
80 opt_failure("Config options (-C, -S) must stand before other options.");