1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/*-------------------------------------------------------------------------
*
* bool.c
* Functions for the built-in type "bool".
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.22 2000/02/10 19:51:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "utils/builtins.h"
/*****************************************************************************
* USER I/O ROUTINES *
*****************************************************************************/
/*
* boolin - converts "t" or "f" to 1 or 0
*
* 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.
*/
bool
boolin(char *b)
{
switch (*b)
{
case 't':
case 'T':
if (strncasecmp(b, "true", strlen(b)) == 0)
return TRUE;
break;
case 'f':
case 'F':
if (strncasecmp(b, "false", strlen(b)) == 0)
return FALSE;
break;
case 'y':
case 'Y':
if (strncasecmp(b, "yes", strlen(b)) == 0)
return TRUE;
break;
case '1':
if (strncasecmp(b, "1", strlen(b)) == 0)
return TRUE;
break;
case 'n':
case 'N':
if (strncasecmp(b, "no", strlen(b)) == 0)
return FALSE;
break;
case '0':
if (strncasecmp(b, "0", strlen(b)) == 0)
return FALSE;
break;
default:
break;
}
elog(ERROR, "Bad boolean external representation '%s'", b);
/* not reached */
return FALSE;
} /* boolin() */
/*
* boolout - converts 1 or 0 to "t" or "f"
*/
char *
boolout(bool b)
{
char *result = (char *) palloc(2);
*result = (b) ? 't' : 'f';
result[1] = '\0';
return result;
} /* boolout() */
/*****************************************************************************
* PUBLIC ROUTINES *
*****************************************************************************/
bool
booleq(bool arg1, bool arg2)
{
return arg1 == arg2;
}
bool
boolne(bool arg1, bool arg2)
{
return arg1 != arg2;
}
bool
boollt(bool arg1, bool arg2)
{
return arg1 < arg2;
}
bool
boolgt(bool arg1, bool arg2)
{
return arg1 > arg2;
}
bool
boolle(bool arg1, bool arg2)
{
return arg1 <= arg2;
}
bool
boolge(bool arg1, bool arg2)
{
return arg1 >= arg2;
}
bool
istrue(bool arg1)
{
return arg1 == TRUE;
} /* istrue() */
bool
isfalse(bool arg1)
{
return arg1 != TRUE;
} /* isfalse() */
|