summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2006-09-22 18:50:41 +0000
committerPeter Eisentraut2006-09-22 18:50:41 +0000
commit8cdd997ec9ba373c9df84624c62936a69387fe36 (patch)
treefa30ae9a421cc05e7f2ed86c9ad8b8e42319009b
parent8e7581cbd1fc2c42650b2be8df58cb1eb9254ac2 (diff)
Rearrange yes/no prompting code so that the prompts always show the
(possibly (un)translated) letters that are actually expected as input. Also reject invalid responses instead of silenty taken them as "no". with help from Bernd Helmle
-rw-r--r--src/bin/scripts/common.c31
-rw-r--r--src/bin/scripts/common.h2
-rw-r--r--src/bin/scripts/createuser.c15
-rw-r--r--src/bin/scripts/dropdb.c5
-rw-r--r--src/bin/scripts/dropuser.c5
-rw-r--r--src/bin/scripts/nls.mk2
6 files changed, 28 insertions, 32 deletions
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c
index 765c52ae9a..4b5f94b895 100644
--- a/src/bin/scripts/common.c
+++ b/src/bin/scripts/common.c
@@ -198,18 +198,29 @@ executeCommand(PGconn *conn, const char *query,
* Check yes/no answer in a localized way. 1=yes, 0=no, -1=neither.
*/
-/* translator: Make sure the (y/n) prompts match the translation of this. */
+/* translator: abbreviation for "yes" */
#define PG_YESLETTER gettext_noop("y")
-/* translator: Make sure the (y/n) prompts match the translation of this. */
+/* translator: abbreviation for "no" */
#define PG_NOLETTER gettext_noop("n")
-int
-check_yesno_response(const char *string)
+bool
+yesno_prompt(const char *question)
{
- if (strcmp(string, _(PG_YESLETTER)) == 0)
- return 1;
- else if (strcmp(string, _(PG_NOLETTER)) == 0)
- return 0;
- else
- return -1;
+ static char prompt[128];
+
+ for (;;)
+ {
+ char *resp;
+
+ /* translator: This is a question followed by the translated options for "yes" and "no". */
+ snprintf(prompt, sizeof(prompt), _("%s (%s/%s) "), _(question), _(PG_YESLETTER), _(PG_NOLETTER));
+ resp = simple_prompt(prompt, 1, true);
+
+ if (strcmp(resp, _(PG_YESLETTER)) == 0)
+ return true;
+ else if (strcmp(resp, _(PG_NOLETTER)) == 0)
+ return false;
+
+ printf(_("Please answer \"%s\" or \"%s\".\n"), _(PG_YESLETTER), _(PG_NOLETTER));
+ }
}
diff --git a/src/bin/scripts/common.h b/src/bin/scripts/common.h
index 728522dbdd..125397c4fa 100644
--- a/src/bin/scripts/common.h
+++ b/src/bin/scripts/common.h
@@ -35,6 +35,6 @@ extern PGresult *executeQuery(PGconn *conn, const char *query,
extern void executeCommand(PGconn *conn, const char *query,
const char *progname, bool echo);
-extern int check_yesno_response(const char *string);
+extern bool yesno_prompt(const char *question);
#endif /* COMMON_H */
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index 8ce206293c..45d64475bc 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -192,10 +192,7 @@ main(int argc, char *argv[])
if (superuser == 0)
{
- char *reply;
-
- reply = simple_prompt("Shall the new role be a superuser? (y/n) ", 1, true);
- if (check_yesno_response(reply) == 1)
+ if (yesno_prompt("Shall the new role be a superuser?"))
superuser = TRI_YES;
else
superuser = TRI_NO;
@@ -210,10 +207,7 @@ main(int argc, char *argv[])
if (createdb == 0)
{
- char *reply;
-
- reply = simple_prompt("Shall the new role be allowed to create databases? (y/n) ", 1, true);
- if (check_yesno_response(reply) == 1)
+ if (yesno_prompt("Shall the new role be allowed to create databases?"))
createdb = TRI_YES;
else
createdb = TRI_NO;
@@ -221,10 +215,7 @@ main(int argc, char *argv[])
if (createrole == 0)
{
- char *reply;
-
- reply = simple_prompt("Shall the new role be allowed to create more new roles? (y/n) ", 1, true);
- if (check_yesno_response(reply) == 1)
+ if (yesno_prompt("Shall the new role be allowed to create more new roles?"))
createrole = TRI_YES;
else
createrole = TRI_NO;
diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c
index cce6249f88..7b114914c0 100644
--- a/src/bin/scripts/dropdb.c
+++ b/src/bin/scripts/dropdb.c
@@ -104,11 +104,8 @@ main(int argc, char *argv[])
if (interactive)
{
- char *reply;
-
printf(_("Database \"%s\" will be permanently removed.\n"), dbname);
- reply = simple_prompt("Are you sure? (y/n) ", 1, true);
- if (check_yesno_response(reply) != 1)
+ if (!yesno_prompt("Are you sure?"))
exit(0);
}
diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c
index e34c5ed24d..a946823fda 100644
--- a/src/bin/scripts/dropuser.c
+++ b/src/bin/scripts/dropuser.c
@@ -105,11 +105,8 @@ main(int argc, char *argv[])
if (interactive)
{
- char *reply;
-
printf(_("Role \"%s\" will be permanently removed.\n"), dropuser);
- reply = simple_prompt("Are you sure? (y/n) ", 1, true);
- if (check_yesno_response(reply) != 1)
+ if (!yesno_prompt("Are you sure?"))
exit(0);
}
diff --git a/src/bin/scripts/nls.mk b/src/bin/scripts/nls.mk
index ad9093bc44..054202e4eb 100644
--- a/src/bin/scripts/nls.mk
+++ b/src/bin/scripts/nls.mk
@@ -5,4 +5,4 @@ GETTEXT_FILES := createdb.c createlang.c createuser.c \
dropdb.c droplang.c dropuser.c \
clusterdb.c vacuumdb.c reindexdb.c \
common.c
-GETTEXT_TRIGGERS:= _ simple_prompt
+GETTEXT_TRIGGERS:= _ simple_prompt yesno_prompt