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
This commit is contained in:
parent
ae3f415f1d
commit
cbb7acface
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.20 2006/03/05 15:58:52 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.21 2006/09/22 18:50:41 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* Copyright (c) 2003-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/common.h,v 1.14 2006/07/14 14:52:27 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/common.h,v 1.15 2006/09/22 18:50:41 petere Exp $
|
||||
*/
|
||||
#ifndef COMMON_H
|
||||
#define 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 */
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.32 2006/06/01 00:15:36 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.33 2006/09/22 18:50:41 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -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;
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.17 2006/05/29 19:52:46 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.18 2006/09/22 18:50:41 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.18 2006/05/29 19:52:46 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.19 2006/09/22 18:50:41 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
# $PostgreSQL: pgsql/src/bin/scripts/nls.mk,v 1.19 2005/07/29 15:13:11 momjian Exp $
|
||||
# $PostgreSQL: pgsql/src/bin/scripts/nls.mk,v 1.20 2006/09/22 18:50:41 petere Exp $
|
||||
CATALOG_NAME := pgscripts
|
||||
AVAIL_LANGUAGES := cs de es fr it ko pt_BR ro ru sk sl sv tr zh_CN zh_TW
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user