This patch reduces some unsightly #ifdefs, and fixes two typos in

comments in the psql code. This doesn't make any functional change, so
feel free to save it for 7.5

Neil Conway
This commit is contained in:
Bruce Momjian 2003-12-01 22:14:40 +00:00
parent abd5d75c4c
commit 35ddc2edee
6 changed files with 31 additions and 60 deletions

View File

@ -3,13 +3,12 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.106 2003/11/29 19:52:06 pgsql Exp $
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.107 2003/12/01 22:14:40 momjian Exp $
*/
#include "postgres_fe.h"
#include "command.h"
#include <errno.h>
#include <assert.h>
#include <ctype.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
@ -97,10 +96,7 @@ HandleSlashCmds(const char *line,
const char *continue_parse = NULL; /* tell the mainloop where the
* backslash command ended */
#ifdef USE_ASSERT_CHECKING
assert(line);
#endif
psql_assert(line);
my_line = xstrdup(line);
/*
@ -1234,9 +1230,7 @@ unescape(const unsigned char *source, size_t len)
*tmp;
size_t length;
#ifdef USE_ASSERT_CHECKING
assert(source);
#endif
psql_assert(source);
length = Min(len, strlen(source)) + 1;
@ -1515,12 +1509,7 @@ editFile(const char *fname)
char *sys;
int result;
#ifdef USE_ASSERT_CHECKING
assert(fname);
#else
if (!fname)
return false;
#endif
psql_assert(fname);
/* Find an editor to use */
editorName = getenv("PSQL_EDITOR");
@ -1755,12 +1744,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
{
size_t vallen = 0;
#ifdef USE_ASSERT_CHECKING
assert(param);
#else
if (!param)
return false;
#endif
psql_assert(param);
if (value)
vallen = strlen(value);

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.30 2003/11/29 19:52:06 pgsql Exp $
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.31 2003/12/01 22:14:40 momjian Exp $
*/
#ifndef COMMON_H
#define COMMON_H
@ -13,6 +13,13 @@
#include "pqsignal.h"
#include "libpq-fe.h"
#ifdef USE_ASSERT_CHECKING
#include <assert.h>
#define psql_assert(p) assert(p)
#else
#define psql_assert(p)
#endif
extern char *xstrdup(const char *string);
extern bool setQFout(const char *fname);

View File

@ -3,13 +3,12 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.34 2003/11/29 19:52:06 pgsql Exp $
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.35 2003/12/01 22:14:40 momjian Exp $
*/
#include "postgres_fe.h"
#include "copy.h"
#include <errno.h>
#include <assert.h>
#include <signal.h>
#include <sys/stat.h>
#ifndef WIN32

View File

@ -3,14 +3,14 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/stringutils.c,v 1.35 2003/11/29 19:52:07 pgsql Exp $
* $PostgreSQL: pgsql/src/bin/psql/stringutils.c,v 1.36 2003/12/01 22:14:40 momjian Exp $
*/
#include "postgres_fe.h"
#include <assert.h>
#include <ctype.h>
#include "libpq-fe.h"
#include "common.h"
#include "settings.h"
#include "stringutils.h"
@ -234,10 +234,8 @@ strip_quotes(char *source, char quote, char escape, int encoding)
char *src;
char *dst;
#ifdef USE_ASSERT_CHECKING
assert(source);
assert(quote);
#endif
psql_assert(source);
psql_assert(quote);
src = dst = source;

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.95 2003/12/01 22:08:01 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.96 2003/12/01 22:14:40 momjian Exp $
*/
/*----------------------------------------------------------------------
@ -49,9 +49,6 @@
#ifdef USE_READLINE
#include <ctype.h>
#ifdef USE_ASSERT_CHECKING
#include <assert.h>
#endif
#include "libpq-fe.h"
#include "pqexpbuffer.h"
#include "common.h"
@ -1345,7 +1342,6 @@ psql_completion(char *text, int start, int end)
}
}
/*
* If we still don't have anything to match we have to fabricate some
* sort of default list. If we were to just return NULL, readline
@ -1360,7 +1356,6 @@ psql_completion(char *text, int start, int end)
#endif
}
/* free storage */
free(prev_wd);
free(prev2_wd);
@ -1382,7 +1377,7 @@ psql_completion(char *text, int start, int end)
directly but through the readline interface.
The return value is expected to be the full completion of the text, going
through a list each time, or NULL if there are no more matches. The string
will be free()'d be readline, so you must run it through strdup() or
will be free()'d by readline, so you must run it through strdup() or
something of that sort.
*/
@ -1637,9 +1632,7 @@ complete_from_list(const char *text, int state)
const char *item;
/* need to have a list */
#ifdef USE_ASSERT_CHECKING
assert(completion_charpp);
#endif
psql_assert(completion_charpp);
/* Initialization */
if (state == 0)
@ -1693,9 +1686,7 @@ complete_from_const(const char *text, int state)
(void) text; /* We don't care about what was entered
* already. */
#ifdef USE_ASSERT_CHECKING
assert(completion_charp);
#endif
psql_assert(completion_charp);
if (state == 0)
return xstrdup(completion_charp);
else
@ -1809,7 +1800,7 @@ previous_word(int point, int skip)
/*
* Surround a string with single quotes. This works for both SQL and
* psql internal. Currently disable because it is reported not to
* psql internal. Currently disabled because it is reported not to
* cooperate with certain versions of readline.
*/
static char *

View File

@ -3,14 +3,12 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.14 2003/11/29 19:52:07 pgsql Exp $
* $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.15 2003/12/01 22:14:40 momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
#include "variables.h"
#include <assert.h>
VariableSpace
CreateVariableSpace(void)
{
@ -46,10 +44,8 @@ GetVariable(VariableSpace space, const char *name)
for (current = space; current; current = current->next)
{
#ifdef USE_ASSERT_CHECKING
assert(current->name);
assert(current->value);
#endif
psql_assert(current->name);
psql_assert(current->value);
if (strcmp(current->name, name) == 0)
return current->value;
}
@ -161,10 +157,8 @@ SetVariable(VariableSpace space, const char *name, const char *value)
for (current = space, previous = NULL; current; previous = current, current = current->next)
{
#ifdef USE_ASSERT_CHECKING
assert(current->name);
assert(current->value);
#endif
psql_assert(current->name);
psql_assert(current->value);
if (strcmp(current->name, name) == 0)
{
free(current->value);
@ -203,10 +197,8 @@ DeleteVariable(VariableSpace space, const char *name)
for (current = space, previous = NULL; current; previous = current, current = current->next)
{
#ifdef USE_ASSERT_CHECKING
assert(current->name);
assert(current->value);
#endif
psql_assert(current->name);
psql_assert(current->value);
if (strcmp(current->name, name) == 0)
{
free(current->name);