1996-07-09 08:22:35 +02: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
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1997-10-09 07:06:12 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.7 1997/10/09 05:06:12 thomas Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-11-03 07:54:38 +01:00
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#include "utils/builtins.h" /* where the declarations go */
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "utils/palloc.h"
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* Check explicitly for "true/TRUE" and allow any odd ASCII value to be "true".
|
|
|
|
* This handles "true/false", "yes/no", "1/0". - thomas 1997-10-05
|
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)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
if (b == NULL)
|
|
|
|
elog(WARN, "Bad input string for type bool");
|
1997-10-09 07:06:12 +02:00
|
|
|
return ((bool) (((*b) == 't') || ((*b) == 'T') || ((*b) & 1)));
|
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';
|
|
|
|
return (result);
|
1996-07-09 08:22:35 +02: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
|
|
|
{
|
|
|
|
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
|
|
|
{
|
1997-09-07 07:04:48 +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
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
return (arg1 > arg2);
|
1997-04-27 21:20:16 +02:00
|
|
|
}
|