diff options
| author | Peter Eisentraut | 2006-09-22 18:50:41 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2006-09-22 18:50:41 +0000 |
| commit | 8cdd997ec9ba373c9df84624c62936a69387fe36 (patch) | |
| tree | fa30ae9a421cc05e7f2ed86c9ad8b8e42319009b /src/bin/scripts/common.c | |
| parent | 8e7581cbd1fc2c42650b2be8df58cb1eb9254ac2 (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
Diffstat (limited to 'src/bin/scripts/common.c')
| -rw-r--r-- | src/bin/scripts/common.c | 31 |
1 files changed, 21 insertions, 10 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)); + } } |
