diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-07-23 21:49:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-23 21:49:16 -0400 |
commit | 71774ecd3658653328f3c903869b52c51c62e237 (patch) | |
tree | bfc136252f81a5350f240c20161d2d0bfc2f80dd /common | |
parent | 224ade138208e9aa525423cbfbd643aa9d9b63c3 (diff) | |
parent | 9ec1d6cf79e6f9c3233f577c6fddeaeb21bb1bfc (diff) |
Merge pull request #2340 from RedSoxFan/parse_boolean
Switch to using a function to parse booleans
Diffstat (limited to 'common')
-rw-r--r-- | common/util.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index e8a88772..467aa4b5 100644 --- a/common/util.c +++ b/common/util.c @@ -123,6 +123,22 @@ uint32_t parse_color(const char *color) { return res; } +bool parse_boolean(const char *boolean, bool current) { + if (strcasecmp(boolean, "1") == 0 + || strcasecmp(boolean, "yes") == 0 + || strcasecmp(boolean, "on") == 0 + || strcasecmp(boolean, "true") == 0 + || strcasecmp(boolean, "enable") == 0 + || strcasecmp(boolean, "enabled") == 0 + || strcasecmp(boolean, "active") == 0) { + return true; + } else if (strcasecmp(boolean, "toggle") == 0) { + return !current; + } + // All other values are false to match i3 + return false; +} + char* resolve_path(const char* path) { struct stat sb; ssize_t r; |