77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.7 1997/10/09 05:06:12 thomas Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.8 1997/10/17 05:38:32 thomas Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
2424/*
2525 *boolin- converts "t" or "f" to 1 or 0
2626 *
27- * Check explicitly for "true/TRUE" and allow any odd ASCII value to be "true".
28- * This handles "true/false", "yes/no", "1/0". - thomas 1997-10-05
27+ * Check explicitly for "true/false" and TRUE/FALSE, 1/0, YES/NO.
28+ * Reject other values. - thomas 1997-10-05
29+ * For now, allow old behavior of everything FALSE if not TRUE.
30+ * After v6.2.1 release, then enable code to reject goofy values.
31+ * Also, start checking the entire string rather than just the first character.
32+ * - thomas 1997-10-16
33+ *
34+ * In the switch statement, check the most-used possibilities first.
2935 */
3036bool
3137boolin (char * b )
3238{
33- if (b == NULL )
34- elog (WARN ,"Bad input string for type bool" );
35- return ((bool ) (((* b )== 't' )|| ((* b )== 'T' )|| ((* b )& 1 )));
36- }
39+ switch (* b ) {
40+ case 't' :
41+ case 'T' :
42+ return (TRUE);
43+ break ;
44+
45+ case 'f' :
46+ case 'F' :
47+ return (FALSE);
48+ break ;
49+
50+ case 'y' :
51+ case 'Y' :
52+ case '1' :
53+ return (TRUE);
54+ break ;
55+
56+ case 'n' :
57+ case 'N' :
58+ case '0' :
59+ return (FALSE);
60+ break ;
61+
62+ default :
63+ #if FALSE
64+ elog (WARN ,"Invalid input string '%s'\n" ,b );
65+ #endif
66+ break ;
67+ }
68+
69+ return (FALSE);
70+ }/* boolin() */
3771
3872/*
3973 *boolout- converts 1 or 0 to "t" or "f"
@@ -46,7 +80,7 @@ boolout(bool b)
4680* result = (b ) ?'t' :'f' ;
4781result [1 ]= '\0' ;
4882return (result );
49- }
83+ }/* boolout() */
5084
5185/*****************************************************************************
5286 * PUBLIC ROUTINES *