diff options
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c index f58747c..48bece7 100644 --- a/src/config.c +++ b/src/config.c @@ -149,6 +149,76 @@ cb_define_format(enum grecs_callback_command cmd, return 0; } +static int +cb_confirm(enum grecs_callback_command cmd, + grecs_locus_t *locus, + void *varptr, + grecs_value_t *value, + void *cb_data) +{ + struct grecs_list_entry *ep; + grecs_value_t *argval; + enum eclat_confirm_mode cfmode; + char *s; + + if (cmd != grecs_callback_set_value) { + grecs_error(locus, 0, "Unexpected block statement"); + return 1; + } + if (!value || value->type != GRECS_TYPE_ARRAY || value->v.arg.c != 2) { + grecs_error(locus, 0, "expected two values"); + return 1; + } + + if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) { + grecs_error(locus, 0, "first argument not a string"); + return 1; + } + + switch (value->v.arg.v[1]->type) { + case GRECS_TYPE_STRING: + set_command_confirmation(value->v.arg.v[1]->v.string, cfmode, + &value->v.arg.v[1]->locus); + return 0; + + case GRECS_TYPE_LIST: + break; + + default: + grecs_error(locus, 0, "second argument not a list"); + return 1; + } + + s = value->v.arg.v[0]->v.string; + if (strcmp(s, "positive") == 0) + cfmode = eclat_confirm_positive; + else if (strcmp(s, "negative") == 0) + cfmode = eclat_confirm_negative; + else if (strcmp(s, "tty") == 0) + cfmode = eclat_confirm_tty; + else if (strcmp(s, "always") == 0) + cfmode = eclat_confirm_always; + else { + grecs_error(&value->v.arg.v[0]->locus, 0, + "unrecognized confirmation mode"); + return 1; + } + + for (ep = value->v.arg.v[1]->v.list->head; ep; ep = ep->next) { + argval = ep->data; + if (argval->type != GRECS_TYPE_STRING) { + grecs_error(&argval->locus, 0, + "list element not a string"); + continue; + } + + set_command_confirmation(argval->v.string, cfmode, + &argval->locus); + } + + return 0; +} + static struct grecs_keyword ssl_kw[] = { { "enable", NULL, "Use SSL", @@ -218,6 +288,10 @@ static struct grecs_keyword eclat_kw[] = { grecs_type_string, GRECS_DFLT, &format_file }, { "map", "name: string", "Configure a map", grecs_type_section, GRECS_INAC }, + { "confirm", + "<mode: { positive | negative | tty | always }> <commands: list>", + "Set confirmation mode", + grecs_type_string, GRECS_LIST, NULL, 0, cb_confirm }, { NULL } }; |