From fe7598d230bb622be9a064be83958f4d274ef83a Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 4 May 2017 11:34:50 +0900 Subject: [PATCH] Make boolean support more like that in postgresql.conf --- config.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/config.c b/config.c index 0a5699ed..aabae8e9 100644 --- a/config.c +++ b/config.c @@ -746,36 +746,45 @@ repmgr_atoi(const char *value, const char *config_item, ItemList *error_list, in * Interpret a parameter value as a boolean. Currently accepts: * * - true/false - * - 0/1 + * - 1/0 * - on/off - * + * - yes/no + * Returns 'false' if unable to determine the booleanness of the value * and adds an entry to the error list, which will result in the program * erroring out before it proceeds to do anything. * - * TODO: make this work like in postgresql.conf + * TODO: accept "any unambiguous prefix of one of these" as per postgresql.conf: + * + * https://www.postgresql.org/docs/current/static/config-setting.html */ bool parse_bool(const char *s, const char *config_item, ItemList *error_list) { PQExpBufferData errors; - if (strcmp(s, "0") == 0) + if (strcasecmp(s, "0") == 0) return false; - if (strcmp(s, "1") == 0) + if (strcasecmp(s, "1") == 0) return true; - if (strcmp(s, "false") == 0) + if (strcasecmp(s, "false") == 0) return false; - if (strcmp(s, "true") == 0) + if (strcasecmp(s, "true") == 0) return true; - if (strcmp(s, "off") == 0) + if (strcasecmp(s, "off") == 0) return false; - if (strcmp(s, "on") == 0) + if (strcasecmp(s, "on") == 0) + return true; + + if (strcasecmp(s, "no") == 0) + return false; + + if (strcasecmp(s, "yes") == 0) return true; initPQExpBuffer(&errors);