1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* bool.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* Functions for the built-in type "bool".
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-01-26 06:58:53 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.21 2000/01/26 05:57:13 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-11-03 07:54:38 +01:00
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
1999-07-16 05:14:30 +02:00
|
|
|
#include "utils/builtins.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* USER I/O ROUTINES *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* boolin - converts "t" or "f" to 1 or 0
|
1997-10-09 07:06:12 +02:00
|
|
|
*
|
1997-10-17 07:38:32 +02:00
|
|
|
* Check explicitly for "true/false" and TRUE/FALSE, 1/0, YES/NO.
|
|
|
|
* Reject other values. - thomas 1997-10-05
|
|
|
|
*
|
|
|
|
* In the switch statement, check the most-used possibilities first.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1996-07-09 08:22:35 +02:00
|
|
|
boolin(char *b)
|
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
switch (*b)
|
|
|
|
{
|
|
|
|
case 't':
|
|
|
|
case 'T':
|
1997-10-25 07:09:58 +02:00
|
|
|
if (strncasecmp(b, "true", strlen(b)) == 0)
|
1998-09-01 05:29:17 +02:00
|
|
|
return TRUE;
|
1997-10-17 07:38:32 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
case 'F':
|
1997-10-25 07:09:58 +02:00
|
|
|
if (strncasecmp(b, "false", strlen(b)) == 0)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-10-17 07:38:32 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'y':
|
|
|
|
case 'Y':
|
1997-10-25 07:09:58 +02:00
|
|
|
if (strncasecmp(b, "yes", strlen(b)) == 0)
|
1998-09-01 05:29:17 +02:00
|
|
|
return TRUE;
|
1997-10-25 07:09:58 +02:00
|
|
|
break;
|
|
|
|
|
1997-10-17 07:38:32 +02:00
|
|
|
case '1':
|
1997-10-25 07:09:58 +02:00
|
|
|
if (strncasecmp(b, "1", strlen(b)) == 0)
|
1998-09-01 05:29:17 +02:00
|
|
|
return TRUE;
|
1997-10-17 07:38:32 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
case 'N':
|
1997-10-25 07:09:58 +02:00
|
|
|
if (strncasecmp(b, "no", strlen(b)) == 0)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-10-25 07:09:58 +02:00
|
|
|
break;
|
|
|
|
|
1997-10-17 07:38:32 +02:00
|
|
|
case '0':
|
1997-10-25 07:09:58 +02:00
|
|
|
if (strncasecmp(b, "0", strlen(b)) == 0)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-10-17 07:38:32 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
elog(ERROR, "Bad boolean external representation '%s'", b);
|
1997-11-07 07:30:20 +01:00
|
|
|
/* not reached */
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* boolin() */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* boolout - converts 1 or 0 to "t" or "f"
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-10-09 07:06:12 +02:00
|
|
|
char *
|
|
|
|
boolout(bool b)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *result = (char *) palloc(2);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
*result = (b) ? 't' : 'f';
|
|
|
|
result[1] = '\0';
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* boolout() */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-11-07 07:30:20 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* PUBLIC ROUTINES *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1997-10-09 07:06:12 +02:00
|
|
|
booleq(bool arg1, bool arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 == arg2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1997-10-09 07:06:12 +02:00
|
|
|
boolne(bool arg1, bool arg2)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 != arg2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-04-27 21:20:16 +02:00
|
|
|
bool
|
1997-10-09 07:06:12 +02:00
|
|
|
boollt(bool arg1, bool arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 < arg2;
|
1997-04-27 21:20:16 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-04-27 21:20:16 +02:00
|
|
|
bool
|
1997-10-09 07:06:12 +02:00
|
|
|
boolgt(bool arg1, bool arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 > arg2;
|
1997-04-27 21:20:16 +02:00
|
|
|
}
|
1997-10-30 17:45:12 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
istrue(bool arg1)
|
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 == TRUE;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* istrue() */
|
1997-10-30 17:45:12 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
isfalse(bool arg1)
|
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 != TRUE;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* isfalse() */
|