1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

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
This commit is contained in:
Bruce Momjian
2003-03-20 06:43:35 +00:00
parent 1b3d4cefe8
commit add932ee91
10 changed files with 235 additions and 203 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/variables.c,v 1.9 2001/02/10 02:31:28 tgl Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/variables.c,v 1.10 2003/03/20 06:43:35 momjian Exp $
*/
#include "postgres_fe.h"
#include "variables.h"
@ -68,6 +68,74 @@ GetVariableBool(VariableSpace space, const char *name)
}
bool
VariableEquals(VariableSpace space, const char name[], const char value[])
{
const char *var;
var = GetVariable(space, name);
return var && (strcmp(var, value) == 0);
}
int
GetVariableNum(VariableSpace space,
const char name[],
int defaultval,
int faultval,
bool allowtrail)
{
const char *var;
int result;
var = GetVariable(space, name);
if (!var)
result = defaultval;
else if (!var[0])
result = faultval;
else
{
char *end;
result = strtol(var, &end, 0);
if (!allowtrail && *end)
result = faultval;
}
return result;
}
int
SwitchVariable(VariableSpace space, const char name[], const char *opt, ...)
{
int result;
const char *var;
var = GetVariable(space, name);
if (var)
{
va_list args;
va_start(args, opt);
for (result=1; opt && (strcmp(var, opt) != 0); result++)
opt = va_arg(args,const char *);
if (!opt) result = var_notfound;
va_end(args);
}
else
result = var_notset;
return result;
}
void
PrintVariables(VariableSpace space)
{
struct _variable *ptr;
for (ptr = space->next; ptr; ptr = ptr->next)
printf("%s = '%s'\n", ptr->name, ptr->value);
}
bool
SetVariable(VariableSpace space, const char *name, const char *value)