aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/prompt.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2003-03-20 06:43:35 +0000
committerBruce Momjian <bruce@momjian.us>2003-03-20 06:43:35 +0000
commitadd932ee91b9ca78c1a0647487cd6d2a680c4f12 (patch)
treeabb208bec97099a408ead6d6c5b0f0929c459a2d /src/bin/psql/prompt.c
parent1b3d4cefe8e025a40e3a795f311d4711178366e9 (diff)
downloadpostgresql-add932ee91b9ca78c1a0647487cd6d2a680c4f12.tar.gz
postgresql-add932ee91b9ca78c1a0647487cd6d2a680c4f12.zip
I'm continuing to work on cleaning up code in psql. As things appear
now, my changes seem to work. Some possible minor bugs got squished on the way but I can't be sure without more feedback from people who really put the code to the test. The new patch mostly simplifies variable handling and reduces code duplication. Changes in the command parser eliminate some redundant variables (boolean state + depth counter), replaces some "else if" constructs with switches, and so on. It is meant to be applied together with my previous patch, although I hope they don't conflict; I went back to the CVS version for this one. One more thing I thought should perhaps be changed: an IGNOREEOF value of n will ignore only n-1 EOFs. I didn't want to touch this for fear of breaking existing applications, but it does seem a tad illogical. Jeroen T. Vermeulen
Diffstat (limited to 'src/bin/psql/prompt.c')
-rw-r--r--src/bin/psql/prompt.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index f01a55b5696..194c6ef0f66 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.22 2001/10/25 05:49:54 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.23 2003/03/20 06:43:35 momjian Exp $
*/
#include "postgres_fe.h"
#include "prompt.h"
@@ -69,17 +69,30 @@ get_prompt(promptStatus_t status)
char buf[MAX_PROMPT_SIZE + 1];
bool esc = false;
const char *p;
- const char *prompt_string;
+ const char *prompt_string = "? ";
+ const char *prompt_name = NULL;
- if (status == PROMPT_READY)
- prompt_string = GetVariable(pset.vars, "PROMPT1");
- else if (status == PROMPT_CONTINUE || status == PROMPT_SINGLEQUOTE || status == PROMPT_DOUBLEQUOTE || status == PROMPT_COMMENT || status == PROMPT_PAREN)
- prompt_string = GetVariable(pset.vars, "PROMPT2");
- else if (status == PROMPT_COPY)
- prompt_string = GetVariable(pset.vars, "PROMPT3");
- else
- prompt_string = "? ";
+ switch (status)
+ {
+ case PROMPT_READY:
+ prompt_name = "PROMPT1";
+ break;
+
+ case PROMPT_CONTINUE:
+ case PROMPT_SINGLEQUOTE:
+ case PROMPT_DOUBLEQUOTE:
+ case PROMPT_COMMENT:
+ case PROMPT_PAREN:
+ prompt_name = "PROMPT2";
+ break;
+
+ case PROMPT_COPY:
+ prompt_name = "PROMPT3";
+ break;
+ }
+ if (prompt_name)
+ prompt_string = GetVariable(pset.vars, prompt_name);
destination[0] = '\0';
@@ -92,21 +105,15 @@ get_prompt(promptStatus_t status)
{
switch (*p)
{
- case '%':
- strcpy(buf, "%");
- break;
-
/* Current database */
case '/':
if (pset.db)
strncpy(buf, PQdb(pset.db), MAX_PROMPT_SIZE);
break;
case '~':
- {
- const char *var;
-
if (pset.db)
{
+ const char *var;
if (strcmp(PQdb(pset.db), PQuser(pset.db)) == 0 ||
((var = getenv("PGDATABASE")) && strcmp(var, PQdb(pset.db)) == 0))
strcpy(buf, "~");
@@ -114,7 +121,7 @@ get_prompt(promptStatus_t status)
strncpy(buf, PQdb(pset.db), MAX_PROMPT_SIZE);
}
break;
- }
+
/* DB server hostname (long/short) */
case 'M':
case 'm':
@@ -164,15 +171,8 @@ get_prompt(promptStatus_t status)
case '7':
case '8':
case '9':
- {
- long int l;
- char *end;
-
- l = strtol(p, &end, 0);
- sprintf(buf, "%c", (unsigned char) l);
- p = end - 1;
+ *buf = parse_char(&p);
break;
- }
case 'R':
switch (status)