From 863914ec9574eb58cb0746d59f216997c4863cdf Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Mon, 23 Jul 2018 15:04:46 -0400 Subject: Switch to using a function to parse booleans --- common/util.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'common/util.c') diff --git a/common/util.c b/common/util.c index e8a88772..33a0c77e 100644 --- a/common/util.c +++ b/common/util.c @@ -123,6 +123,21 @@ uint32_t parse_color(const char *color) { return res; } +bool parse_boolean(const char *boolean, const bool current) { + if (strcmp(boolean, "1") == 0 + || strcmp(boolean, "yes") == 0 + || strcmp(boolean, "on") == 0 + || strcmp(boolean, "true") == 0 + || strcmp(boolean, "enable") == 0 + || strcmp(boolean, "enabled") == 0 + || strcmp(boolean, "active") == 0) { + return true; + } else if (strcmp(boolean, "toggle") == 0) { + return !current; + } + return false; +} + char* resolve_path(const char* path) { struct stat sb; ssize_t r; -- cgit v1.2.3-54-g00ecf