1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Add psql \prompt capability.

Chad Wagner
This commit is contained in:
Bruce Momjian
2007-02-23 18:20:59 +00:00
parent cc77005df7
commit 7031dd6869
4 changed files with 77 additions and 6 deletions

View File

@ -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)
{