Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cbb7acf

Browse files
committed
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
1 parent ae3f415 commit cbb7acf

File tree

6 files changed

+34
-38
lines changed

6 files changed

+34
-38
lines changed

src/bin/scripts/common.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.20 2006/03/05 15:58:52 momjian Exp $
10+
* $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.21 2006/09/22 18:50:41 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -198,18 +198,29 @@ executeCommand(PGconn *conn, const char *query,
198198
* Check yes/no answer in a localized way. 1=yes, 0=no, -1=neither.
199199
*/
200200

201-
/* translator: Make sure the (y/n) prompts match the translation of this. */
201+
/* translator: abbreviation for "yes" */
202202
#define PG_YESLETTER gettext_noop("y")
203-
/* translator: Make sure the (y/n) prompts match the translation of this. */
203+
/* translator: abbreviation for "no" */
204204
#define PG_NOLETTER gettext_noop("n")
205205

206-
int
207-
check_yesno_response(const char *string)
206+
bool
207+
yesno_prompt(const char *question)
208208
{
209-
if (strcmp(string, _(PG_YESLETTER)) == 0)
210-
return 1;
211-
else if (strcmp(string, _(PG_NOLETTER)) == 0)
212-
return 0;
213-
else
214-
return -1;
209+
static char prompt[128];
210+
211+
for (;;)
212+
{
213+
char *resp;
214+
215+
/* translator: This is a question followed by the translated options for "yes" and "no". */
216+
snprintf(prompt, sizeof(prompt), _("%s (%s/%s) "), _(question), _(PG_YESLETTER), _(PG_NOLETTER));
217+
resp = simple_prompt(prompt, 1, true);
218+
219+
if (strcmp(resp, _(PG_YESLETTER)) == 0)
220+
return true;
221+
else if (strcmp(resp, _(PG_NOLETTER)) == 0)
222+
return false;
223+
224+
printf(_("Please answer \"%s\" or \"%s\".\n"), _(PG_YESLETTER), _(PG_NOLETTER));
225+
}
215226
}

src/bin/scripts/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2003-2006, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/scripts/common.h,v 1.14 2006/07/14 14:52:27 momjian Exp $
7+
* $PostgreSQL: pgsql/src/bin/scripts/common.h,v 1.15 2006/09/22 18:50:41 petere Exp $
88
*/
99
#ifndef COMMON_H
1010
#define COMMON_H
@@ -35,6 +35,6 @@ extern PGresult *executeQuery(PGconn *conn, const char *query,
3535
extern void executeCommand(PGconn *conn, const char *query,
3636
const char *progname, bool echo);
3737

38-
extern int check_yesno_response(const char *string);
38+
extern bool yesno_prompt(const char *question);
3939

4040
#endif /* COMMON_H */

src/bin/scripts/createuser.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.32 2006/06/01 00:15:36 tgl Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.33 2006/09/22 18:50:41 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -192,10 +192,7 @@ main(int argc, char *argv[])
192192

193193
if (superuser == 0)
194194
{
195-
char *reply;
196-
197-
reply = simple_prompt("Shall the new role be a superuser? (y/n) ", 1, true);
198-
if (check_yesno_response(reply) == 1)
195+
if (yesno_prompt("Shall the new role be a superuser?"))
199196
superuser = TRI_YES;
200197
else
201198
superuser = TRI_NO;
@@ -210,21 +207,15 @@ main(int argc, char *argv[])
210207

211208
if (createdb == 0)
212209
{
213-
char *reply;
214-
215-
reply = simple_prompt("Shall the new role be allowed to create databases? (y/n) ", 1, true);
216-
if (check_yesno_response(reply) == 1)
210+
if (yesno_prompt("Shall the new role be allowed to create databases?"))
217211
createdb = TRI_YES;
218212
else
219213
createdb = TRI_NO;
220214
}
221215

222216
if (createrole == 0)
223217
{
224-
char *reply;
225-
226-
reply = simple_prompt("Shall the new role be allowed to create more new roles? (y/n) ", 1, true);
227-
if (check_yesno_response(reply) == 1)
218+
if (yesno_prompt("Shall the new role be allowed to create more new roles?"))
228219
createrole = TRI_YES;
229220
else
230221
createrole = TRI_NO;

src/bin/scripts/dropdb.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.17 2006/05/29 19:52:46 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.18 2006/09/22 18:50:41 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -104,11 +104,8 @@ main(int argc, char *argv[])
104104

105105
if (interactive)
106106
{
107-
char *reply;
108-
109107
printf(_("Database \"%s\" will be permanently removed.\n"), dbname);
110-
reply = simple_prompt("Are you sure? (y/n) ", 1, true);
111-
if (check_yesno_response(reply) != 1)
108+
if (!yesno_prompt("Are you sure?"))
112109
exit(0);
113110
}
114111

src/bin/scripts/dropuser.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.18 2006/05/29 19:52:46 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.19 2006/09/22 18:50:41 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -105,11 +105,8 @@ main(int argc, char *argv[])
105105

106106
if (interactive)
107107
{
108-
char *reply;
109-
110108
printf(_("Role \"%s\" will be permanently removed.\n"), dropuser);
111-
reply = simple_prompt("Are you sure? (y/n) ", 1, true);
112-
if (check_yesno_response(reply) != 1)
109+
if (!yesno_prompt("Are you sure?"))
113110
exit(0);
114111
}
115112

src/bin/scripts/nls.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# $PostgreSQL: pgsql/src/bin/scripts/nls.mk,v 1.19 2005/07/29 15:13:11 momjian Exp $
1+
# $PostgreSQL: pgsql/src/bin/scripts/nls.mk,v 1.20 2006/09/22 18:50:41 petere Exp $
22
CATALOG_NAME := pgscripts
33
AVAIL_LANGUAGES := cs de es fr it ko pt_BR ro ru sk sl sv tr zh_CN zh_TW
44
GETTEXT_FILES := createdb.c createlang.c createuser.c \
55
dropdb.c droplang.c dropuser.c \
66
clusterdb.c vacuumdb.c reindexdb.c \
77
common.c
8-
GETTEXT_TRIGGERS:= _ simple_prompt
8+
GETTEXT_TRIGGERS:= _ simple_prompt yesno_prompt

0 commit comments

Comments
 (0)