(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
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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));
+ }
}
*
* 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
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 */
* 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 $
*
*-------------------------------------------------------------------------
*/
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;
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;
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;
* 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 $
*
*-------------------------------------------------------------------------
*/
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);
}
* 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 $
*
*-------------------------------------------------------------------------
*/
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);
}
-# $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