aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-07 14:57:32 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-12-07 15:16:14 +0200
commit5a7b73860974384d8e00065105435403b0842ab0 (patch)
tree3f029c22f0a29a842002279bb4b5561af61a8aa8 /src/config.c
parentc12cd5695cf1a6c2c44100a68762ab66356f43b8 (diff)
downloadeclat-5a7b73860974384d8e00065105435403b0842ab0.tar.gz
eclat-5a7b73860974384d8e00065105435403b0842ab0.tar.bz2
Re-implement confirmation support.
* doc/eclat-delete-volume.1: Update. * doc/eclat-release-address.1: Update. * doc/eclat.1: Update. * doc/eclat.conf.5: New section "CONFIRMATION" * lib/getyn.c (eclat_vgetyn): Negative default stands for no default at all. * lib/confirm.c (eclat_confirm_mode): Remove. (eclat_confirm): Change signature. Act according to the first argument. * lib/libeclat.h (eclat_confirm_mode): New enum. (eclat_confirm): Change signature. * src/cmdline.opt: Change handling of -Y and -N options. * src/config.c: New statement "confirm". * src/cretags.c: Remove call to eclat_confirm. This is done by the caller. * src/delvol.c: Likewise. * src/reladdr.c: Likewise. * src/eclat.c (confirm_mode): New variable. (command) <flags>: New member. (cmdtab): Mark commands with appropriate flags. (main): Call eclat_confirm to confirm the command. * src/eclat.h (confirm_mode): New extern. (set_command_confirmation): New proto. * etc/eclat.cfin: Set a reasonably safe confirmation default. * lib/forlan.c (strtots): Remove unused variable.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c74
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 }
};

Return to:

Send suggestions and report system problems to the System administrator.