- for (int i=0;i<oc->positional_max+257;i++) {
- if (!oc->shortopt[i])
- continue;
- if (!oc->shortopt[i]->count && (oc->shortopt[i]->flags & OPT_REQUIRED))
- if (i < 256)
- opt_failure("Required option -%c not found.", oc->shortopt[i]->item->letter);
- else
- opt_failure("Required positional argument #%d not found.", (i > 256) ? oc->shortopt[i]->item->letter-256 : oc->positional_max+1);
- }
-
- for (int i=0;i<oc->opt_count;i++) {
- if (!oc->opts[i])
- continue;
- if (!oc->opts[i]->count && (oc->opts[i]->flags & OPT_REQUIRED))
- opt_failure("Required option --%s not found.", oc->opts[i]->item->name);
- }
-}
-
-static void opt_conf_end_of_options(struct cf_context *cc) {
- cf_load_default(cc);
- if (cc->postpone_commit && cf_close_group())
- opt_failure("Loading of configuration failed");
-}
-
-void opt_conf_internal(struct opt_item * opt, const char * value, void * data UNUSED) {
- struct cf_context *cc = cf_get_context();
- switch (opt->letter) {
- case 'S':
- cf_load_default(cc);
- if (cf_set(value))
- opt_failure("Cannot set %s", value);
- break;
- case 'C':
- if (cf_load(value))
- opt_failure("Cannot load config file %s", value);
- break;
-#ifdef CONFIG_UCW_DEBUG
- case '0':
- opt_conf_end_of_options(cc);
- struct fastbuf *b = bfdopen(1, 4096);
- cf_dump_sections(b);
- bclose(b);
- exit(0);
- break;
-#endif
- }
-
- opt_conf_parsed_count++;
-}
-
-void opt_conf_hook_internal(struct opt_item * opt, const char * value UNUSED, void * data UNUSED) {
- static enum {
- OPT_CONF_HOOK_BEGIN,
- OPT_CONF_HOOK_CONFIG,
- OPT_CONF_HOOK_OTHERS
- } state = OPT_CONF_HOOK_BEGIN;
-
- int confopt = 0;
-
- if (opt->letter == 'S' || opt->letter == 'C' || (opt->name && !strcmp(opt->name, "dumpconfig")))
- confopt = 1;
-
- switch (state) {
- case OPT_CONF_HOOK_BEGIN:
- if (confopt)
- state = OPT_CONF_HOOK_CONFIG;
- else {
- opt_conf_end_of_options(cf_get_context());
- state = OPT_CONF_HOOK_OTHERS;
- }
- break;
- case OPT_CONF_HOOK_CONFIG:
- if (!confopt) {
- opt_conf_end_of_options(cf_get_context());
- state = OPT_CONF_HOOK_OTHERS;
- }
- break;
- case OPT_CONF_HOOK_OTHERS:
- if (confopt)
- opt_failure("Config options (-C, -S) must stand before other options.");
- break;
- default:
- ASSERT(0);
- }