Tom Lane wrote:
> Bruce Momjian <[EMAIL PROTECTED]> 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  <[EMAIL PROTECTED]>        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
-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Reply via email to