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
Index: src/bin/psql/command.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/psql/command.c,v
retrieving revision 1.105
diff -c -r1.105 command.c
*** src/bin/psql/command.c 11 Oct 2003 18:04:26 -0000 1.105
--- src/bin/psql/command.c 18 Oct 2003 04:02:50 -0000
***************
*** 9,15 ****
#include "command.h"
#include <errno.h>
- #include <assert.h>
#include <ctype.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
--- 9,14 ----
***************
*** 97,106 ****
const char *continue_parse = NULL; /* tell the mainloop where the
* backslash command ended */
! #ifdef USE_ASSERT_CHECKING
! assert(line);
! #endif
!
my_line = xstrdup(line);
/*
--- 96,102 ----
const char *continue_parse = NULL; /* tell the mainloop where the
* backslash command ended */
! psql_assert(line);
my_line = xstrdup(line);
/*
***************
*** 1234,1242 ****
*tmp;
size_t length;
! #ifdef USE_ASSERT_CHECKING
! assert(source);
! #endif
length = Min(len, strlen(source)) + 1;
--- 1230,1236 ----
*tmp;
size_t length;
! psql_assert(source);
length = Min(len, strlen(source)) + 1;
***************
*** 1515,1526 ****
char *sys;
int result;
! #ifdef USE_ASSERT_CHECKING
! assert(fname);
! #else
! if (!fname)
! return false;
! #endif
/* Find an editor to use */
editorName = getenv("PSQL_EDITOR");
--- 1509,1515 ----
char *sys;
int result;
! psql_assert(fname);
/* Find an editor to use */
editorName = getenv("PSQL_EDITOR");
***************
*** 1755,1766 ****
{
size_t vallen = 0;
! #ifdef USE_ASSERT_CHECKING
! assert(param);
! #else
! if (!param)
! return false;
! #endif
if (value)
vallen = strlen(value);
--- 1744,1750 ----
{
size_t vallen = 0;
! psql_assert(param);
if (value)
vallen = strlen(value);
Index: src/bin/psql/common.h
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/psql/common.h,v
retrieving revision 1.29
diff -c -r1.29 common.h
*** src/bin/psql/common.h 3 Sep 2003 22:05:09 -0000 1.29
--- src/bin/psql/common.h 18 Oct 2003 04:00:20 -0000
***************
*** 13,18 ****
--- 13,25 ----
#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);
Index: src/bin/psql/copy.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/psql/copy.c,v
retrieving revision 1.33
diff -c -r1.33 copy.c
*** src/bin/psql/copy.c 4 Aug 2003 23:59:39 -0000 1.33
--- src/bin/psql/copy.c 18 Oct 2003 04:03:02 -0000
***************
*** 9,15 ****
#include "copy.h"
#include <errno.h>
- #include <assert.h>
#include <signal.h>
#include <sys/stat.h>
#ifndef WIN32
--- 9,14 ----
Index: src/bin/psql/stringutils.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/psql/stringutils.c,v
retrieving revision 1.34
diff -c -r1.34 stringutils.c
*** src/bin/psql/stringutils.c 4 Aug 2003 23:59:40 -0000 1.34
--- src/bin/psql/stringutils.c 18 Oct 2003 04:02:28 -0000
***************
*** 7,16 ****
*/
#include "postgres_fe.h"
- #include <assert.h>
#include <ctype.h>
#include "libpq-fe.h"
#include "settings.h"
#include "stringutils.h"
--- 7,16 ----
*/
#include "postgres_fe.h"
#include <ctype.h>
#include "libpq-fe.h"
+ #include "common.h"
#include "settings.h"
#include "stringutils.h"
***************
*** 234,243 ****
char *src;
char *dst;
! #ifdef USE_ASSERT_CHECKING
! assert(source);
! assert(quote);
! #endif
src = dst = source;
--- 234,241 ----
char *src;
char *dst;
! psql_assert(source);
! psql_assert(quote);
src = dst = source;
Index: src/bin/psql/tab-complete.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/psql/tab-complete.c,v
retrieving revision 1.89
diff -c -r1.89 tab-complete.c
*** src/bin/psql/tab-complete.c 17 Oct 2003 11:52:06 -0000 1.89
--- src/bin/psql/tab-complete.c 18 Oct 2003 04:27:01 -0000
***************
*** 50,58 ****
#ifdef USE_READLINE
#include <ctype.h>
- #ifdef USE_ASSERT_CHECKING
- #include <assert.h>
- #endif
#include "libpq-fe.h"
--- 50,55 ----
***************
*** 1342,1348 ****
}
}
-
/*
* 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
--- 1339,1344 ----
***************
*** 1357,1363 ****
#endif
}
-
/* free storage */
free(prev_wd);
free(prev2_wd);
--- 1353,1358 ----
***************
*** 1379,1385 ****
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
something of that sort.
*/
--- 1374,1380 ----
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 by readline, so you must run it through strdup() or
something of that sort.
*/
***************
*** 1559,1567 ****
char *item;
/* need to have a list */
! #ifdef USE_ASSERT_CHECKING
! assert(completion_charpp);
! #endif
/* Initialization */
if (state == 0)
--- 1554,1560 ----
char *item;
/* need to have a list */
! psql_assert(completion_charpp);
/* Initialization */
if (state == 0)
***************
*** 1615,1623 ****
(void) text; /* We don't care about what was entered
* already. */
! #ifdef USE_ASSERT_CHECKING
! assert(completion_charp);
! #endif
if (state == 0)
return xstrdup(completion_charp);
else
--- 1608,1614 ----
(void) text; /* We don't care about what was entered
* already. */
! psql_assert(completion_charp);
if (state == 0)
return xstrdup(completion_charp);
else
***************
*** 1642,1650 ****
if (query == NULL || !pset.db || PQstatus(pset.db) != CONNECTION_OK)
return NULL;
! #ifdef USE_ASSERT_CHECKING
! assert(query[strlen(query) - 1] != ';');
! #endif
if (snprintf(query_buffer, BUF_SIZE, "%s LIMIT %d",
query, completion_max_records) == -1)
--- 1633,1640 ----
if (query == NULL || !pset.db || PQstatus(pset.db) != CONNECTION_OK)
return NULL;
!
! psql_assert(query[strlen(query) - 1] != ';');
if (snprintf(query_buffer, BUF_SIZE, "%s LIMIT %d",
query, completion_max_records) == -1)
***************
*** 1743,1749 ****
/*
* Surround a string with single quotes. This works for both SQL and
! * psql internal. Currently disable because it is reported not to
* cooperate with certain versions of readline.
*/
static char *
--- 1733,1739 ----
/*
* Surround a string with single quotes. This works for both SQL and
! * psql internal. Currently disabled because it is reported not to
* cooperate with certain versions of readline.
*/
static char *
Index: src/bin/psql/variables.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/psql/variables.c,v
retrieving revision 1.13
diff -c -r1.13 variables.c
*** src/bin/psql/variables.c 4 Aug 2003 23:59:40 -0000 1.13
--- src/bin/psql/variables.c 18 Oct 2003 04:02:13 -0000
***************
*** 6,16 ****
* $Header: /var/lib/cvs/pgsql-server/src/bin/psql/variables.c,v 1.13 2003/08/04 23:59:40 tgl Exp $
*/
#include "postgres_fe.h"
#include "variables.h"
- #include <assert.h>
-
-
VariableSpace
CreateVariableSpace(void)
{
--- 6,14 ----
* $Header: /var/lib/cvs/pgsql-server/src/bin/psql/variables.c,v 1.13 2003/08/04 23:59:40 tgl Exp $
*/
#include "postgres_fe.h"
+ #include "common.h"
#include "variables.h"
VariableSpace
CreateVariableSpace(void)
{
***************
*** 46,55 ****
for (current = space; current; current = current->next)
{
! #ifdef USE_ASSERT_CHECKING
! assert(current->name);
! assert(current->value);
! #endif
if (strcmp(current->name, name) == 0)
return current->value;
}
--- 44,51 ----
for (current = space; current; current = current->next)
{
! psql_assert(current->name);
! psql_assert(current->value);
if (strcmp(current->name, name) == 0)
return current->value;
}
***************
*** 161,170 ****
for (current = space, previous = NULL; current; previous = current, current = current->next)
{
! #ifdef USE_ASSERT_CHECKING
! assert(current->name);
! assert(current->value);
! #endif
if (strcmp(current->name, name) == 0)
{
free(current->value);
--- 157,164 ----
for (current = space, previous = NULL; current; previous = current, current = current->next)
{
! psql_assert(current->name);
! psql_assert(current->value);
if (strcmp(current->name, name) == 0)
{
free(current->value);
***************
*** 203,212 ****
for (current = space, previous = NULL; current; previous = current, current = current->next)
{
! #ifdef USE_ASSERT_CHECKING
! assert(current->name);
! assert(current->value);
! #endif
if (strcmp(current->name, name) == 0)
{
free(current->name);
--- 197,204 ----
for (current = space, previous = NULL; current; previous = current, current = current->next)
{
! psql_assert(current->name);
! psql_assert(current->value);
if (strcmp(current->name, name) == 0)
{
free(current->name);
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly