summaryrefslogtreecommitdiffabout
path: root/lib
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-07 12:57:32 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2012-12-07 13:16:14 (GMT)
commit5a7b73860974384d8e00065105435403b0842ab0 (patch) (side-by-side diff)
tree3f029c22f0a29a842002279bb4b5561af61a8aa8 /lib
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 'lib') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/confirm.c28
-rw-r--r--lib/forlan.c1
-rw-r--r--lib/getyn.c14
-rw-r--r--lib/libeclat.h12
4 files changed, 39 insertions, 16 deletions
diff --git a/lib/confirm.c b/lib/confirm.c
index bd283a1..18eb409 100644
--- a/lib/confirm.c
+++ b/lib/confirm.c
@@ -17,22 +17,32 @@
#include "libeclat.h"
#include <sysexits.h>
-int eclat_confirm_mode = -1;
-
int
-eclat_confirm(const char *prompt, ...)
+eclat_confirm(enum eclat_confirm_mode mode, const char *prompt, ...)
{
int rc;
va_list ap;
-
- if (!isatty(0) || eclat_confirm_mode >= 0) {
- if (eclat_confirm_mode == -1)
- die(EX_USAGE, "stdin not a terminal and no default response provided; use -Y or -N option to override");
- return eclat_confirm_mode;
+
+ switch (mode) {
+ case eclat_confirm_unspecified:
+ case eclat_confirm_positive:
+ return 1;
+ case eclat_confirm_negative:
+ return 0;
+ case eclat_confirm_tty:
+ if (!isatty(0))
+ return 1;
+ break;
+ case eclat_confirm_always:
+ if (!isatty(0))
+ die(EX_USAGE,
+ "confirmation required, "
+ "but stdin is not a terminal");
+ break;
}
va_start(ap, prompt);
- rc = eclat_vgetyn(!!eclat_confirm_mode, prompt, ap);
+ rc = eclat_vgetyn(-1, prompt, ap);
va_end(ap);
return rc;
diff --git a/lib/forlan.c b/lib/forlan.c
index 7a9dab1..828fb09 100644
--- a/lib/forlan.c
+++ b/lib/forlan.c
@@ -58,7 +58,6 @@ static unsigned long
strtots(const char *input)
{
struct tm tm;
- time_t t;
/* 2012-06-21T10:36:48.000Z */
memset(&tm, 0, sizeof(tm));
diff --git a/lib/getyn.c b/lib/getyn.c
index 8ec8a07..ee49d3f 100644
--- a/lib/getyn.c
+++ b/lib/getyn.c
@@ -21,10 +21,14 @@
int
eclat_vgetyn(int dfl, const char *prompt, va_list ap)
{
- static char *hint[] = { "y/N", "Y/n" };
+ static char *hint[] = { "y/n", "y/N", "Y/n" };
int state = 0;
int c, resp;
-
+
+ if (dfl < -1)
+ dfl = -1;
+ else if (dfl > 1)
+ dfl = 1;
do {
switch (state) {
case 1:
@@ -43,7 +47,9 @@ eclat_vgetyn(int dfl, const char *prompt, va_list ap)
case 'N':
return 0;
case '\n':
- return dfl;
+ if (dfl >= 0)
+ return dfl;
+ /* fall through */
default:
err("Please, reply 'y' or 'n'");
}
@@ -52,7 +58,7 @@ eclat_vgetyn(int dfl, const char *prompt, va_list ap)
break;
case 0:
vfprintf(stdout, prompt, ap);
- fprintf(stdout, " [%s] ", hint[dfl]);
+ fprintf(stdout, " [%s] ", hint[dfl+1]);
fflush(stdout);
state = 1;
break;
diff --git a/lib/libeclat.h b/lib/libeclat.h
index 35d2538..a558dae 100644
--- a/lib/libeclat.h
+++ b/lib/libeclat.h
@@ -110,8 +110,16 @@ char *eclat_getans(char *prompt, char *dfl, int pass);
int eclat_getyn(int dfl, const char *prompt, ...);
int eclat_vgetyn(int dfl, const char *prompt, va_list ap);
-extern int eclat_confirm_mode;
-int eclat_confirm(const char *prompt, ...);
+enum eclat_confirm_mode
+{
+ eclat_confirm_unspecified,
+ eclat_confirm_positive,
+ eclat_confirm_negative,
+ eclat_confirm_tty,
+ eclat_confirm_always
+};
+
+int eclat_confirm(enum eclat_confirm_mode mode, const char *prompt, ...);
#define ECLAT_MAP_OPEN 0x01

Return to:

Send suggestions and report system problems to the System administrator.