summaryrefslogtreecommitdiff
path: root/src/bin/psql/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r--src/bin/psql/command.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index c25a5e6f0f7..bcaf684a8ec 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.177 2007/01/05 22:19:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.178 2007/02/23 18:20:58 momjian Exp $
*/
#include "postgres_fe.h"
#include "command.h"
@@ -712,6 +712,57 @@ exec_command(const char *cmd,
free(pw2);
}
+ /* \prompt -- prompt and set variable */
+ else if (strcmp(cmd, "prompt") == 0)
+ {
+ char *opt, *prompt_text = NULL;
+ char *arg1, *arg2;
+
+ arg1 = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, false);
+ arg2 = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, false);
+
+ if (!arg1)
+ {
+ psql_error("\\%s: missing required argument\n", cmd);
+ success = false;
+ }
+ else
+ {
+ char *result;
+
+ if (arg2)
+ {
+ prompt_text = arg1;
+ opt = arg2;
+ }
+ else
+ opt = arg1;
+
+ if (!pset.inputfile)
+ result = simple_prompt(prompt_text, 4096, true);
+ else
+ {
+ if (prompt_text)
+ {
+ fputs(prompt_text, stdout);
+ fflush(stdout);
+ }
+ result = gets_fromFile(stdin);
+ }
+
+ if (!SetVariable(pset.vars, opt, result))
+ {
+ psql_error("\\%s: error\n", cmd);
+ success = false;
+ }
+
+ free(result);
+ if (prompt_text)
+ free(prompt_text);
+ free(opt);
+ }
+ }
+
/* \pset -- set printing parameters */
else if (strcmp(cmd, "pset") == 0)
{