This patch reduces some unsightly #ifdefs, and fixes two typos in
authorBruce Momjian
Mon, 1 Dec 2003 22:14:40 +0000 (22:14 +0000)
committerBruce Momjian
Mon, 1 Dec 2003 22:14:40 +0000 (22:14 +0000)
comments in the psql code. This doesn't make any functional change, so
feel free to save it for 7.5

Neil Conway

src/bin/psql/command.c
src/bin/psql/common.h
src/bin/psql/copy.c
src/bin/psql/stringutils.c
src/bin/psql/tab-complete.c
src/bin/psql/variables.c

index 6a26ef549aeefa0ffddcf01f4c25a2719fd2f2bc..fda770f9dc8fa99f133923d571cf7170934d6ac0 100644 (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 
-#include 
 #include 
 #ifdef HAVE_PWD_H
 #include 
@@ -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);
index 74e6deb2346a0d0944f2e41bd17e4f8d89b3e9f7..2e9cc5952e0c867ded68fd4312a32044f0849cca 100644 (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
 #include "pqsignal.h"
 #include "libpq-fe.h"
 
+#ifdef USE_ASSERT_CHECKING
+#include 
+#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 91e11e40001d9f50ce9325336c248fc711a08e39..200029b77bd9ea190ca4e441b70049cd05630052 100644 (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 
-#include 
 #include 
 #include 
 #ifndef WIN32
index 1dbc369df9bf603ab8698e7b4364819cbb86430d..c90abb2cdd674f44ddd5accc2dae6ee958841bb9 100644 (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 
 #include 
 
 #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;
 
index c50ce514d1fec6514faa9de6e97e16c1411ae606..b6ae2ce8659cc89de1867707436c88822471a949 100644 (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 
-#ifdef USE_ASSERT_CHECKING
-#include 
-#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 *
index 2275b818fb4e64158f081345c2b1a28b53de3942..21dc8aecb68a17346c638509c2c573465c9b6855 100644 (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 
-
-
 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);