Re: [HACKERS] [GENERAL] psql \pset pager - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [HACKERS] [GENERAL] psql \pset pager
Date
Msg-id 200805070234.m472YHV27262@momjian.us
Whole thread Raw
List pgsql-patches
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > Tom Lane wrote:
> >> If we're going to change it, we should make it match GUC's parse_bool,
> >> which has had some actual thought put into it.
>
> > Good idea.  Do I copy the C code into /psql or somehow share the
> > function?
>
> Just copy it --- it's not large enough to be worth doing something like
> inventing a /port module for, and besides it's not clear that you want
> exactly the same API.

Patch attached and applied.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/bin/psql/variables.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/variables.c,v
retrieving revision 1.28
diff -c -c -r1.28 variables.c
*** src/bin/psql/variables.c    1 Jan 2008 19:45:56 -0000    1.28
--- src/bin/psql/variables.c    7 May 2008 02:10:55 -0000
***************
*** 48,68 ****
      return NULL;
  }

  bool
! ParseVariableBool(const char *val)
  {
!     if (val == NULL)
          return false;            /* not set -> assume "off" */
-     if (pg_strcasecmp(val, "off") == 0)
-         return false;            /* accept "off" or "OFF" as true */

!     /*
!      * for backwards compatibility, anything except "off" or "OFF" is taken as
!      * "true"
!      */
      return true;
  }

  /*
   * 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
--- 48,95 ----
      return NULL;
  }

+ /*
+  * Try to interpret value as boolean value.  Valid values are: true,
+  * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
+  */
  bool
! ParseVariableBool(const char *value)
  {
!     size_t        len;
!
!     if (value == NULL)
          return false;            /* not set -> assume "off" */

!     len = strlen(value);
!
!     if (pg_strncasecmp(value, "true", len) == 0)
!         return true;
!     else if (pg_strncasecmp(value, "false", len) == 0)
!         return false;
!     else if (pg_strncasecmp(value, "yes", len) == 0)
!         return true;
!     else if (pg_strncasecmp(value, "no", len) == 0)
!         return false;
!     /* 'o' is not unique enough */
!     else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
!         return true;
!     else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
!         return false;
!     else if (pg_strcasecmp(value, "1") == 0)
!         return true;
!     else if (pg_strcasecmp(value, "0") == 0)
!         return false;
!     else
!     {
!         /* NULL is treated as false, so a non-matching value is 'true' */
!         psql_error("unrecognized boolean value; assuming \"on\".\n");
!         return true;
!     }
!     /* suppress compiler warning */
      return true;
  }

+
  /*
   * 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

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: column level privileges
Next
From: Andrew Dunstan
Date:
Subject: Re: column level privileges