|
3 | 3 | *
|
4 | 4 | * Copyright (c) 2000-2008, PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.28 2008/01/01 19:45:56 momjian Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.29 2008/05/07 02:33:52 momjian Exp $ |
7 | 7 | */
|
8 | 8 | #include"postgres_fe.h"
|
9 | 9 | #include"common.h"
|
@@ -48,21 +48,48 @@ GetVariable(VariableSpace space, const char *name)
|
48 | 48 | returnNULL;
|
49 | 49 | }
|
50 | 50 |
|
| 51 | +/* |
| 52 | + * Try to interpret value as boolean value. Valid values are: true, |
| 53 | + * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof. |
| 54 | + */ |
51 | 55 | bool
|
52 |
| -ParseVariableBool(constchar*val) |
| 56 | +ParseVariableBool(constchar*value) |
53 | 57 | {
|
54 |
| -if (val==NULL) |
| 58 | +size_tlen; |
| 59 | + |
| 60 | +if (value==NULL) |
55 | 61 | return false;/* not set -> assume "off" */
|
56 |
| -if (pg_strcasecmp(val,"off")==0) |
57 |
| -return false;/* accept "off" or "OFF" as true */ |
58 | 62 |
|
59 |
| -/* |
60 |
| - * for backwards compatibility, anything except "off" or "OFF" is taken as |
61 |
| - * "true" |
62 |
| - */ |
| 63 | +len=strlen(value); |
| 64 | + |
| 65 | +if (pg_strncasecmp(value,"true",len)==0) |
| 66 | +return true; |
| 67 | +elseif (pg_strncasecmp(value,"false",len)==0) |
| 68 | +return false; |
| 69 | +elseif (pg_strncasecmp(value,"yes",len)==0) |
| 70 | +return true; |
| 71 | +elseif (pg_strncasecmp(value,"no",len)==0) |
| 72 | +return false; |
| 73 | +/* 'o' is not unique enough */ |
| 74 | +elseif (pg_strncasecmp(value,"on", (len>2 ?len :2))==0) |
| 75 | +return true; |
| 76 | +elseif (pg_strncasecmp(value,"off", (len>2 ?len :2))==0) |
| 77 | +return false; |
| 78 | +elseif (pg_strcasecmp(value,"1")==0) |
| 79 | +return true; |
| 80 | +elseif (pg_strcasecmp(value,"0")==0) |
| 81 | +return false; |
| 82 | +else |
| 83 | +{ |
| 84 | +/* NULL is treated as false, so a non-matching value is 'true' */ |
| 85 | +psql_error("unrecognized boolean value; assuming \"on\".\n"); |
| 86 | +return true; |
| 87 | +} |
| 88 | +/* suppress compiler warning */ |
63 | 89 | return true;
|
64 | 90 | }
|
65 | 91 |
|
| 92 | + |
66 | 93 | /*
|
67 | 94 | * Read numeric variable, or defaultval if it is not set, or faultval if its
|
68 | 95 | * value is not a valid numeric string. If allowtrail is false, this will
|
|