diff options
author | Bruce Momjian | 2003-03-20 06:43:35 +0000 |
---|---|---|
committer | Bruce Momjian | 2003-03-20 06:43:35 +0000 |
commit | add932ee91b9ca78c1a0647487cd6d2a680c4f12 (patch) | |
tree | abb208bec97099a408ead6d6c5b0f0929c459a2d /src/bin/psql/variables.h | |
parent | 1b3d4cefe8e025a40e3a795f311d4711178366e9 (diff) |
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/variables.h')
-rw-r--r-- | src/bin/psql/variables.h | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/bin/psql/variables.h b/src/bin/psql/variables.h index a3e79b76214..d297b5a4efa 100644 --- a/src/bin/psql/variables.h +++ b/src/bin/psql/variables.h @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/variables.h,v 1.10 2001/11/05 17:46:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/variables.h,v 1.11 2003/03/20 06:43:35 momjian Exp $ */ /* @@ -30,10 +30,33 @@ typedef struct _variable *VariableSpace; VariableSpace CreateVariableSpace(void); const char *GetVariable(VariableSpace space, const char *name); -bool GetVariableBool(VariableSpace space, const char *name); -bool SetVariable(VariableSpace space, const char *name, const char *value); -bool SetVariableBool(VariableSpace space, const char *name); -bool DeleteVariable(VariableSpace space, const char *name); -void DestroyVariableSpace(VariableSpace space); +bool GetVariableBool(VariableSpace space, const char *name); +bool VariableEquals(VariableSpace space, const char name[], const char *opt); + +/* Read numeric variable, or defaultval if it is not set, or faultval if its + * value is not a valid numeric string. If allowtrail is false, this will + * include the case where there are trailing characters after the number. + */ +int GetVariableNum(VariableSpace space, + const char name[], + int defaultval, + int faultval, + bool allowtrail); + + +/* Find value of variable <name> among NULL-terminated list of alternative + * options. Returns var_notset if the variable was not set, var_notfound if its + * value did not occur in the list of options, or the number of the matching + * option. The first option is 1, the second is 2 and so on. + */ +enum { var_notset = 0, var_notfound = -1 }; +int SwitchVariable(VariableSpace space, const char name[], const char *opt,...); + +void PrintVariables(VariableSpace space); + +bool SetVariable(VariableSpace space, const char *name, const char *value); +bool SetVariableBool(VariableSpace space, const char *name); +bool DeleteVariable(VariableSpace space, const char *name); +void DestroyVariableSpace(VariableSpace space); #endif /* VARIABLES_H */ |